Generated on Sat Feb 7 2015 02:01:26 for Gecode by doxygen 1.8.9.1
bool.hpp
Go to the documentation of this file.
1 /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2 /*
3  * Main authors:
4  * Guido Tack <tack@gecode.org>
5  *
6  * Copyright:
7  * Guido Tack, 2004
8  *
9  * Last modified:
10  * $Date: 2015-01-16 01:21:56 +0100 (Fri, 16 Jan 2015) $ by $Author: tack $
11  * $Revision: 14355 $
12  *
13  * This file is part of Gecode, the generic constraint
14  * development environment:
15  * http://www.gecode.org
16  *
17  * Permission is hereby granted, free of charge, to any person obtaining
18  * a copy of this software and associated documentation files (the
19  * "Software"), to deal in the Software without restriction, including
20  * without limitation the rights to use, copy, modify, merge, publish,
21  * distribute, sublicense, and/or sell copies of the Software, and to
22  * permit persons to whom the Software is furnished to do so, subject to
23  * the following conditions:
24  *
25  * The above copyright notice and this permission notice shall be
26  * included in all copies or substantial portions of the Software.
27  *
28  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
29  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
30  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
31  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
32  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
33  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
34  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35  *
36  */
37 
38 #include <gecode/int.hh>
39 
40 namespace Gecode { namespace Set { namespace Channel {
41 
42  template<class View>
43  template<class A>
47  Council<A>& c, int index)
48  : Advisor(home,p,c), idx(index) {
49  if (idx == -1)
50  p.y.subscribe(home,*this);
51  else {
52  p.x[idx].subscribe(home,*this);
53  }
54  }
55 
56  template<class View>
59  IndexAdvisor& a)
60  : Advisor(home,share,a), idx(a.idx) {}
61 
62  template<class View>
63  forceinline int
65  return idx;
66  }
67 
68  template<class View>
69  template<class A>
70  forceinline void
72  ChannelBool<View>& p = static_cast<ChannelBool<View>&>(propagator());
73  if (idx == -1)
74  p.y.cancel(home,*this);
75  else {
76  p.x[idx].cancel(home,*this);
77  }
78  Advisor::dispose(home,c);
79  }
80 
81  template<class View>
85  View y0)
86  : Super(home,x0,y0), co(home), running(false) {
87  bool assigned = false;
88  for (int i=x.size(); i--;) {
89  if (x[i].zero()) {
90  assigned = true;
91  SetDelta d;
92  zeros.include(home, i, i, d);
93  } else if (x[i].one()) {
94  assigned = true;
95  SetDelta d;
96  ones.include(home, i, i, d);
97  } else {
98  (void) new (home) IndexAdvisor(home,*this,co,i);
99  }
100  }
101  if (assigned)
103  View::schedule(home, *this, y.assigned() ? ME_SET_VAL : ME_SET_BB);
104  if (y.assigned()) {
105  if (y.glbSize() == y.glbMax()-y.glbMin()+1) {
106  new (&delta) SetDelta(y.glbMin(),y.glbMax(),1,0);
107  } else {
108  new (&delta) SetDelta(2,0,1,0);
109  }
110  }
111  (void) new (home) IndexAdvisor(home,*this,co,-1);
112  }
113 
114  template<class View>
117  : Super(home,share,p), running(false) {
118  co.update(home, share, p.co);
119  }
120 
121  template<class View>
124  View y) {
125  GECODE_ME_CHECK(y.intersect(home, 0, x.size()-1));
126  (void) new (home) ChannelBool(home,x,y);
127  return ES_OK;
128  }
129 
130  template<class View>
131  PropCost
133  return PropCost::quadratic(PropCost::LO, x.size()+1);
134  }
135 
136  template<class View>
137  forceinline size_t
139  co.dispose(home);
140  (void) Super::dispose(home);
141  return sizeof(*this);
142  }
143 
144  template<class View>
145  Actor*
146  ChannelBool<View>::copy(Space& home, bool share) {
147  return new (home) ChannelBool(home,share,*this);
148  }
149 
150  template<class View>
151  ExecStatus
153  running = true;
154  if (zeros.size() > 0) {
155  BndSetRanges zi(zeros);
156  GECODE_ME_CHECK(y.excludeI(home, zi));
157  zeros.init(home);
158  }
159  if (ones.size() > 0) {
160  BndSetRanges oi(ones);
161  GECODE_ME_CHECK(y.includeI(home, oi));
162  ones.init(home);
163  }
164  running = false;
165 
166  if (delta.glbMin() != 1 || delta.glbMax() != 0) {
167  if (!delta.glbAny()) {
168  for (int i=delta.glbMin(); i<=delta.glbMax(); i++)
169  GECODE_ME_CHECK(x[i].one(home));
170  } else {
171  GlbRanges<View> glb(y);
172  for (Iter::Ranges::ToValues<GlbRanges<View> > gv(glb); gv(); ++gv) {
173  GECODE_ME_CHECK(x[gv.val()].one(home));
174  }
175  }
176  }
177  if (delta.lubMin() != 1 || delta.lubMax() != 0) {
178  if (!delta.lubAny()) {
179  for (int i=delta.lubMin(); i<=delta.lubMax(); i++)
180  GECODE_ME_CHECK(x[i].zero(home));
181  } else {
182  int cur = 0;
183  for (LubRanges<View> lub(y); lub(); ++lub) {
184  for (; cur < lub.min(); cur++) {
185  GECODE_ME_CHECK(x[cur].zero(home));
186  }
187  cur = lub.max() + 1;
188  }
189  for (; cur < x.size(); cur++) {
190  GECODE_ME_CHECK(x[cur].zero(home));
191  }
192  }
193  }
194 
195  new (&delta) SetDelta();
196 
197  return y.assigned() ? home.ES_SUBSUMED(*this) : ES_FIX;
198  }
199 
200  template<class View>
201  ExecStatus
203  IndexAdvisor& a = static_cast<IndexAdvisor&>(_a);
204  const SetDelta& d = static_cast<const SetDelta&>(_d);
205 
206  ModEvent me = View::modevent(d);
207  int index = a.index();
208  if ( (running && index == -1 && me != ME_SET_VAL)
209  || (index == -1 && me == ME_SET_CARD) ) {
210  return ES_OK;
211  }
212 
213  if (index >= 0) {
214  if (x[index].zero()) {
215  SetDelta dummy;
216  zeros.include(home, index, index, dummy);
217  } else {
218  assert(x[index].one());
219  SetDelta dummy;
220  ones.include(home, index, index, dummy);
221  }
222  return home.ES_NOFIX_DISPOSE( co, a);
223  }
224 
225  if ((a.index() == -1) && Rel::testSetEventLB(me)) {
226  if (d.glbAny()) {
227  new (&delta)
228  SetDelta(2,0, delta.lubMin(), delta.lubMax());
229  } else {
230  if (delta.glbMin() == 1 && delta.glbMax() == 0) {
231  new (&delta)
232  SetDelta(d.glbMin(), d.glbMax(),
233  delta.lubMin(), delta.lubMax());
234  } else {
235  if (delta.glbMin() != 2 || delta.glbMax() != 0) {
236  if ((delta.glbMin() <= d.glbMin() && delta.glbMax() >= d.glbMin())
237  ||
238  (delta.glbMin() <= d.glbMax() && delta.glbMax() >= d.glbMax())
239  ) {
240  new (&delta)
241  SetDelta(std::min(delta.glbMin(), d.glbMin()),
242  std::max(delta.glbMax(), d.glbMax()),
243  delta.lubMin(), delta.lubMax());
244  } else {
245  new (&delta)
246  SetDelta(2, 0, delta.lubMin(), delta.lubMax());
247  }
248  }
249  }
250  }
251  }
252  if ((a.index() == -1) && Rel::testSetEventUB(me)) {
253  if (d.lubAny()) {
254  new (&delta)
255  SetDelta(delta.glbMin(), delta.glbMax(), 2,0);
256  } else {
257  if (delta.lubMin() == 1 && delta.lubMax() == 0) {
258  new (&delta)
259  SetDelta(delta.glbMin(), delta.glbMax(),
260  d.lubMin(), d.lubMax());
261  } else {
262  if (delta.lubMin() != 2 || delta.lubMax() != 0) {
263  if ((delta.lubMin() <= d.lubMin() && delta.lubMax() >= d.lubMin())
264  ||
265  (delta.lubMin() <= d.lubMax() && delta.lubMax() >= d.lubMax())
266  ) {
267  new (&delta)
268  SetDelta(delta.lubMin(), delta.lubMax(),
269  std::min(delta.lubMin(), d.lubMin()),
270  std::max(delta.lubMax(), d.lubMax())
271  );
272  } else {
273  new (&delta)
274  SetDelta(delta.glbMin(), delta.glbMax(), 2, 0);
275  }
276  }
277  }
278  }
279  }
280  if (y.assigned())
281  return home.ES_NOFIX_DISPOSE( co, a);
282  else
283  return ES_NOFIX;
284  }
285 
286 }}}
287 
288 // STATISTICS: set-prop
Council of advisors
Definition: core.hpp:226
bool running
Flag whether propagation is currently running.
Definition: channel.hh:193
static PropCost quadratic(PropCost::Mod m, unsigned int n)
Quadratic complexity for modifier m and size measure n.
Definition: core.hpp:4032
ExecStatus ES_SUBSUMED(Propagator &p)
Definition: core.hpp:2973
const FloatNum max
Largest allowed float value.
Definition: float.hh:831
bool one(const Gecode::FloatValArgs &a)
Check whether has only one coefficients.
Definition: linear.cpp:50
void dummy(Space &home)
A dummy function for branching.
Definition: nogoods.cpp:55
Multi _d(Gecode::IntArgs(3, 3, 2, 1))
const Gecode::ModEvent ME_SET_BB
Domain operation has changed both greatest lower and least upper bound.
Definition: var-type.hpp:172
int ModEvent
Type for modification events.
Definition: core.hpp:146
Council< IndexAdvisor > co
Council for managing advisors.
Definition: channel.hh:185
void dispose(Space &home, Council< A > &c)
Delete advisor.
Definition: bool.hpp:71
Base-class for advisors.
Definition: core.hpp:926
GLBndSet zeros
Accumulated zero Booleans.
Definition: channel.hh:189
ExecStatus ES_NOFIX_DISPOSE(Council< A > &c, A &a)
Advisor a must be disposed and its propagator must be run
Definition: core.hpp:3285
virtual PropCost cost(const Space &home, const ModEventDelta &med) const
Cost function (defined as PC_QUADRATIC_LO)
Definition: bool.hpp:132
static ExecStatus post(Home home, ViewArray< Gecode::Int::BoolView > &x, View y)
Post propagator for .
Definition: bool.hpp:123
Propagation has computed fixpoint.
Definition: core.hpp:528
Computation spaces.
Definition: core.hpp:1362
Base-class for both propagators and branchers.
Definition: core.hpp:666
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
Definition: bool.hpp:152
bool glbAny(void) const
Test whether delta represents any domain change in glb.
Definition: delta.hpp:68
Gecode::IntSet d(v, 7)
IndexAdvisor(Space &home, ChannelBool< View > &p, Council< A > &c, int index)
Constructor for creation.
Definition: bool.hpp:45
Gecode::FloatVal c(-8, 8)
Single _a(2, 3)
int p
Number of positive literals for node type.
Definition: bool-expr.cpp:236
const FloatNum min
Smallest allowed float value.
Definition: float.hh:833
Gecode::IntArgs i(4, 1, 2, 3, 4)
void subscribe(Space &home, Propagator &p, PropCond pc, bool process=true)
Subscribe propagator p with propagation condition pc to variable.
Definition: array.hpp:1400
virtual size_t dispose(Space &home)
Delete propagator and return its size.
Definition: bool.hpp:138
int glbMax(void) const
Return glb maximum.
Definition: delta.hpp:56
int glbMin(void) const
Return glb minimum.
Definition: delta.hpp:52
Value iterator from range iterator.
int index(void) const
Access index.
Definition: bool.hpp:64
Range iterator for integer sets.
Definition: var-imp.hpp:189
Advisor storing a single index
Definition: channel.hh:166
void cancel(Space &home, Propagator &p, PropCond pc)
Cancel subscription of propagator p with propagation condition pc to all views.
Definition: array.hpp:1408
#define GECODE_ME_CHECK(me)
Check whether modification event me is failed, and forward failure.
Definition: macros.hpp:45
virtual ExecStatus advise(Space &home, Advisor &a, const Delta &d)
Give advice to propagator.
Definition: bool.hpp:202
bool testSetEventLB(ModEvent me0, ModEvent me1, ModEvent me2)
Definition: common.hpp:75
int lubMin(void) const
Return lub minimum.
Definition: delta.hpp:60
Node * x
Pointer to corresponding Boolean expression node.
Definition: bool-expr.cpp:253
Generic domain change information to be supplied to advisors.
Definition: core.hpp:275
void dispose(Space &home, Council< A > &c)
Dispose the advisor.
Definition: core.hpp:3267
Propagation cost.
Definition: core.hpp:537
ExecStatus
Definition: core.hpp:523
bool assigned(View x, int v)
Whether x is assigned to value v.
Definition: single.hpp:47
virtual Actor * copy(Space &home, bool)
Copy propagator during cloning.
Definition: bool.hpp:146
#define forceinline
Definition: config.hpp:132
int lubMax(void) const
Return lub maximum.
Definition: delta.hpp:64
Execution is okay.
Definition: core.hpp:527
Propagation has not computed fixpoint.
Definition: core.hpp:526
GLBndSet ones
Accumulated one Booleans.
Definition: channel.hh:191
int size(void) const
Return size of array (number of elements)
Definition: array.hpp:1215
Propagator for channelling between set variable and its characteristic function
Definition: channel.hh:148
Gecode toplevel namespace
static void schedule(Space &home, Propagator &p, ModEvent me)
Schedule propagator p with modification event me.
bool testSetEventUB(ModEvent me0, ModEvent me1, ModEvent me2)
Definition: common.hpp:79
SetDelta delta
Accumulated delta information.
Definition: channel.hh:187
const Gecode::ModEvent ME_SET_VAL
Domain operation has resulted in a value (assigned variable)
Definition: var-type.hpp:142
const Gecode::ModEvent ME_SET_CARD
Domain operation has changed the variable cardinality.
Definition: var-type.hpp:148
int ModEventDelta
Modification event deltas.
Definition: core.hpp:173
Home class for posting propagators
Definition: core.hpp:717
ChannelBool(Space &home, bool share, ChannelBool &p)
Constructor for cloning p.
Definition: bool.hpp:116
struct Gecode::@518::NNF::@57::@59 a
For atomic nodes.
bool include(Space &home, int i, int j, SetDelta &d)
Include the set in this set.
Definition: integerset.hpp:283
bool lubAny(void) const
Test whether delta represents any domain change in lub.
Definition: delta.hpp:72
const Gecode::ModEvent ME_BOOL_VAL
Domain operation has resulted in a value (assigned variable)
Definition: var-type.hpp:116
Finite set delta information for advisors.
Definition: var-imp.hpp:56