Generated on Tue Sep 16 2014 20:36:47 for Gecode by doxygen 1.8.8
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: 2011-11-03 11:52:07 +0100 (Thu, 03 Nov 2011) $ by $Author: tack $
11  * $Revision: 12452 $
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  (void) new (home) IndexAdvisor(home,*this,co,-1);
105  }
106 
107  template<class View>
110  : Super(home,share,p), running(false) {
111  co.update(home, share, p.co);
112  }
113 
114  template<class View>
117  View y) {
118  GECODE_ME_CHECK(y.intersect(home, 0, x.size()-1));
119  (void) new (home) ChannelBool(home,x,y);
120  return ES_OK;
121  }
122 
123  template<class View>
124  PropCost
126  return PropCost::quadratic(PropCost::LO, x.size()+1);
127  }
128 
129  template<class View>
130  forceinline size_t
132  co.dispose(home);
133  (void) Super::dispose(home);
134  return sizeof(*this);
135  }
136 
137  template<class View>
138  Actor*
139  ChannelBool<View>::copy(Space& home, bool share) {
140  return new (home) ChannelBool(home,share,*this);
141  }
142 
143  template<class View>
144  ExecStatus
146  running = true;
147  if (zeros.size() > 0) {
148  BndSetRanges zi(zeros);
149  GECODE_ME_CHECK(y.excludeI(home, zi));
150  zeros.init(home);
151  }
152  if (ones.size() > 0) {
153  BndSetRanges oi(ones);
154  GECODE_ME_CHECK(y.includeI(home, oi));
155  ones.init(home);
156  }
157  running = false;
158 
159  if (delta.glbMin() != 1 || delta.glbMax() != 0) {
160  if (!delta.glbAny()) {
161  for (int i=delta.glbMin(); i<=delta.glbMax(); i++)
162  GECODE_ME_CHECK(x[i].one(home));
163  } else {
164  GlbRanges<View> glb(y);
165  for (Iter::Ranges::ToValues<GlbRanges<View> > gv(glb); gv(); ++gv) {
166  GECODE_ME_CHECK(x[gv.val()].one(home));
167  }
168  }
169  }
170  if (delta.lubMin() != 1 || delta.lubMax() != 0) {
171  if (!delta.lubAny()) {
172  for (int i=delta.lubMin(); i<=delta.lubMax(); i++)
173  GECODE_ME_CHECK(x[i].zero(home));
174  } else {
175  int cur = 0;
176  for (LubRanges<View> lub(y); lub(); ++lub) {
177  for (; cur < lub.min(); cur++) {
178  GECODE_ME_CHECK(x[cur].zero(home));
179  }
180  cur = lub.max() + 1;
181  }
182  for (; cur < x.size(); cur++) {
183  GECODE_ME_CHECK(x[cur].zero(home));
184  }
185  }
186  }
187 
188  new (&delta) SetDelta();
189 
190  return y.assigned() ? home.ES_SUBSUMED(*this) : ES_FIX;
191  }
192 
193  template<class View>
194  ExecStatus
196  IndexAdvisor& a = static_cast<IndexAdvisor&>(_a);
197  const SetDelta& d = static_cast<const SetDelta&>(_d);
198 
199  ModEvent me = View::modevent(d);
200  int index = a.index();
201  if ( (running && index == -1 && me != ME_SET_VAL)
202  || (index == -1 && me == ME_SET_CARD) ) {
203  return ES_OK;
204  }
205 
206  if (index >= 0) {
207  if (x[index].zero()) {
208  SetDelta dummy;
209  zeros.include(home, index, index, dummy);
210  } else {
211  assert(x[index].one());
212  SetDelta dummy;
213  ones.include(home, index, index, dummy);
214  }
215  return home.ES_NOFIX_DISPOSE( co, a);
216  }
217 
218  if ((a.index() == -1) && Rel::testSetEventLB(me)) {
219  if (d.glbAny()) {
220  new (&delta)
221  SetDelta(2,0, delta.lubMin(), delta.lubMax());
222  } else {
223  if (delta.glbMin() == 1 && delta.glbMax() == 0) {
224  new (&delta)
225  SetDelta(d.glbMin(), d.glbMax(),
226  delta.lubMin(), delta.lubMax());
227  } else {
228  if (delta.glbMin() != 2 || delta.glbMax() != 0) {
229  if ((delta.glbMin() <= d.glbMin() && delta.glbMax() >= d.glbMin())
230  ||
231  (delta.glbMin() <= d.glbMax() && delta.glbMax() >= d.glbMax())
232  ) {
233  new (&delta)
234  SetDelta(std::min(delta.glbMin(), d.glbMin()),
235  std::max(delta.glbMax(), d.glbMax()),
236  delta.lubMin(), delta.lubMax());
237  } else {
238  new (&delta)
239  SetDelta(2, 0, delta.lubMin(), delta.lubMax());
240  }
241  }
242  }
243  }
244  }
245  if ((a.index() == -1) && Rel::testSetEventUB(me)) {
246  if (d.lubAny()) {
247  new (&delta)
248  SetDelta(delta.glbMin(), delta.glbMax(), 2,0);
249  } else {
250  if (delta.lubMin() == 1 && delta.lubMax() == 0) {
251  new (&delta)
252  SetDelta(delta.glbMin(), delta.glbMax(),
253  d.lubMin(), d.lubMax());
254  } else {
255  if (delta.lubMin() != 2 || delta.lubMax() != 0) {
256  if ((delta.lubMin() <= d.lubMin() && delta.lubMax() >= d.lubMin())
257  ||
258  (delta.lubMin() <= d.lubMax() && delta.lubMax() >= d.lubMax())
259  ) {
260  new (&delta)
261  SetDelta(delta.lubMin(), delta.lubMax(),
262  std::min(delta.lubMin(), d.lubMin()),
263  std::max(delta.lubMax(), d.lubMax())
264  );
265  } else {
266  new (&delta)
267  SetDelta(delta.glbMin(), delta.glbMax(), 2, 0);
268  }
269  }
270  }
271  }
272  }
273 
274  if (y.assigned())
275  return home.ES_NOFIX_DISPOSE( co, a);
276  else
277  return ES_NOFIX;
278  }
279 
280 }}}
281 
282 // STATISTICS: set-prop
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:3955
ExecStatus ES_SUBSUMED(Propagator &p)
Definition: core.hpp:2896
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:3208
virtual PropCost cost(const Space &home, const ModEventDelta &med) const
Cost function (defined as PC_QUADRATIC_LO)
Definition: bool.hpp:125
static ExecStatus post(Home home, ViewArray< Gecode::Int::BoolView > &x, View y)
Post propagator for .
Definition: bool.hpp:116
Propagation has computed fixpoint.
Definition: core.hpp:528
Computation spaces.
Definition: core.hpp:1325
Base-class for both propagators and branchers.
Definition: core.hpp:666
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
Definition: bool.hpp:145
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:131
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:195
Council of advisors
Definition: core.hpp:226
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:3190
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:139
#define forceinline
Definition: config.hpp:167
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
struct Gecode::@512::NNF::@54::@56 a
For atomic nodes.
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:109
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