Generated on Thu Jan 16 2025 00:00:00 for Gecode by doxygen 1.14.0
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 * This file is part of Gecode, the generic constraint
10 * development environment:
11 * http://www.gecode.org
12 *
13 * Permission is hereby granted, free of charge, to any person obtaining
14 * a copy of this software and associated documentation files (the
15 * "Software"), to deal in the Software without restriction, including
16 * without limitation the rights to use, copy, modify, merge, publish,
17 * distribute, sublicense, and/or sell copies of the Software, and to
18 * permit persons to whom the Software is furnished to do so, subject to
19 * the following conditions:
20 *
21 * The above copyright notice and this permission notice shall be
22 * included in all copies or substantial portions of the Software.
23 *
24 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
28 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
29 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
30 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 *
32 */
33
34namespace Gecode { namespace Int { namespace Bool {
35
37 template<class BV>
38 class OrTrueSubsumed : public BoolBinary<BV,BV> {
39 protected:
40 using BoolBinary<BV,BV>::x0;
41 using BoolBinary<BV,BV>::x1;
45 static ExecStatus post(Home home, BV b0, BV b1);
46 public:
48 OrTrueSubsumed(Home home, BV b0, BV b1);
51 BV b0, BV b1);
53 virtual Actor* copy(Space& home);
55 virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
56 };
57
58 template<class BV>
61 (Home home, BV b0, BV b1)
62 : BoolBinary<BV,BV>(home,b0,b1) {}
63
64 template<class BV>
66 OrTrueSubsumed<BV>::post(Home home, BV b0, BV b1) {
67 (void) new (home) OrTrueSubsumed(home,b0,b1);
68 return ES_OK;
69 }
70
71 template<class BV>
76
77 template<class BV>
80 BV b0, BV b1)
81 : BoolBinary<BV,BV>(home,p,b0,b1) {}
82
83 template<class BV>
84 Actor*
86 return new (home) OrTrueSubsumed<BV>(home,*this);
87 }
88
89 template<class BV>
92 return home.ES_SUBSUMED(*this);
93 }
94
95
96 /*
97 * Binary Boolean disjunction propagator (true)
98 *
99 */
100
101 template<class BVA, class BVB>
104 : BoolBinary<BVA,BVB>(home,b0,b1) {}
105
106 template<class BVA, class BVB>
110
111 template<class BVA, class BVB>
114 BVA b0, BVB b1)
115 : BoolBinary<BVA,BVB>(home,p,b0,b1) {}
116
117 template<class BVA, class BVB>
118 Actor*
120 return new (home) BinOrTrue<BVA,BVB>(home,*this);
121 }
122
123 template<class BVA, class BVB>
124 inline ExecStatus
125 BinOrTrue<BVA,BVB>::post(Home home, BVA b0, BVB b1) {
126 switch (bool_test(b0,b1)) {
127 case BT_SAME:
128 GECODE_ME_CHECK(b0.one(home));
129 break;
130 case BT_COMP:
131 break;
132 case BT_NONE:
133 if (b0.zero()) {
134 GECODE_ME_CHECK(b1.one(home));
135 } else if (b1.zero()) {
136 GECODE_ME_CHECK(b0.one(home));
137 } else if (!b0.one() && !b1.one()) {
138 (void) new (home) BinOrTrue<BVA,BVB>(home,b0,b1);
139 }
140 break;
141 default: GECODE_NEVER;
142 }
143 return ES_OK;
144 }
145
146 template<class BVA, class BVB>
149#define GECODE_INT_STATUS(S0,S1) \
150 ((BVA::S0<<(1*BVA::BITS))|(BVB::S1<<(0*BVB::BITS)))
151 switch ((x0.status() << (1*BVA::BITS)) | (x1.status() << (0*BVB::BITS))) {
152 case GECODE_INT_STATUS(NONE,NONE):
154 case GECODE_INT_STATUS(NONE,ZERO):
155 GECODE_ME_CHECK(x0.one_none(home)); break;
156 case GECODE_INT_STATUS(NONE,ONE):
157 break;
158 case GECODE_INT_STATUS(ZERO,NONE):
159 GECODE_ME_CHECK(x1.one_none(home)); break;
160 case GECODE_INT_STATUS(ZERO,ZERO):
161 return ES_FAILED;
162 case GECODE_INT_STATUS(ZERO,ONE):
163 case GECODE_INT_STATUS(ONE,NONE):
164 case GECODE_INT_STATUS(ONE,ZERO):
165 case GECODE_INT_STATUS(ONE,ONE):
166 break;
167 default:
169 }
170 return home.ES_SUBSUMED(*this);
171#undef GECODE_INT_STATUS
172 }
173
174 /*
175 * Boolean disjunction propagator (true)
176 *
177 */
178
179 template<class BV>
181 TerOrTrue<BV>::TerOrTrue(Home home, BV b0, BV b1, BV b2)
182 : BoolBinary<BV,BV>(home,b0,b1), x2(b2) {}
183
184 template<class BV>
185 forceinline size_t
187 (void) BoolBinary<BV,BV>::dispose(home);
188 return sizeof(*this);
189 }
190
191 template<class BV>
194 : BoolBinary<BV,BV>(home,p) {
195 x2.update(home,p.x2);
196 }
197
198 template<class BV>
201 BV b0, BV b1, BV b2)
202 : BoolBinary<BV,BV>(home,p,b0,b1) {
203 x2.update(home,b2);
204 }
205
206 template<class BV>
207 Actor*
209 assert(x0.none() && x1.none());
210 if (x2.one())
211 return new (home) OrTrueSubsumed<BV>(home,*this,x0,x1);
212 else if (x2.zero())
213 return new (home) BinOrTrue<BV,BV>(home,*this,x0,x1);
214 else
215 return new (home) TerOrTrue<BV>(home,*this);
216 }
217
218 template<class BV>
220 TerOrTrue<BV>::post(Home home, BV b0, BV b1, BV b2) {
221 (void) new (home) TerOrTrue<BV>(home,b0,b1,b2);
222 return ES_OK;
223 }
224
225 template<class BV>
228#define GECODE_INT_STATUS(S0,S1,S2) \
229 ((BV::S0<<(2*BV::BITS))|(BV::S1<<(1*BV::BITS))|(BV::S2<<(0*BV::BITS)))
230 switch ((x0.status() << (2*BV::BITS)) | (x1.status() << (1*BV::BITS)) |
231 (x2.status() << (0*BV::BITS))) {
232 case GECODE_INT_STATUS(NONE,NONE,NONE):
233 case GECODE_INT_STATUS(NONE,NONE,ZERO):
234 case GECODE_INT_STATUS(NONE,NONE,ONE):
236 case GECODE_INT_STATUS(NONE,ZERO,NONE):
237 std::swap(x1,x2); x1.subscribe(home,*this,PC_BOOL_VAL);
238 return ES_FIX;
239 case GECODE_INT_STATUS(NONE,ZERO,ZERO):
240 GECODE_ME_CHECK(x0.one_none(home)); break;
241 case GECODE_INT_STATUS(NONE,ZERO,ONE):
242 case GECODE_INT_STATUS(NONE,ONE,NONE):
243 case GECODE_INT_STATUS(NONE,ONE,ZERO):
244 case GECODE_INT_STATUS(NONE,ONE,ONE):
245 break;
246 case GECODE_INT_STATUS(ZERO,NONE,NONE):
247 std::swap(x0,x2); x0.subscribe(home,*this,PC_BOOL_VAL);
248 return ES_FIX;
249 case GECODE_INT_STATUS(ZERO,NONE,ZERO):
250 GECODE_ME_CHECK(x1.one_none(home)); break;
251 case GECODE_INT_STATUS(ZERO,NONE,ONE):
252 break;
253 case GECODE_INT_STATUS(ZERO,ZERO,NONE):
254 GECODE_ME_CHECK(x2.one_none(home)); break;
255 case GECODE_INT_STATUS(ZERO,ZERO,ZERO):
256 return ES_FAILED;
257 case GECODE_INT_STATUS(ZERO,ZERO,ONE):
258 case GECODE_INT_STATUS(ZERO,ONE,NONE):
259 case GECODE_INT_STATUS(ZERO,ONE,ZERO):
260 case GECODE_INT_STATUS(ZERO,ONE,ONE):
261 case GECODE_INT_STATUS(ONE,NONE,NONE):
262 case GECODE_INT_STATUS(ONE,NONE,ZERO):
263 case GECODE_INT_STATUS(ONE,NONE,ONE):
264 case GECODE_INT_STATUS(ONE,ZERO,NONE):
265 case GECODE_INT_STATUS(ONE,ZERO,ZERO):
266 case GECODE_INT_STATUS(ONE,ZERO,ONE):
267 case GECODE_INT_STATUS(ONE,ONE,NONE):
268 case GECODE_INT_STATUS(ONE,ONE,ZERO):
269 case GECODE_INT_STATUS(ONE,ONE,ONE):
270 break;
271 default:
273 }
274 return home.ES_SUBSUMED(*this);
275#undef GECODE_INT_STATUS
276 }
277
278 /*
279 * Boolean disjunction propagator (true)
280 *
281 */
282
283 template<class BV>
285 QuadOrTrue<BV>::QuadOrTrue(Home home, BV b0, BV b1, BV b2, BV b3)
286 : BoolBinary<BV,BV>(home,b0,b1), x2(b2), x3(b3) {}
287
288 template<class BV>
289 forceinline size_t
291 (void) BoolBinary<BV,BV>::dispose(home);
292 return sizeof(*this);
293 }
294
295 template<class BV>
298 : BoolBinary<BV,BV>(home,p) {
299 x2.update(home,p.x2);
300 x3.update(home,p.x3);
301 }
302
303 template<class BV>
306 BV b0, BV b1, BV b2, BV b3)
307 : BoolBinary<BV,BV>(home,p,b0,b1) {
308 x2.update(home,b2);
309 x3.update(home,b3);
310 }
311
312 template<class BV>
313 Actor*
315 assert(x0.none() && x1.none());
316 if (x2.one() || x3.one())
317 return new (home) OrTrueSubsumed<BV>(home,*this,x0,x1);
318 else if (x2.zero() && x3.zero())
319 return new (home) BinOrTrue<BV,BV>(home,*this,x0,x1);
320 else if (x2.zero())
321 return new (home) TerOrTrue<BV>(home,*this,x0,x1,x3);
322 else if (x3.zero())
323 return new (home) TerOrTrue<BV>(home,*this,x0,x1,x2);
324 else
325 return new (home) QuadOrTrue<BV>(home,*this);
326 }
327
328 template<class BV>
330 QuadOrTrue<BV>::post(Home home, BV b0, BV b1, BV b2, BV b3) {
331 (void) new (home) QuadOrTrue<BV>(home,b0,b1,b2,b3);
332 return ES_OK;
333 }
334
335 template<class BV>
338#define GECODE_INT_STATUS(S0,S1,S2,S3) \
339 ((BV::S0 << (3*BV::BITS)) | (BV::S1 << (2*BV::BITS)) | \
340 (BV::S2 << (1*BV::BITS)) | (BV::S3 << (0*BV::BITS)))
341 switch ((x0.status() << (3*BV::BITS)) | (x1.status() << (2*BV::BITS)) |
342 (x2.status() << (1*BV::BITS)) | (x3.status() << (0*BV::BITS))) {
343 case GECODE_INT_STATUS(NONE,NONE,NONE,NONE):
344 case GECODE_INT_STATUS(NONE,NONE,NONE,ZERO):
345 case GECODE_INT_STATUS(NONE,NONE,NONE,ONE):
346 case GECODE_INT_STATUS(NONE,NONE,ZERO,NONE):
347 case GECODE_INT_STATUS(NONE,NONE,ZERO,ZERO):
348 case GECODE_INT_STATUS(NONE,NONE,ZERO,ONE):
349 case GECODE_INT_STATUS(NONE,NONE,ONE,NONE):
350 case GECODE_INT_STATUS(NONE,NONE,ONE,ZERO):
351 case GECODE_INT_STATUS(NONE,NONE,ONE,ONE):
353 case GECODE_INT_STATUS(NONE,ZERO,NONE,NONE):
354 case GECODE_INT_STATUS(NONE,ZERO,NONE,ZERO):
355 std::swap(x1,x2); x1.subscribe(home,*this,PC_BOOL_VAL,false);
356 return ES_FIX;
357 case GECODE_INT_STATUS(NONE,ZERO,NONE,ONE):
358 break;
359 case GECODE_INT_STATUS(NONE,ZERO,ZERO,NONE):
360 std::swap(x1,x3); x1.subscribe(home,*this,PC_BOOL_VAL,false);
361 return ES_FIX;
362 case GECODE_INT_STATUS(NONE,ZERO,ZERO,ZERO):
363 GECODE_ME_CHECK(x0.one_none(home)); break;
364 case GECODE_INT_STATUS(NONE,ZERO,ZERO,ONE):
365 case GECODE_INT_STATUS(NONE,ZERO,ONE,NONE):
366 case GECODE_INT_STATUS(NONE,ZERO,ONE,ZERO):
367 case GECODE_INT_STATUS(NONE,ZERO,ONE,ONE):
368 case GECODE_INT_STATUS(NONE,ONE,NONE,NONE):
369 case GECODE_INT_STATUS(NONE,ONE,NONE,ZERO):
370 case GECODE_INT_STATUS(NONE,ONE,NONE,ONE):
371 case GECODE_INT_STATUS(NONE,ONE,ZERO,NONE):
372 case GECODE_INT_STATUS(NONE,ONE,ZERO,ZERO):
373 case GECODE_INT_STATUS(NONE,ONE,ZERO,ONE):
374 case GECODE_INT_STATUS(NONE,ONE,ONE,NONE):
375 case GECODE_INT_STATUS(NONE,ONE,ONE,ZERO):
376 case GECODE_INT_STATUS(NONE,ONE,ONE,ONE):
377 break;
378 case GECODE_INT_STATUS(ZERO,NONE,NONE,NONE):
379 case GECODE_INT_STATUS(ZERO,NONE,NONE,ZERO):
380 std::swap(x0,x2); x0.subscribe(home,*this,PC_BOOL_VAL,false);
381 return ES_FIX;
382 case GECODE_INT_STATUS(ZERO,NONE,NONE,ONE):
383 break;
384 case GECODE_INT_STATUS(ZERO,NONE,ZERO,NONE):
385 std::swap(x0,x3); x0.subscribe(home,*this,PC_BOOL_VAL,false);
386 return ES_FIX;
387 case GECODE_INT_STATUS(ZERO,NONE,ZERO,ZERO):
388 GECODE_ME_CHECK(x1.one_none(home)); break;
389 case GECODE_INT_STATUS(ZERO,NONE,ZERO,ONE):
390 case GECODE_INT_STATUS(ZERO,NONE,ONE,NONE):
391 case GECODE_INT_STATUS(ZERO,NONE,ONE,ZERO):
392 case GECODE_INT_STATUS(ZERO,NONE,ONE,ONE):
393 break;
394 case GECODE_INT_STATUS(ZERO,ZERO,NONE,NONE):
395 std::swap(x0,x2); x0.subscribe(home,*this,PC_BOOL_VAL,false);
396 std::swap(x1,x3); x1.subscribe(home,*this,PC_BOOL_VAL,false);
397 return ES_FIX;
398 case GECODE_INT_STATUS(ZERO,ZERO,NONE,ZERO):
399 GECODE_ME_CHECK(x2.one_none(home)); break;
400 case GECODE_INT_STATUS(ZERO,ZERO,NONE,ONE):
401 break;
402 case GECODE_INT_STATUS(ZERO,ZERO,ZERO,NONE):
403 GECODE_ME_CHECK(x3.one_none(home)); break;
404 case GECODE_INT_STATUS(ZERO,ZERO,ZERO,ZERO):
405 return ES_FAILED;
406 case GECODE_INT_STATUS(ZERO,ZERO,ZERO,ONE):
407 case GECODE_INT_STATUS(ZERO,ZERO,ONE,NONE):
408 case GECODE_INT_STATUS(ZERO,ZERO,ONE,ZERO):
409 case GECODE_INT_STATUS(ZERO,ZERO,ONE,ONE):
410 case GECODE_INT_STATUS(ZERO,ONE,NONE,NONE):
411 case GECODE_INT_STATUS(ZERO,ONE,NONE,ZERO):
412 case GECODE_INT_STATUS(ZERO,ONE,NONE,ONE):
413 case GECODE_INT_STATUS(ZERO,ONE,ZERO,NONE):
414 case GECODE_INT_STATUS(ZERO,ONE,ZERO,ZERO):
415 case GECODE_INT_STATUS(ZERO,ONE,ZERO,ONE):
416 case GECODE_INT_STATUS(ZERO,ONE,ONE,NONE):
417 case GECODE_INT_STATUS(ZERO,ONE,ONE,ZERO):
418 case GECODE_INT_STATUS(ZERO,ONE,ONE,ONE):
419 case GECODE_INT_STATUS(ONE,NONE,NONE,NONE):
420 case GECODE_INT_STATUS(ONE,NONE,NONE,ZERO):
421 case GECODE_INT_STATUS(ONE,NONE,NONE,ONE):
422 case GECODE_INT_STATUS(ONE,NONE,ZERO,NONE):
423 case GECODE_INT_STATUS(ONE,NONE,ZERO,ZERO):
424 case GECODE_INT_STATUS(ONE,NONE,ZERO,ONE):
425 case GECODE_INT_STATUS(ONE,NONE,ONE,NONE):
426 case GECODE_INT_STATUS(ONE,NONE,ONE,ZERO):
427 case GECODE_INT_STATUS(ONE,NONE,ONE,ONE):
428 case GECODE_INT_STATUS(ONE,ZERO,NONE,NONE):
429 case GECODE_INT_STATUS(ONE,ZERO,NONE,ZERO):
430 case GECODE_INT_STATUS(ONE,ZERO,NONE,ONE):
431 case GECODE_INT_STATUS(ONE,ZERO,ZERO,NONE):
432 case GECODE_INT_STATUS(ONE,ZERO,ZERO,ZERO):
433 case GECODE_INT_STATUS(ONE,ZERO,ZERO,ONE):
434 case GECODE_INT_STATUS(ONE,ZERO,ONE,NONE):
435 case GECODE_INT_STATUS(ONE,ZERO,ONE,ZERO):
436 case GECODE_INT_STATUS(ONE,ZERO,ONE,ONE):
437 case GECODE_INT_STATUS(ONE,ONE,NONE,NONE):
438 case GECODE_INT_STATUS(ONE,ONE,NONE,ZERO):
439 case GECODE_INT_STATUS(ONE,ONE,NONE,ONE):
440 case GECODE_INT_STATUS(ONE,ONE,ZERO,NONE):
441 case GECODE_INT_STATUS(ONE,ONE,ZERO,ZERO):
442 case GECODE_INT_STATUS(ONE,ONE,ZERO,ONE):
443 case GECODE_INT_STATUS(ONE,ONE,ONE,NONE):
444 case GECODE_INT_STATUS(ONE,ONE,ONE,ZERO):
445 case GECODE_INT_STATUS(ONE,ONE,ONE,ONE):
446 break;
447 default:
449 }
450 return home.ES_SUBSUMED(*this);
451#undef GECODE_INT_STATUS
452 }
453
454 /*
455 * Boolean disjunction propagator
456 *
457 */
458
459 template<class BVA, class BVB, class BVC>
461 Or<BVA,BVB,BVC>::Or(Home home, BVA b0, BVB b1, BVC b2)
462 : BoolTernary<BVA,BVB,BVC>(home,b0,b1,b2) {}
463
464 template<class BVA, class BVB, class BVC>
467 : BoolTernary<BVA,BVB,BVC>(home,p) {}
468
469 template<class BVA, class BVB, class BVC>
472 BVA b0, BVB b1, BVC b2)
473 : BoolTernary<BVA,BVB,BVC>(home,p,b0,b1,b2) {}
474
475 template<class BVA, class BVB, class BVC>
476 Actor*
478 if (x2.one()) {
479 assert(x0.none() && x1.none());
480 return new (home) BinOrTrue<BVA,BVB>(home,*this,x0,x1);
481 } else if (x0.zero()) {
482 assert(x1.none() && x2.none());
483 return new (home) Eq<BVB,BVC>(home,*this,x1,x2);
484 } else if (x1.zero()) {
485 assert(x0.none() && x2.none());
486 return new (home) Eq<BVA,BVC>(home,*this,x0,x2);
487 } else {
488 return new (home) Or<BVA,BVB,BVC>(home,*this);
489 }
490 }
491
492 template<class BVA, class BVB, class BVC>
493 inline ExecStatus
494 Or<BVA,BVB,BVC>::post(Home home, BVA b0, BVB b1, BVC b2) {
495 if (b2.zero()) {
496 GECODE_ME_CHECK(b0.zero(home));
497 GECODE_ME_CHECK(b1.zero(home));
498 } else if (b2.one()) {
499 return BinOrTrue<BVA,BVB>::post(home,b0,b1);
500 } else {
501 switch (bool_test(b0,b1)) {
502 case BT_SAME:
503 return Eq<BVA,BVC>::post(home,b0,b2);
504 case BT_COMP:
505 GECODE_ME_CHECK(b2.one(home));
506 break;
507 case BT_NONE:
508 if (b0.one() || b1.one()) {
509 GECODE_ME_CHECK(b2.one(home));
510 } else if (b0.zero()) {
511 return Eq<BVB,BVC>::post(home,b1,b2);
512 } else if (b1.zero()) {
513 return Eq<BVA,BVC>::post(home,b0,b2);
514 } else {
515 (void) new (home) Or<BVA,BVB,BVC>(home,b0,b1,b2);
516 }
517 break;
518 default: GECODE_NEVER;
519 }
520 }
521 return ES_OK;
522 }
523
524 template<class BVA, class BVB, class BVC>
527#define GECODE_INT_STATUS(S0,S1,S2) \
528 ((BVA::S0<<(2*BVA::BITS))|(BVB::S1<<(1*BVB::BITS))|(BVC::S2<<(0*BVC::BITS)))
529 switch ((x0.status() << (2*BVA::BITS)) | (x1.status() << (1*BVB::BITS)) |
530 (x2.status() << (0*BVC::BITS))) {
531 case GECODE_INT_STATUS(NONE,NONE,NONE):
533 case GECODE_INT_STATUS(NONE,NONE,ZERO):
534 GECODE_ME_CHECK(x0.zero_none(home));
535 GECODE_ME_CHECK(x1.zero_none(home));
536 break;
537 case GECODE_INT_STATUS(NONE,NONE,ONE):
538 return ES_FIX;
539 case GECODE_INT_STATUS(NONE,ZERO,NONE):
540 switch (bool_test(x0,x2)) {
541 case BT_SAME: return home.ES_SUBSUMED(*this);
542 case BT_COMP: return ES_FAILED;
543 case BT_NONE: return ES_FIX;
544 default: GECODE_NEVER;
545 }
547 case GECODE_INT_STATUS(NONE,ZERO,ZERO):
548 GECODE_ME_CHECK(x0.zero_none(home)); break;
549 case GECODE_INT_STATUS(NONE,ZERO,ONE):
550 GECODE_ME_CHECK(x0.one_none(home)); break;
551 case GECODE_INT_STATUS(NONE,ONE,NONE):
552 GECODE_ME_CHECK(x2.one_none(home)); break;
553 case GECODE_INT_STATUS(NONE,ONE,ZERO):
554 return ES_FAILED;
555 case GECODE_INT_STATUS(NONE,ONE,ONE):
556 break;
557 case GECODE_INT_STATUS(ZERO,NONE,NONE):
558 switch (bool_test(x1,x2)) {
559 case BT_SAME: return home.ES_SUBSUMED(*this);
560 case BT_COMP: return ES_FAILED;
561 case BT_NONE: return ES_FIX;
562 default: GECODE_NEVER;
563 }
565 case GECODE_INT_STATUS(ZERO,NONE,ZERO):
566 GECODE_ME_CHECK(x1.zero_none(home)); break;
567 case GECODE_INT_STATUS(ZERO,NONE,ONE):
568 GECODE_ME_CHECK(x1.one_none(home)); break;
569 case GECODE_INT_STATUS(ZERO,ZERO,NONE):
570 GECODE_ME_CHECK(x2.zero_none(home)); break;
571 case GECODE_INT_STATUS(ZERO,ZERO,ZERO):
572 break;
573 case GECODE_INT_STATUS(ZERO,ZERO,ONE):
574 return ES_FAILED;
575 case GECODE_INT_STATUS(ZERO,ONE,NONE):
576 GECODE_ME_CHECK(x2.one_none(home)); break;
577 case GECODE_INT_STATUS(ZERO,ONE,ZERO):
578 return ES_FAILED;
579 case GECODE_INT_STATUS(ZERO,ONE,ONE):
580 break;
581 case GECODE_INT_STATUS(ONE,NONE,NONE):
582 GECODE_ME_CHECK(x2.one_none(home)); break;
583 case GECODE_INT_STATUS(ONE,NONE,ZERO):
584 return ES_FAILED;
585 case GECODE_INT_STATUS(ONE,NONE,ONE):
586 break;
587 case GECODE_INT_STATUS(ONE,ZERO,NONE):
588 GECODE_ME_CHECK(x2.one_none(home)); break;
589 case GECODE_INT_STATUS(ONE,ZERO,ZERO):
590 return ES_FAILED;
591 case GECODE_INT_STATUS(ONE,ZERO,ONE):
592 break;
593 case GECODE_INT_STATUS(ONE,ONE,NONE):
594 GECODE_ME_CHECK(x2.one_none(home)); break;
595 case GECODE_INT_STATUS(ONE,ONE,ZERO):
596 return ES_FAILED;
597 case GECODE_INT_STATUS(ONE,ONE,ONE):
598 break;
599 default:
601 }
602 return home.ES_SUBSUMED(*this);
603#undef GECODE_INT_STATUS
604 }
605
606 /*
607 * N-ary Boolean disjunction propagator (true)
608 *
609 */
610
611 template<class BV>
614 : BinaryPropagator<BV,PC_BOOL_VAL>(home,b[0],b[1]), x(b) {
615 assert(x.size() > 2);
616 x.drop_fst(2);
617 }
618
619 template<class BV>
623 }
624
625 template<class BV>
628 : BinaryPropagator<BV,PC_BOOL_VAL>(home,p) {
629 x.update(home,p.x);
630 }
631
632 template<class BV>
633 Actor*
635 int n = x.size();
636 if (n > 0) {
637 // Eliminate all zeros and find a one
638 for (int i=n; i--; )
639 if (x[i].one()) {
640 // Only keep the one
641 x[0]=x[i]; x.size(1);
642 return new (home) OrTrueSubsumed<BV>(home,*this,x0,x1);
643 } else if (x[i].zero()) {
644 // Eliminate the zero
645 x[i]=x[--n];
646 }
647 x.size(n);
648 }
649 switch (n) {
650 case 0:
651 return new (home) BinOrTrue<BV,BV>(home,*this,x0,x1);
652 case 1:
653 return new (home) TerOrTrue<BV>(home,*this,x0,x1,x[0]);
654 case 2:
655 return new (home) QuadOrTrue<BV>(home,*this,x0,x1,x[0],x[1]);
656 default:
657 return new (home) NaryOrTrue<BV>(home,*this);
658 }
659 }
660
661 template<class BV>
662 inline ExecStatus
664 for (int i=b.size(); i--; )
665 if (b[i].one())
666 return ES_OK;
667 else if (b[i].zero())
668 b.move_lst(i);
669 if (b.size() == 0)
670 return ES_FAILED;
671 if (b.size() == 1) {
672 GECODE_ME_CHECK(b[0].one(home));
673 } else if (b.size() == 2) {
674 return BinOrTrue<BV,BV>::post(home,b[0],b[1]);
675 } else if (b.size() == 3) {
676 return TerOrTrue<BV>::post(home,b[0],b[1],b[2]);
677 } else if (b.size() == 4) {
678 return QuadOrTrue<BV>::post(home,b[0],b[1],b[2],b[3]);
679 } else {
680 (void) new (home) NaryOrTrue(home,b);
681 }
682 return ES_OK;
683 }
684
685 template<class BV>
686 forceinline size_t
689 return sizeof(*this);
690 }
691
692 template<class BV>
695 if (x0.zero()) {
696 int n = x.size();
697 for (int i=n; i--; )
698 if (x[i].one()) {
699 return home.ES_SUBSUMED(*this);
700 } else if (x[i].zero()) {
701 x[i] = x[--n];
702 } else {
703 // Move to x0 and subscribe
704 x0=x[i]; x[i]=x[--n];
705 x.size(n);
706 x0.subscribe(home,*this,PC_BOOL_VAL,false);
707 return ES_FIX;
708 }
709 // All views have been assigned!
710 GECODE_ME_CHECK(x1.one(home));
711 return home.ES_SUBSUMED(*this);
712 }
713 return ES_FIX;
714 }
715
716 template<class BV>
719 if (x0.one())
720 return home.ES_SUBSUMED(*this);
721 if (x1.one())
722 return home.ES_SUBSUMED(*this);
725 return ES_FIX;
726 }
727
728
729 /*
730 * N-ary Boolean disjunction propagator
731 *
732 */
733
734 template<class VX, class VY>
738 n_zero(0), c(home) {
739 x.subscribe(home,*new (home) Advisor(home,*this,c));
740 }
741
742 template<class VX, class VY>
746 n_zero(p.n_zero) {
747 c.update(home,p.c);
748 }
749
750 template<class VX, class VY>
751 Actor*
753 assert(n_zero < x.size());
754 if (n_zero > 0) {
755 int n=x.size();
756 // Eliminate all zeros
757 for (int i=n; i--; )
758 if (x[i].zero())
759 x[i]=x[--n];
760 x.size(n);
761 n_zero = 0;
762 }
763 assert(n_zero < x.size());
764 return new (home) NaryOr<VX,VY>(home,*this);
765 }
766
767 template<class VX, class VY>
768 inline ExecStatus
770 assert(!shared(x));
771 if (y.one())
772 return NaryOrTrue<VX>::post(home,x);
773 if (y.zero()) {
774 for (int i=0; i<x.size(); i++)
775 GECODE_ME_CHECK(x[i].zero(home));
776 return ES_OK;
777 }
778 for (int i=x.size(); i--; )
779 if (x[i].one()) {
780 GECODE_ME_CHECK(y.one_none(home));
781 return ES_OK;
782 } else if (x[i].zero()) {
783 x.move_lst(i);
784 }
785 if (x.size() == 0) {
786 GECODE_ME_CHECK(y.zero_none(home));
787 } else if (x.size() == 1) {
788 return Eq<VX,VY>::post(home,x[0],y);
789 } else if (x.size() == 2) {
790 return Or<VX,VX,VY>::post(home,x[0],x[1],y);
791 } else {
792 (void) new (home) NaryOr(home,x,y);
793 }
794 return ES_OK;
795 }
796
797 template<class VX, class VY>
801 }
802
803 template<class VX, class VY>
806 // Decides whether the propagator must be run
807 if (VX::zero(d) && (++n_zero < x.size()))
808 return ES_FIX;
809 else
810 return ES_NOFIX;
811 }
812
813 template<class VX, class VY>
814 void
816 y.reschedule(home,*this,PC_BOOL_VAL);
817 if (n_zero == x.size())
818 VX::schedule(home,*this,ME_BOOL_VAL);
819 for (int i=0; i<x.size(); i++)
820 if (x[i].one()) {
821 VX::schedule(home,*this,ME_BOOL_VAL);
822 break;
823 }
824 }
825
826 template<class VX, class VY>
827 forceinline size_t
830 x.cancel(home,as.advisor());
831 c.dispose(home);
833 ::dispose(home);
834 return sizeof(*this);
835 }
836
837 template<class VX, class VY>
840 if (y.one())
841 GECODE_REWRITE(*this,NaryOrTrue<VX>::post(home(*this),x));
842 if (y.zero()) {
843 // Note that this might trigger the advisor of this propagator!
844 for (int i=0; i<x.size(); i++)
845 GECODE_ME_CHECK(x[i].zero(home));
846 } else if (n_zero == x.size()) {
847 // All views are zero
848 GECODE_ME_CHECK(y.zero_none(home));
849 } else {
850 // There is at least one view which is one
851 GECODE_ME_CHECK(y.one_none(home));
852 }
853 return home.ES_SUBSUMED(*this);
854 }
855
856}}}
857
858// STATISTICS: int-prop
859
Base-class for both propagators and branchers.
Definition core.hpp:628
Class to iterate over advisors of a council.
Definition core.hpp:1268
A & advisor(void) const
Return advisor.
Definition core.hpp:4017
BinaryPropagator(Space &home, BinaryPropagator &p)
virtual size_t dispose(Space &home)
Delete propagator and return its size.
Definition pattern.hpp:396
Generic domain change information to be supplied to advisors.
Definition core.hpp:204
FloatNum size(void) const
Return size of float value (distance between maximum and minimum)
Definition val.hpp:78
Home class for posting propagators
Definition core.hpp:856
Binary Boolean disjunction propagator (true)
Definition bool.hh:237
BinOrTrue(Home home, BVA b0, BVB b1)
Constructor for posting.
Definition or.hpp:103
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
Definition or.hpp:148
static ExecStatus post(Home home, BVA b0, BVB b1)
Post propagator .
Definition or.hpp:125
virtual Actor * copy(Space &home)
Copy propagator during cloning.
Definition or.hpp:119
virtual size_t dispose(Space &home)
Delete propagator and return its size.
Definition base.hpp:80
BoolBinary(Home home, BV b0, BV b1)
Definition base.hpp:42
BoolTernary(Home home, BVA b0, BVB b1, BVC b2)
Definition base.hpp:94
BVB x1
Boolean view.
Definition bool.hh:80
BVA x0
Boolean view.
Definition bool.hh:79
BVC x2
Boolean view Constructor for posting.
Definition bool.hh:81
Boolean equality propagator.
Definition bool.hh:105
static ExecStatus post(Home home, BVA x0, BVB x1)
Post propagator .
Definition eq.hpp:60
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
Definition or.hpp:718
ExecStatus resubscribe(Space &home, BV &x0, BV x1)
Update subscription.
Definition or.hpp:694
static ExecStatus post(Home home, ViewArray< BV > &b)
Post propagator .
Definition or.hpp:663
ViewArray< BV > x
Views not yet subscribed to.
Definition bool.hh:398
virtual Actor * copy(Space &home)
Copy propagator during cloning.
Definition or.hpp:634
virtual PropCost cost(const Space &home, const ModEventDelta &med) const
Cost function (defined as low unary)
Definition or.hpp:621
NaryOrTrue(Home home, ViewArray< BV > &x)
Constructor for posting.
Definition or.hpp:613
virtual size_t dispose(Space &home)
Delete propagator and return its size.
Definition or.hpp:687
virtual void reschedule(Space &home)
Schedule function.
Definition or.hpp:815
virtual ExecStatus advise(Space &home, Advisor &a, const Delta &d)
Give advice to propagator.
Definition or.hpp:805
NaryOr(Home home, ViewArray< VX > &x, VY y)
Constructor for posting.
Definition or.hpp:736
virtual Actor * copy(Space &home)
Copy propagator during cloning.
Definition or.hpp:752
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
Definition or.hpp:839
virtual PropCost cost(const Space &home, const ModEventDelta &med) const
Cost function (defined as low unary)
Definition or.hpp:799
int n_zero
The number of views assigned to zero in x.
Definition bool.hh:361
Council< Advisor > c
The advisor council.
Definition bool.hh:363
static ExecStatus post(Home home, ViewArray< VX > &x, VY y)
Post propagator .
Definition or.hpp:769
virtual size_t dispose(Space &home)
Delete propagator and return its size.
Definition or.hpp:828
Binary Boolean disjunction propagator (subsumed)
Definition or.hpp:38
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
Definition or.hpp:91
static ExecStatus post(Home home, BV b0, BV b1)
Post propagator.
Definition or.hpp:66
virtual Actor * copy(Space &home)
Copy propagator during cloning.
Definition or.hpp:85
OrTrueSubsumed(Space &home, OrTrueSubsumed &p)
Constructor for cloning p.
Definition or.hpp:74
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
Definition or.hpp:526
virtual Actor * copy(Space &home)
Copy propagator during cloning.
Definition or.hpp:477
static ExecStatus post(Home home, BVA b0, BVB b1, BVC b2)
Post propagator .
Definition or.hpp:494
Or(Home home, BVA b0, BVB b1, BVC b2)
Constructor for posting.
Definition or.hpp:461
Quarternary Boolean disjunction propagator (true)
Definition bool.hh:295
QuadOrTrue(Home home, BV b0, BV b1, BV b2, BV b3)
Constructor for posting.
Definition or.hpp:285
BV x2
Boolean view without subscription.
Definition bool.hh:300
BV x3
Boolean view without subscription.
Definition bool.hh:302
static ExecStatus post(Home home, BV b0, BV b1, BV b2, BV b3)
Post propagator .
Definition or.hpp:330
virtual size_t dispose(Space &home)
Delete propagator and return its size.
Definition or.hpp:290
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
Definition or.hpp:337
virtual Actor * copy(Space &home)
Copy propagator during cloning.
Definition or.hpp:314
Ternary Boolean disjunction propagator (true)
Definition bool.hh:264
TerOrTrue(Home home, BV b0, BV b1, BV b2)
Constructor for posting.
Definition or.hpp:181
virtual Actor * copy(Space &home)
Copy propagator during cloning.
Definition or.hpp:208
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:186
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
Definition or.hpp:227
static ExecStatus post(Home home, BV b0, BV b1, BV b2)
Post propagator .
Definition or.hpp:220
MixNaryOnePropagator(Space &home, MixNaryOnePropagator &p)
Definition pattern.hpp:733
Propagation cost.
Definition core.hpp:486
static PropCost unary(PropCost::Mod m)
Single variable for modifier pcm.
Definition core.hpp:4820
static PropCost binary(PropCost::Mod m)
Two variables for modifier pcm.
Definition core.hpp:4816
friend class Space
Definition core.hpp:1068
friend class Advisor
Definition core.hpp:1070
ModEventDelta med
A set of modification events (used during propagation)
Definition core.hpp:1077
Propagator(Home home)
Constructor for posting.
Definition core.hpp:3505
View arrays.
Definition array.hpp:253
ExecStatus ES_SUBSUMED(Propagator &p)
Propagator p is subsumed
Definition core.hpp:3570
int ModEventDelta
Modification event deltas.
Definition core.hpp:89
#define GECODE_ME_CHECK(me)
Check whether modification event me is failed, and forward failure.
Definition macros.hpp:52
#define GECODE_REWRITE(prop, post)
Rewrite propagator by executing post function.
Definition macros.hpp:116
#define GECODE_ES_CHECK(es)
Check whether execution status es is failed or subsumed, and forward failure or subsumption.
Definition macros.hpp:91
#define GECODE_INT_STATUS(S0, S1)
Boolean propagators.
ExecStatus resubscribe(Space &home, Propagator &p, VX &x0, ViewArray< VX > &x, VY &x1, ViewArray< VY > &y)
Definition clause.hpp:138
Finite domain integers.
const Gecode::PropCond PC_BOOL_NONE
Propagation condition to be ignored (convenience)
Definition var-type.hpp:118
const Gecode::ModEvent ME_BOOL_VAL
Domain operation has resulted in a value (assigned variable)
Definition var-type.hpp:116
const Gecode::PropCond PC_BOOL_VAL
Propagate when a view becomes assigned (single value)
Definition var-type.hpp:126
BoolTest bool_test(const BoolView &b0, const BoolView &b1)
Definition bool-test.hpp:41
@ BT_NONE
No sharing.
Definition view.hpp:1785
@ BT_COMP
Same variable but complement.
Definition view.hpp:1787
@ BT_SAME
Same variable.
Definition view.hpp:1786
Gecode toplevel namespace
ExecStatus
Definition core.hpp:472
@ ES_OK
Execution is okay.
Definition core.hpp:476
@ ES_FIX
Propagation has computed fixpoint.
Definition core.hpp:477
@ ES_FAILED
Execution has resulted in failure.
Definition core.hpp:474
@ ES_NOFIX
Propagation has not computed fixpoint.
Definition core.hpp:475
bool shared(ViewArray< ViewX > x, ViewArray< ViewY > y)
Definition array.hpp:1472
#define forceinline
Definition config.hpp:194
#define GECODE_NEVER
Assert that this command is never executed.
Definition macros.hpp:56