Generated on Sat Feb 7 2015 02:01:20 for Gecode by doxygen 1.8.9.1
or.hpp
Go to the documentation of this file.
1 /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2 /*
3  * Main authors:
4  * Christian Schulte <schulte@gecode.org>
5  *
6  * Copyright:
7  * Christian Schulte, 2004
8  *
9  * Last modified:
10  * $Date: 2012-09-10 11:31:52 +0200 (Mon, 10 Sep 2012) $ by $Author: schulte $
11  * $Revision: 13071 $
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 namespace Gecode { namespace Int { namespace Bool {
39 
41  template<class BV>
42  class OrTrueSubsumed : public BoolBinary<BV,BV> {
43  protected:
47  OrTrueSubsumed(Space& home, bool share, OrTrueSubsumed& p);
49  static ExecStatus post(Home home, BV b0, BV b1);
50  public:
52  OrTrueSubsumed(Home home, BV b0, BV b1);
54  OrTrueSubsumed(Space& home, bool share, Propagator& p,
55  BV b0, BV b1);
57  virtual Actor* copy(Space& home, bool share);
59  virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
60  };
61 
62  template<class BV>
65  (Home home, BV b0, BV b1)
66  : BoolBinary<BV,BV>(home,b0,b1) {}
67 
68  template<class BV>
70  OrTrueSubsumed<BV>::post(Home home, BV b0, BV b1) {
71  (void) new (home) OrTrueSubsumed(home,b0,b1);
72  return ES_OK;
73  }
74 
75  template<class BV>
78  (Space& home, bool share, OrTrueSubsumed<BV>& p)
79  : BoolBinary<BV,BV>(home,share,p) {}
80 
81  template<class BV>
84  BV b0, BV b1)
85  : BoolBinary<BV,BV>(home,share,p,b0,b1) {}
86 
87  template<class BV>
88  Actor*
89  OrTrueSubsumed<BV>::copy(Space& home, bool share) {
90  return new (home) OrTrueSubsumed<BV>(home,share,*this);
91  }
92 
93  template<class BV>
96  return home.ES_SUBSUMED(*this);
97  }
98 
99 
100  /*
101  * Binary Boolean disjunction propagator (true)
102  *
103  */
104 
105  template<class BVA, class BVB>
107  BinOrTrue<BVA,BVB>::BinOrTrue(Home home, BVA b0, BVB b1)
108  : BoolBinary<BVA,BVB>(home,b0,b1) {}
109 
110  template<class BVA, class BVB>
113  : BoolBinary<BVA,BVB>(home,share,p) {}
114 
115  template<class BVA, class BVB>
118  BVA b0, BVB b1)
119  : BoolBinary<BVA,BVB>(home,share,p,b0,b1) {}
120 
121  template<class BVA, class BVB>
122  Actor*
123  BinOrTrue<BVA,BVB>::copy(Space& home, bool share) {
124  return new (home) BinOrTrue<BVA,BVB>(home,share,*this);
125  }
126 
127  template<class BVA, class BVB>
128  inline ExecStatus
129  BinOrTrue<BVA,BVB>::post(Home home, BVA b0, BVB b1) {
130  switch (bool_test(b0,b1)) {
131  case BT_SAME:
132  GECODE_ME_CHECK(b0.one(home));
133  break;
134  case BT_COMP:
135  break;
136  case BT_NONE:
137  if (b0.zero()) {
138  GECODE_ME_CHECK(b1.one(home));
139  } else if (b1.zero()) {
140  GECODE_ME_CHECK(b0.one(home));
141  } else if (!b0.one() && !b1.one()) {
142  (void) new (home) BinOrTrue<BVA,BVB>(home,b0,b1);
143  }
144  break;
145  default: GECODE_NEVER;
146  }
147  return ES_OK;
148  }
149 
150  template<class BVA, class BVB>
151  ExecStatus
153 #define GECODE_INT_STATUS(S0,S1) \
154  ((BVA::S0<<(1*BVA::BITS))|(BVB::S1<<(0*BVB::BITS)))
155  switch ((x0.status() << (1*BVA::BITS)) | (x1.status() << (0*BVB::BITS))) {
156  case GECODE_INT_STATUS(NONE,NONE):
157  GECODE_NEVER;
158  case GECODE_INT_STATUS(NONE,ZERO):
159  GECODE_ME_CHECK(x0.one_none(home)); break;
160  case GECODE_INT_STATUS(NONE,ONE):
161  break;
162  case GECODE_INT_STATUS(ZERO,NONE):
163  GECODE_ME_CHECK(x1.one_none(home)); break;
164  case GECODE_INT_STATUS(ZERO,ZERO):
165  return ES_FAILED;
166  case GECODE_INT_STATUS(ZERO,ONE):
167  case GECODE_INT_STATUS(ONE,NONE):
168  case GECODE_INT_STATUS(ONE,ZERO):
169  case GECODE_INT_STATUS(ONE,ONE):
170  break;
171  default:
172  GECODE_NEVER;
173  }
174  return home.ES_SUBSUMED(*this);
175 #undef GECODE_INT_STATUS
176  }
177 
178  /*
179  * Boolean disjunction propagator (true)
180  *
181  */
182 
183  template<class BV>
185  TerOrTrue<BV>::TerOrTrue(Home home, BV b0, BV b1, BV b2)
186  : BoolBinary<BV,BV>(home,b0,b1), x2(b2) {}
187 
188  template<class BV>
189  forceinline size_t
191  (void) BoolBinary<BV,BV>::dispose(home);
192  return sizeof(*this);
193  }
194 
195  template<class BV>
198  : BoolBinary<BV,BV>(home,share,p) {
199  x2.update(home,share,p.x2);
200  }
201 
202  template<class BV>
205  BV b0, BV b1, BV b2)
206  : BoolBinary<BV,BV>(home,share,p,b0,b1) {
207  x2.update(home,share,b2);
208  }
209 
210  template<class BV>
211  Actor*
212  TerOrTrue<BV>::copy(Space& home, bool share) {
213  assert(x0.none() && x1.none());
214  if (x2.one())
215  return new (home) OrTrueSubsumed<BV>(home,share,*this,x0,x1);
216  else if (x2.zero())
217  return new (home) BinOrTrue<BV,BV>(home,share,*this,x0,x1);
218  else
219  return new (home) TerOrTrue<BV>(home,share,*this);
220  }
221 
222  template<class BV>
224  TerOrTrue<BV>::post(Home home, BV b0, BV b1, BV b2) {
225  (void) new (home) TerOrTrue<BV>(home,b0,b1,b2);
226  return ES_OK;
227  }
228 
229  template<class BV>
230  ExecStatus
232 #define GECODE_INT_STATUS(S0,S1,S2) \
233  ((BV::S0<<(2*BV::BITS))|(BV::S1<<(1*BV::BITS))|(BV::S2<<(0*BV::BITS)))
234  switch ((x0.status() << (2*BV::BITS)) | (x1.status() << (1*BV::BITS)) |
235  (x2.status() << (0*BV::BITS))) {
236  case GECODE_INT_STATUS(NONE,NONE,NONE):
237  case GECODE_INT_STATUS(NONE,NONE,ZERO):
238  case GECODE_INT_STATUS(NONE,NONE,ONE):
239  GECODE_NEVER;
240  case GECODE_INT_STATUS(NONE,ZERO,NONE):
241  std::swap(x1,x2); x1.subscribe(home,*this,PC_BOOL_VAL);
242  return ES_FIX;
243  case GECODE_INT_STATUS(NONE,ZERO,ZERO):
244  GECODE_ME_CHECK(x0.one_none(home)); break;
245  case GECODE_INT_STATUS(NONE,ZERO,ONE):
246  case GECODE_INT_STATUS(NONE,ONE,NONE):
247  case GECODE_INT_STATUS(NONE,ONE,ZERO):
248  case GECODE_INT_STATUS(NONE,ONE,ONE):
249  break;
250  case GECODE_INT_STATUS(ZERO,NONE,NONE):
251  std::swap(x0,x2); x0.subscribe(home,*this,PC_BOOL_VAL);
252  return ES_FIX;
253  case GECODE_INT_STATUS(ZERO,NONE,ZERO):
254  GECODE_ME_CHECK(x1.one_none(home)); break;
255  case GECODE_INT_STATUS(ZERO,NONE,ONE):
256  break;
257  case GECODE_INT_STATUS(ZERO,ZERO,NONE):
258  GECODE_ME_CHECK(x2.one_none(home)); break;
259  case GECODE_INT_STATUS(ZERO,ZERO,ZERO):
260  return ES_FAILED;
261  case GECODE_INT_STATUS(ZERO,ZERO,ONE):
262  case GECODE_INT_STATUS(ZERO,ONE,NONE):
263  case GECODE_INT_STATUS(ZERO,ONE,ZERO):
264  case GECODE_INT_STATUS(ZERO,ONE,ONE):
265  case GECODE_INT_STATUS(ONE,NONE,NONE):
266  case GECODE_INT_STATUS(ONE,NONE,ZERO):
267  case GECODE_INT_STATUS(ONE,NONE,ONE):
268  case GECODE_INT_STATUS(ONE,ZERO,NONE):
269  case GECODE_INT_STATUS(ONE,ZERO,ZERO):
270  case GECODE_INT_STATUS(ONE,ZERO,ONE):
271  case GECODE_INT_STATUS(ONE,ONE,NONE):
272  case GECODE_INT_STATUS(ONE,ONE,ZERO):
273  case GECODE_INT_STATUS(ONE,ONE,ONE):
274  break;
275  default:
276  GECODE_NEVER;
277  }
278  return home.ES_SUBSUMED(*this);
279 #undef GECODE_INT_STATUS
280  }
281 
282  /*
283  * Boolean disjunction propagator (true)
284  *
285  */
286 
287  template<class BV>
289  QuadOrTrue<BV>::QuadOrTrue(Home home, BV b0, BV b1, BV b2, BV b3)
290  : BoolBinary<BV,BV>(home,b0,b1), x2(b2), x3(b3) {}
291 
292  template<class BV>
293  forceinline size_t
295  (void) BoolBinary<BV,BV>::dispose(home);
296  return sizeof(*this);
297  }
298 
299  template<class BV>
302  : BoolBinary<BV,BV>(home,share,p) {
303  x2.update(home,share,p.x2);
304  x3.update(home,share,p.x3);
305  }
306 
307  template<class BV>
310  BV b0, BV b1, BV b2, BV b3)
311  : BoolBinary<BV,BV>(home,share,p,b0,b1) {
312  x2.update(home,share,b2);
313  x3.update(home,share,b3);
314  }
315 
316  template<class BV>
317  Actor*
318  QuadOrTrue<BV>::copy(Space& home, bool share) {
319  assert(x0.none() && x1.none());
320  if (x2.one() || x3.one())
321  return new (home) OrTrueSubsumed<BV>(home,share,*this,x0,x1);
322  else if (x2.zero() && x3.zero())
323  return new (home) BinOrTrue<BV,BV>(home,share,*this,x0,x1);
324  else if (x2.zero())
325  return new (home) TerOrTrue<BV>(home,share,*this,x0,x1,x3);
326  else if (x3.zero())
327  return new (home) TerOrTrue<BV>(home,share,*this,x0,x1,x2);
328  else
329  return new (home) QuadOrTrue<BV>(home,share,*this);
330  }
331 
332  template<class BV>
334  QuadOrTrue<BV>::post(Home home, BV b0, BV b1, BV b2, BV b3) {
335  (void) new (home) QuadOrTrue<BV>(home,b0,b1,b2,b3);
336  return ES_OK;
337  }
338 
339  template<class BV>
340  ExecStatus
342 #define GECODE_INT_STATUS(S0,S1,S2,S3) \
343  ((BV::S0 << (3*BV::BITS)) | (BV::S1 << (2*BV::BITS)) | \
344  (BV::S2 << (1*BV::BITS)) | (BV::S3 << (0*BV::BITS)))
345  switch ((x0.status() << (3*BV::BITS)) | (x1.status() << (2*BV::BITS)) |
346  (x2.status() << (1*BV::BITS)) | (x3.status() << (0*BV::BITS))) {
347  case GECODE_INT_STATUS(NONE,NONE,NONE,NONE):
348  case GECODE_INT_STATUS(NONE,NONE,NONE,ZERO):
349  case GECODE_INT_STATUS(NONE,NONE,NONE,ONE):
350  case GECODE_INT_STATUS(NONE,NONE,ZERO,NONE):
351  case GECODE_INT_STATUS(NONE,NONE,ZERO,ZERO):
352  case GECODE_INT_STATUS(NONE,NONE,ZERO,ONE):
353  case GECODE_INT_STATUS(NONE,NONE,ONE,NONE):
354  case GECODE_INT_STATUS(NONE,NONE,ONE,ZERO):
355  case GECODE_INT_STATUS(NONE,NONE,ONE,ONE):
356  GECODE_NEVER;
357  case GECODE_INT_STATUS(NONE,ZERO,NONE,NONE):
358  case GECODE_INT_STATUS(NONE,ZERO,NONE,ZERO):
359  std::swap(x1,x2); x1.subscribe(home,*this,PC_BOOL_VAL,false);
360  return ES_FIX;
361  case GECODE_INT_STATUS(NONE,ZERO,NONE,ONE):
362  break;
363  case GECODE_INT_STATUS(NONE,ZERO,ZERO,NONE):
364  std::swap(x1,x3); x1.subscribe(home,*this,PC_BOOL_VAL,false);
365  return ES_FIX;
366  case GECODE_INT_STATUS(NONE,ZERO,ZERO,ZERO):
367  GECODE_ME_CHECK(x0.one_none(home)); break;
368  case GECODE_INT_STATUS(NONE,ZERO,ZERO,ONE):
369  case GECODE_INT_STATUS(NONE,ZERO,ONE,NONE):
370  case GECODE_INT_STATUS(NONE,ZERO,ONE,ZERO):
371  case GECODE_INT_STATUS(NONE,ZERO,ONE,ONE):
372  case GECODE_INT_STATUS(NONE,ONE,NONE,NONE):
373  case GECODE_INT_STATUS(NONE,ONE,NONE,ZERO):
374  case GECODE_INT_STATUS(NONE,ONE,NONE,ONE):
375  case GECODE_INT_STATUS(NONE,ONE,ZERO,NONE):
376  case GECODE_INT_STATUS(NONE,ONE,ZERO,ZERO):
377  case GECODE_INT_STATUS(NONE,ONE,ZERO,ONE):
378  case GECODE_INT_STATUS(NONE,ONE,ONE,NONE):
379  case GECODE_INT_STATUS(NONE,ONE,ONE,ZERO):
380  case GECODE_INT_STATUS(NONE,ONE,ONE,ONE):
381  break;
382  case GECODE_INT_STATUS(ZERO,NONE,NONE,NONE):
383  case GECODE_INT_STATUS(ZERO,NONE,NONE,ZERO):
384  std::swap(x0,x2); x0.subscribe(home,*this,PC_BOOL_VAL,false);
385  return ES_FIX;
386  case GECODE_INT_STATUS(ZERO,NONE,NONE,ONE):
387  break;
388  case GECODE_INT_STATUS(ZERO,NONE,ZERO,NONE):
389  std::swap(x0,x3); x0.subscribe(home,*this,PC_BOOL_VAL,false);
390  return ES_FIX;
391  case GECODE_INT_STATUS(ZERO,NONE,ZERO,ZERO):
392  GECODE_ME_CHECK(x1.one_none(home)); break;
393  case GECODE_INT_STATUS(ZERO,NONE,ZERO,ONE):
394  case GECODE_INT_STATUS(ZERO,NONE,ONE,NONE):
395  case GECODE_INT_STATUS(ZERO,NONE,ONE,ZERO):
396  case GECODE_INT_STATUS(ZERO,NONE,ONE,ONE):
397  break;
398  case GECODE_INT_STATUS(ZERO,ZERO,NONE,NONE):
399  std::swap(x0,x2); x0.subscribe(home,*this,PC_BOOL_VAL,false);
400  std::swap(x1,x3); x1.subscribe(home,*this,PC_BOOL_VAL,false);
401  return ES_FIX;
402  case GECODE_INT_STATUS(ZERO,ZERO,NONE,ZERO):
403  GECODE_ME_CHECK(x2.one_none(home)); break;
404  case GECODE_INT_STATUS(ZERO,ZERO,NONE,ONE):
405  break;
406  case GECODE_INT_STATUS(ZERO,ZERO,ZERO,NONE):
407  GECODE_ME_CHECK(x3.one_none(home)); break;
408  case GECODE_INT_STATUS(ZERO,ZERO,ZERO,ZERO):
409  return ES_FAILED;
410  case GECODE_INT_STATUS(ZERO,ZERO,ZERO,ONE):
411  case GECODE_INT_STATUS(ZERO,ZERO,ONE,NONE):
412  case GECODE_INT_STATUS(ZERO,ZERO,ONE,ZERO):
413  case GECODE_INT_STATUS(ZERO,ZERO,ONE,ONE):
414  case GECODE_INT_STATUS(ZERO,ONE,NONE,NONE):
415  case GECODE_INT_STATUS(ZERO,ONE,NONE,ZERO):
416  case GECODE_INT_STATUS(ZERO,ONE,NONE,ONE):
417  case GECODE_INT_STATUS(ZERO,ONE,ZERO,NONE):
418  case GECODE_INT_STATUS(ZERO,ONE,ZERO,ZERO):
419  case GECODE_INT_STATUS(ZERO,ONE,ZERO,ONE):
420  case GECODE_INT_STATUS(ZERO,ONE,ONE,NONE):
421  case GECODE_INT_STATUS(ZERO,ONE,ONE,ZERO):
422  case GECODE_INT_STATUS(ZERO,ONE,ONE,ONE):
423  case GECODE_INT_STATUS(ONE,NONE,NONE,NONE):
424  case GECODE_INT_STATUS(ONE,NONE,NONE,ZERO):
425  case GECODE_INT_STATUS(ONE,NONE,NONE,ONE):
426  case GECODE_INT_STATUS(ONE,NONE,ZERO,NONE):
427  case GECODE_INT_STATUS(ONE,NONE,ZERO,ZERO):
428  case GECODE_INT_STATUS(ONE,NONE,ZERO,ONE):
429  case GECODE_INT_STATUS(ONE,NONE,ONE,NONE):
430  case GECODE_INT_STATUS(ONE,NONE,ONE,ZERO):
431  case GECODE_INT_STATUS(ONE,NONE,ONE,ONE):
432  case GECODE_INT_STATUS(ONE,ZERO,NONE,NONE):
433  case GECODE_INT_STATUS(ONE,ZERO,NONE,ZERO):
434  case GECODE_INT_STATUS(ONE,ZERO,NONE,ONE):
435  case GECODE_INT_STATUS(ONE,ZERO,ZERO,NONE):
436  case GECODE_INT_STATUS(ONE,ZERO,ZERO,ZERO):
437  case GECODE_INT_STATUS(ONE,ZERO,ZERO,ONE):
438  case GECODE_INT_STATUS(ONE,ZERO,ONE,NONE):
439  case GECODE_INT_STATUS(ONE,ZERO,ONE,ZERO):
440  case GECODE_INT_STATUS(ONE,ZERO,ONE,ONE):
441  case GECODE_INT_STATUS(ONE,ONE,NONE,NONE):
442  case GECODE_INT_STATUS(ONE,ONE,NONE,ZERO):
443  case GECODE_INT_STATUS(ONE,ONE,NONE,ONE):
444  case GECODE_INT_STATUS(ONE,ONE,ZERO,NONE):
445  case GECODE_INT_STATUS(ONE,ONE,ZERO,ZERO):
446  case GECODE_INT_STATUS(ONE,ONE,ZERO,ONE):
447  case GECODE_INT_STATUS(ONE,ONE,ONE,NONE):
448  case GECODE_INT_STATUS(ONE,ONE,ONE,ZERO):
449  case GECODE_INT_STATUS(ONE,ONE,ONE,ONE):
450  break;
451  default:
452  GECODE_NEVER;
453  }
454  return home.ES_SUBSUMED(*this);
455 #undef GECODE_INT_STATUS
456  }
457 
458  /*
459  * Boolean disjunction propagator
460  *
461  */
462 
463  template<class BVA, class BVB, class BVC>
465  Or<BVA,BVB,BVC>::Or(Home home, BVA b0, BVB b1, BVC b2)
466  : BoolTernary<BVA,BVB,BVC>(home,b0,b1,b2) {}
467 
468  template<class BVA, class BVB, class BVC>
471  : BoolTernary<BVA,BVB,BVC>(home,share,p) {}
472 
473  template<class BVA, class BVB, class BVC>
475  Or<BVA,BVB,BVC>::Or(Space& home, bool share, Propagator& p,
476  BVA b0, BVB b1, BVC b2)
477  : BoolTernary<BVA,BVB,BVC>(home,share,p,b0,b1,b2) {}
478 
479  template<class BVA, class BVB, class BVC>
480  Actor*
481  Or<BVA,BVB,BVC>::copy(Space& home, bool share) {
482  if (x2.one()) {
483  assert(x0.none() && x1.none());
484  return new (home) BinOrTrue<BVA,BVB>(home,share,*this,x0,x1);
485  } else if (x0.zero()) {
486  assert(x1.none() && x2.none());
487  return new (home) Eq<BVB,BVC>(home,share,*this,x1,x2);
488  } else if (x1.zero()) {
489  assert(x0.none() && x2.none());
490  return new (home) Eq<BVA,BVC>(home,share,*this,x0,x2);
491  } else {
492  return new (home) Or<BVA,BVB,BVC>(home,share,*this);
493  }
494  }
495 
496  template<class BVA, class BVB, class BVC>
497  inline ExecStatus
498  Or<BVA,BVB,BVC>::post(Home home, BVA b0, BVB b1, BVC b2) {
499  if (b2.zero()) {
500  GECODE_ME_CHECK(b0.zero(home));
501  GECODE_ME_CHECK(b1.zero(home));
502  } else if (b2.one()) {
503  return BinOrTrue<BVA,BVB>::post(home,b0,b1);
504  } else {
505  switch (bool_test(b0,b1)) {
506  case BT_SAME:
507  return Eq<BVA,BVC>::post(home,b0,b2);
508  case BT_COMP:
509  GECODE_ME_CHECK(b2.one(home));
510  break;
511  case BT_NONE:
512  if (b0.one() || b1.one()) {
513  GECODE_ME_CHECK(b2.one(home));
514  } else if (b0.zero()) {
515  return Eq<BVB,BVC>::post(home,b1,b2);
516  } else if (b1.zero()) {
517  return Eq<BVA,BVC>::post(home,b0,b2);
518  } else {
519  (void) new (home) Or<BVA,BVB,BVC>(home,b0,b1,b2);
520  }
521  break;
522  default: GECODE_NEVER;
523  }
524  }
525  return ES_OK;
526  }
527 
528  template<class BVA, class BVB, class BVC>
529  ExecStatus
531 #define GECODE_INT_STATUS(S0,S1,S2) \
532  ((BVA::S0<<(2*BVA::BITS))|(BVB::S1<<(1*BVB::BITS))|(BVC::S2<<(0*BVC::BITS)))
533  switch ((x0.status() << (2*BVA::BITS)) | (x1.status() << (1*BVB::BITS)) |
534  (x2.status() << (0*BVC::BITS))) {
535  case GECODE_INT_STATUS(NONE,NONE,NONE):
536  GECODE_NEVER;
537  case GECODE_INT_STATUS(NONE,NONE,ZERO):
538  GECODE_ME_CHECK(x0.zero_none(home));
539  GECODE_ME_CHECK(x1.zero_none(home));
540  break;
541  case GECODE_INT_STATUS(NONE,NONE,ONE):
542  return ES_FIX;
543  case GECODE_INT_STATUS(NONE,ZERO,NONE):
544  switch (bool_test(x0,x2)) {
545  case BT_SAME: return home.ES_SUBSUMED(*this);
546  case BT_COMP: return ES_FAILED;
547  case BT_NONE: return ES_FIX;
548  default: GECODE_NEVER;
549  }
550  GECODE_NEVER;
551  case GECODE_INT_STATUS(NONE,ZERO,ZERO):
552  GECODE_ME_CHECK(x0.zero_none(home)); break;
553  case GECODE_INT_STATUS(NONE,ZERO,ONE):
554  GECODE_ME_CHECK(x0.one_none(home)); break;
555  case GECODE_INT_STATUS(NONE,ONE,NONE):
556  GECODE_ME_CHECK(x2.one_none(home)); break;
557  case GECODE_INT_STATUS(NONE,ONE,ZERO):
558  return ES_FAILED;
559  case GECODE_INT_STATUS(NONE,ONE,ONE):
560  break;
561  case GECODE_INT_STATUS(ZERO,NONE,NONE):
562  switch (bool_test(x1,x2)) {
563  case BT_SAME: return home.ES_SUBSUMED(*this);
564  case BT_COMP: return ES_FAILED;
565  case BT_NONE: return ES_FIX;
566  default: GECODE_NEVER;
567  }
568  GECODE_NEVER;
569  case GECODE_INT_STATUS(ZERO,NONE,ZERO):
570  GECODE_ME_CHECK(x1.zero_none(home)); break;
571  case GECODE_INT_STATUS(ZERO,NONE,ONE):
572  GECODE_ME_CHECK(x1.one_none(home)); break;
573  case GECODE_INT_STATUS(ZERO,ZERO,NONE):
574  GECODE_ME_CHECK(x2.zero_none(home)); break;
575  case GECODE_INT_STATUS(ZERO,ZERO,ZERO):
576  break;
577  case GECODE_INT_STATUS(ZERO,ZERO,ONE):
578  return ES_FAILED;
579  case GECODE_INT_STATUS(ZERO,ONE,NONE):
580  GECODE_ME_CHECK(x2.one_none(home)); break;
581  case GECODE_INT_STATUS(ZERO,ONE,ZERO):
582  return ES_FAILED;
583  case GECODE_INT_STATUS(ZERO,ONE,ONE):
584  break;
585  case GECODE_INT_STATUS(ONE,NONE,NONE):
586  GECODE_ME_CHECK(x2.one_none(home)); break;
587  case GECODE_INT_STATUS(ONE,NONE,ZERO):
588  return ES_FAILED;
589  case GECODE_INT_STATUS(ONE,NONE,ONE):
590  break;
591  case GECODE_INT_STATUS(ONE,ZERO,NONE):
592  GECODE_ME_CHECK(x2.one_none(home)); break;
593  case GECODE_INT_STATUS(ONE,ZERO,ZERO):
594  return ES_FAILED;
595  case GECODE_INT_STATUS(ONE,ZERO,ONE):
596  break;
597  case GECODE_INT_STATUS(ONE,ONE,NONE):
598  GECODE_ME_CHECK(x2.one_none(home)); break;
599  case GECODE_INT_STATUS(ONE,ONE,ZERO):
600  return ES_FAILED;
601  case GECODE_INT_STATUS(ONE,ONE,ONE):
602  break;
603  default:
604  GECODE_NEVER;
605  }
606  return home.ES_SUBSUMED(*this);
607 #undef GECODE_INT_STATUS
608  }
609 
610  /*
611  * N-ary Boolean disjunction propagator (true)
612  *
613  */
614 
615  template<class BV>
618  : BinaryPropagator<BV,PC_BOOL_VAL>(home,b[0],b[1]), x(b) {
619  assert(x.size() > 2);
620  x.drop_fst(2);
621  }
622 
623  template<class BV>
624  PropCost
625  NaryOrTrue<BV>::cost(const Space&, const ModEventDelta&) const {
627  }
628 
629  template<class BV>
632  : BinaryPropagator<BV,PC_BOOL_VAL>(home,share,p) {
633  x.update(home,share,p.x);
634  }
635 
636  template<class BV>
637  Actor*
638  NaryOrTrue<BV>::copy(Space& home, bool share) {
639  int n = x.size();
640  if (n > 0) {
641  // Eliminate all zeros and find a one
642  for (int i=n; i--; )
643  if (x[i].one()) {
644  // Only keep the one
645  x[0]=x[i]; x.size(1);
646  return new (home) OrTrueSubsumed<BV>(home,share,*this,x0,x1);
647  } else if (x[i].zero()) {
648  // Eliminate the zero
649  x[i]=x[--n];
650  }
651  x.size(n);
652  }
653  switch (n) {
654  case 0:
655  return new (home) BinOrTrue<BV,BV>(home,share,*this,x0,x1);
656  case 1:
657  return new (home) TerOrTrue<BV>(home,share,*this,x0,x1,x[0]);
658  case 2:
659  return new (home) QuadOrTrue<BV>(home,share,*this,x0,x1,x[0],x[1]);
660  default:
661  return new (home) NaryOrTrue<BV>(home,share,*this);
662  }
663  }
664 
665  template<class BV>
666  inline ExecStatus
668  for (int i=b.size(); i--; )
669  if (b[i].one())
670  return ES_OK;
671  else if (b[i].zero())
672  b.move_lst(i);
673  if (b.size() == 0)
674  return ES_FAILED;
675  if (b.size() == 1) {
676  GECODE_ME_CHECK(b[0].one(home));
677  } else if (b.size() == 2) {
678  return BinOrTrue<BV,BV>::post(home,b[0],b[1]);
679  } else if (b.size() == 3) {
680  return TerOrTrue<BV>::post(home,b[0],b[1],b[2]);
681  } else if (b.size() == 4) {
682  return QuadOrTrue<BV>::post(home,b[0],b[1],b[2],b[3]);
683  } else {
684  (void) new (home) NaryOrTrue(home,b);
685  }
686  return ES_OK;
687  }
688 
689  template<class BV>
690  forceinline size_t
693  return sizeof(*this);
694  }
695 
696  template<class BV>
698  NaryOrTrue<BV>::resubscribe(Space& home, BV& x0, BV x1) {
699  if (x0.zero()) {
700  int n = x.size();
701  for (int i=n; i--; )
702  if (x[i].one()) {
703  return home.ES_SUBSUMED(*this);
704  } else if (x[i].zero()) {
705  x[i] = x[--n];
706  } else {
707  // Move to x0 and subscribe
708  x0=x[i]; x[i]=x[--n];
709  x.size(n);
710  x0.subscribe(home,*this,PC_BOOL_VAL,false);
711  return ES_FIX;
712  }
713  // All views have been assigned!
714  GECODE_ME_CHECK(x1.one(home));
715  return home.ES_SUBSUMED(*this);
716  }
717  return ES_FIX;
718  }
719 
720  template<class BV>
721  ExecStatus
723  if (x0.one())
724  return home.ES_SUBSUMED(*this);
725  if (x1.one())
726  return home.ES_SUBSUMED(*this);
727  GECODE_ES_CHECK(resubscribe(home,x0,x1));
728  GECODE_ES_CHECK(resubscribe(home,x1,x0));
729  return ES_FIX;
730  }
731 
732 
733  /*
734  * N-ary Boolean disjunction propagator
735  *
736  */
737 
738  template<class VX, class VY>
741  : MixNaryOnePropagator<VX,PC_BOOL_NONE,VY,PC_BOOL_VAL>(home,x,y),
742  n_zero(0), c(home) {
743  x.subscribe(home,*new (home) Advisor(home,*this,c));
744  }
745 
746  template<class VX, class VY>
749  : MixNaryOnePropagator<VX,PC_BOOL_NONE,VY,PC_BOOL_VAL>(home,share,p),
750  n_zero(p.n_zero) {
751  c.update(home,share,p.c);
752  }
753 
754  template<class VX, class VY>
755  Actor*
756  NaryOr<VX,VY>::copy(Space& home, bool share) {
757  assert(n_zero < x.size());
758  if (n_zero > 0) {
759  int n=x.size();
760  // Eliminate all zeros
761  for (int i=n; i--; )
762  if (x[i].zero())
763  x[i]=x[--n];
764  x.size(n);
765  n_zero = 0;
766  }
767  assert(n_zero < x.size());
768  return new (home) NaryOr<VX,VY>(home,share,*this);
769  }
770 
771  template<class VX, class VY>
772  inline ExecStatus
774  assert(!x.shared(home));
775  if (y.one())
776  return NaryOrTrue<VX>::post(home,x);
777  if (y.zero()) {
778  for (int i=x.size(); i--; )
779  GECODE_ME_CHECK(x[i].zero(home));
780  return ES_OK;
781  }
782  for (int i=x.size(); i--; )
783  if (x[i].one()) {
784  GECODE_ME_CHECK(y.one_none(home));
785  return ES_OK;
786  } else if (x[i].zero()) {
787  x.move_lst(i);
788  }
789  if (x.size() == 0) {
790  GECODE_ME_CHECK(y.zero_none(home));
791  } else if (x.size() == 1) {
792  return Eq<VX,VY>::post(home,x[0],y);
793  } else if (x.size() == 2) {
794  return Or<VX,VX,VY>::post(home,x[0],x[1],y);
795  } else {
796  (void) new (home) NaryOr(home,x,y);
797  }
798  return ES_OK;
799  }
800 
801  template<class VX, class VY>
802  PropCost
803  NaryOr<VX,VY>::cost(const Space&, const ModEventDelta&) const {
805  }
806 
807  template<class VX, class VY>
808  ExecStatus
810  // Decides whether the propagator must be run
811  if (VX::zero(d) && (++n_zero < x.size()))
812  return ES_FIX;
813  else
814  return ES_NOFIX;
815  }
816 
817  template<class VX, class VY>
818  forceinline size_t
820  Advisors<Advisor> as(c);
821  x.cancel(home,as.advisor());
822  c.dispose(home);
824  ::dispose(home);
825  return sizeof(*this);
826  }
827 
828  template<class VX, class VY>
829  ExecStatus
831  if (y.one())
832  GECODE_REWRITE(*this,NaryOrTrue<VX>::post(home(*this),x));
833  if (y.zero()) {
834  // Note that this might trigger the advisor of this propagator!
835  for (int i = x.size(); i--; )
836  GECODE_ME_CHECK(x[i].zero(home));
837  } else if (n_zero == x.size()) {
838  // All views are zero
839  GECODE_ME_CHECK(y.zero_none(home));
840  } else {
841  // There is exactly one view which is one
842  GECODE_ME_CHECK(y.one_none(home));
843  }
844  return home.ES_SUBSUMED(*this);
845  }
846 
847 }}}
848 
849 // STATISTICS: int-prop
850 
#define GECODE_REWRITE(prop, post)
Rewrite propagator by executing post function.
Definition: macros.hpp:109
void update(Space &, bool share, ViewArray< View > &a)
Update array to be a clone of array a.
Definition: array.hpp:1387
TerOrTrue(Home home, BV b0, BV b1, BV b2)
Constructor for posting.
Definition: or.hpp:185
static ExecStatus post(Home home, BV b0, BV b1)
Post propagator.
Definition: or.hpp:70
ExecStatus ES_SUBSUMED(Propagator &p)
Definition: core.hpp:2973
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
Definition: or.hpp:231
virtual ExecStatus advise(Space &home, Advisor &a, const Delta &d)
Give advice to propagator.
Definition: or.hpp:809
bool one(const Gecode::FloatValArgs &a)
Check whether has only one coefficients.
Definition: linear.cpp:50
ExecStatus resubscribe(Space &home, Propagator &p, VX &x0, ViewArray< VX > &x, VY &x1, ViewArray< VY > &y)
Definition: clause.hpp:142
BV x2
Boolean view without subscription.
Definition: bool.hh:269
virtual size_t dispose(Space &home)
Delete propagator and return its size.
Definition: or.hpp:294
Mixed (n+1)-ary propagator.
Definition: propagator.hpp:268
A & advisor(void) const
Return advisor.
Definition: core.hpp:3408
ExecStatus resubscribe(Space &home, BV &x0, BV x1)
Update subscription.
Definition: or.hpp:698
Base-class for propagators.
Definition: core.hpp:755
Base-class for advisors.
Definition: core.hpp:926
static ExecStatus post(Home home, BVA b0, BVB b1, BVC b2)
Post propagator .
Definition: or.hpp:498
Class to iterate over advisors of a council.
Definition: core.hpp:227
static ExecStatus post(Home home, BV b0, BV b1, BV b2, BV b3)
Post propagator .
Definition: or.hpp:334
Propagation has computed fixpoint.
Definition: core.hpp:528
static PropCost unary(PropCost::Mod m)
Single variable for modifier pcm.
Definition: core.hpp:4058
virtual Actor * copy(Space &home, bool share)
Copy propagator during cloning.
Definition: or.hpp:89
Computation spaces.
Definition: core.hpp:1362
Quarternary Boolean disjunction propagator (true)
Definition: bool.hh:295
Base-class for both propagators and branchers.
Definition: core.hpp:666
Or(Home home, BVA b0, BVB b1, BVC b2)
Constructor for posting.
Definition: or.hpp:465
virtual size_t dispose(Space &home)
Delete propagator and return its size.
Definition: or.hpp:190
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
Definition: or.hpp:341
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
Definition: or.hpp:722
Gecode::IntSet d(v, 7)
NaryOrTrue(Home home, ViewArray< BV > &x)
Constructor for posting.
Definition: or.hpp:617
#define GECODE_ES_CHECK(es)
Check whether execution status es is failed or subsumed, and forward failure or subsumption.
Definition: macros.hpp:84
Same variable.
Definition: view.hpp:1666
Gecode::FloatVal c(-8, 8)
Binary Boolean disjunction propagator (subsumed)
Definition: or.hpp:42
Ternary Boolean disjunction propagator (true)
Definition: bool.hh:264
int p
Number of positive literals for node type.
Definition: bool-expr.cpp:236
QuadOrTrue(Home home, BV b0, BV b1, BV b2, BV b3)
Constructor for posting.
Definition: or.hpp:289
Gecode::IntArgs i(4, 1, 2, 3, 4)
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
Definition: or.hpp:830
int n
Number of negative literals for node type.
Definition: bool-expr.cpp:238
static ExecStatus post(Home home, BVA x0, BVB x1)
Post propagator .
Definition: eq.hpp:64
Execution has resulted in failure.
Definition: core.hpp:525
const Gecode::PropCond PC_BOOL_NONE
Propagation condition to be ignored (convenience)
Definition: var-type.hpp:118
Binary propagator.
Definition: propagator.hpp:87
Council< Advisor > c
The advisor council.
Definition: bool.hh:363
void subscribe(Space &home, Propagator &p, PropCond pc, bool process=true)
Subscribe propagator p with propagation condition pc to variable.
Definition: array.hpp:1400
bool shared(const Space &home) const
Test whether array contains shared views.
Definition: array.hpp:1511
virtual Actor * copy(Space &home, bool share)
Copy propagator during cloning.
Definition: or.hpp:318
ModEventDelta med
A set of modification events (used during propagation)
Definition: core.hpp:764
NaryOr(Home home, ViewArray< VX > &x, VY y)
Constructor for posting.
Definition: or.hpp:740
virtual size_t dispose(Space &home)
Delete propagator and return its size.
Definition: or.hpp:691
Boolean disjunction propagator.
Definition: bool.hh:328
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
Definition: or.hpp:530
virtual size_t dispose(Space &home)
Delete propagator and return its size.
Definition: or.hpp:819
virtual Actor * copy(Space &home, bool share)
Copy propagator during cloning.
Definition: or.hpp:638
BinOrTrue(Home home, BVA b0, BVB b1)
Constructor for posting.
Definition: or.hpp:107
Boolean equality propagator.
Definition: bool.hh:105
BoolTest bool_test(const BoolView &b0, const BoolView &b1)
Definition: bool-test.hpp:45
void drop_fst(int i)
Drop views from positions 0 to i-1 from array.
Definition: array.hpp:1301
virtual Actor * copy(Space &home, bool share)
Copy propagator during cloning.
Definition: or.hpp:123
#define GECODE_ME_CHECK(me)
Check whether modification event me is failed, and forward failure.
Definition: macros.hpp:45
Same variable but complement.
Definition: view.hpp:1667
void move_lst(int i)
Move view from position size()-1 to position i (truncate array by one)
Definition: array.hpp:1295
BV x2
Boolean view without subscription.
Definition: bool.hh:300
virtual PropCost cost(const Space &home, const ModEventDelta &med) const
Cost function (defined as low unary)
Definition: or.hpp:625
static ExecStatus post(Home home, BV b0, BV b1, BV b2)
Post propagator .
Definition: or.hpp:224
Boolean n-ary disjunction propagator (true)
Definition: bool.hh:391
static ExecStatus post(Home home, BVA b0, BVB b1)
Post propagator .
Definition: or.hpp:129
ViewArray< BV > x
Views not yet subscribed to.
Definition: bool.hh:396
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
virtual PropCost cost(const Space &home, const ModEventDelta &med) const
Cost function (defined as low unary)
Definition: or.hpp:803
Propagation cost.
Definition: core.hpp:537
friend class Advisor
Definition: core.hpp:759
Boolean n-ary disjunction propagator.
Definition: bool.hh:355
Binary Boolean disjunction propagator (true)
Definition: bool.hh:237
ExecStatus
Definition: core.hpp:523
#define forceinline
Definition: config.hpp:132
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
Definition: or.hpp:152
virtual Actor * copy(Space &home, bool share)
Copy propagator during cloning.
Definition: or.hpp:212
Execution is okay.
Definition: core.hpp:527
Propagation has not computed fixpoint.
Definition: core.hpp:526
static ExecStatus post(Home home, ViewArray< BV > &b)
Post propagator .
Definition: or.hpp:667
int size(void) const
Return size of array (number of elements)
Definition: array.hpp:1215
virtual Actor * copy(Space &home, bool share)
Copy propagator during cloning.
Definition: or.hpp:481
No sharing.
Definition: view.hpp:1665
BV x3
Boolean view without subscription.
Definition: bool.hh:302
static ExecStatus post(Home home, ViewArray< VX > &x, VY y)
Post propagator .
Definition: or.hpp:773
virtual Actor * copy(Space &home, bool share)
Copy propagator during cloning.
Definition: or.hpp:756
OrTrueSubsumed(Space &home, bool share, OrTrueSubsumed &p)
Constructor for cloning p.
Definition: or.hpp:78
struct Gecode::@518::NNF::@57::@58 b
For binary nodes (and, or, eqv)
Gecode toplevel namespace
Base-class for ternary Boolean propagators.
Definition: bool.hh:79
Base-class for binary Boolean propagators.
Definition: bool.hh:59
int ModEventDelta
Modification event deltas.
Definition: core.hpp:173
Home class for posting propagators
Definition: core.hpp:717
static PropCost binary(PropCost::Mod m)
Two variables for modifier pcm.
Definition: core.hpp:4054
#define GECODE_NEVER
Assert that this command is never executed.
Definition: macros.hpp:60
#define GECODE_INT_STATUS(S0, S1)
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
Definition: or.hpp:95
const Gecode::PropCond PC_BOOL_VAL
Propagate when a view becomes assigned (single value)
Definition: var-type.hpp:126