Generated on Sat Jan 12 2019 20:58:51 for Gecode by doxygen 1.8.13
bool.hh
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  * Guido Tack <tack@gecode.org>
6  *
7  * Copyright:
8  * Christian Schulte, 2002
9  * Guido Tack, 2004
10  *
11  * This file is part of Gecode, the generic constraint
12  * development environment:
13  * http://www.gecode.org
14  *
15  * Permission is hereby granted, free of charge, to any person obtaining
16  * a copy of this software and associated documentation files (the
17  * "Software"), to deal in the Software without restriction, including
18  * without limitation the rights to use, copy, modify, merge, publish,
19  * distribute, sublicense, and/or sell copies of the Software, and to
20  * permit persons to whom the Software is furnished to do so, subject to
21  * the following conditions:
22  *
23  * The above copyright notice and this permission notice shall be
24  * included in all copies or substantial portions of the Software.
25  *
26  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
27  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
28  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
29  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
30  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
31  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
32  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
33  *
34  */
35 
36 #ifndef __GECODE_INT_BOOL_HH__
37 #define __GECODE_INT_BOOL_HH__
38 
39 #include <gecode/int.hh>
40 
46 namespace Gecode { namespace Int { namespace Bool {
47 
48  /*
49  * Base Classes
50  *
51  */
52 
54  template<class BVA, class BVB>
55  class BoolBinary : public Propagator {
56  protected:
57  BVA x0;
58  BVB x1;
59  BoolBinary(Home home, BVA b0, BVB b1);
62  BoolBinary(Space& home, BoolBinary& p);
64  BoolBinary(Space& home, Propagator& p,
65  BVA b0, BVB b1);
66  public:
68  virtual PropCost cost(const Space& home, const ModEventDelta& med) const;
70  virtual void reschedule(Space& home);
72  virtual size_t dispose(Space& home);
73  };
74 
76  template<class BVA, class BVB, class BVC>
77  class BoolTernary : public Propagator {
78  protected:
79  BVA x0;
80  BVB x1;
81  BVC x2;
82  BoolTernary(Home home, BVA b0, BVB b1, BVC b2);
85  BoolTernary(Space& home, BoolTernary& p);
86  public:
88  BoolTernary(Space& home, Propagator& p,
89  BVA b0, BVB b1, BVC b2);
91  virtual PropCost cost(const Space& home, const ModEventDelta& med) const;
93  virtual void reschedule(Space& home);
95  virtual size_t dispose(Space& home);
96  };
97 
104  template<class BVA, class BVB>
105  class Eq : public BoolBinary<BVA,BVB> {
106  protected:
110  Eq(Home home, BVA b0, BVB b1);
112  Eq(Space& home, Eq& p);
113  public:
115  Eq(Space& home, Propagator& p,
116  BVA b0, BVB b1);
118  virtual Actor* copy(Space& home);
120  virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
122  static ExecStatus post(Home home, BVA x0, BVB x1);
123  };
124 
125 
132  template<class BV>
133  class NaryEq : public NaryPropagator<BV,PC_BOOL_VAL> {
134  protected:
137  NaryEq(Home home, ViewArray<BV>& x);
139  NaryEq(Space& home, NaryEq& p);
140  public:
142  virtual Actor* copy(Space& home);
144  virtual PropCost cost(const Space& home, const ModEventDelta& med) const;
146  virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
148  static ExecStatus post(Home home, ViewArray<BV>& x);
149  };
150 
151 
158  template<class BV>
159  class Lq : public BoolBinary<BV,BV> {
160  protected:
161  using BoolBinary<BV,BV>::x0;
162  using BoolBinary<BV,BV>::x1;
164  Lq(Home home, BV b0, BV b1);
166  Lq(Space& home, Lq& p);
167  public:
169  virtual Actor* copy(Space& home);
171  virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
173  static ExecStatus post(Home home, BV b0, BV b1);
174  };
175 
182  template<class VX>
183  class NaryLq : public NaryPropagator<VX,PC_BOOL_NONE> {
184  protected:
187  bool run;
189  int n_zero;
191  int n_one;
195  NaryLq(Home home, ViewArray<VX>& x);
197  NaryLq(Space& home, NaryLq<VX>& p);
198  public:
200  virtual Actor* copy(Space& home);
202  virtual ExecStatus advise(Space& home, Advisor& a, const Delta& d);
204  virtual PropCost cost(const Space& home, const ModEventDelta& med) const;
206  virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
208  static ExecStatus post(Home home, ViewArray<VX>& x);
210  virtual size_t dispose(Space& home);
211  };
212 
213 
214 
215 
222  template<class BV>
223  class Le {
224  public:
226  static ExecStatus post(Home home, BV b0, BV b1);
227  };
228 
229 
236  template<class BVA, class BVB>
237  class BinOrTrue : public BoolBinary<BVA,BVB> {
238  protected:
242  BinOrTrue(Home home, BVA b0, BVB b1);
244  BinOrTrue(Space& home, BinOrTrue& p);
245  public:
247  BinOrTrue(Space& home, Propagator& p,
248  BVA b0, BVB b1);
250  virtual Actor* copy(Space& home);
252  virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
254  static ExecStatus post(Home home, BVA b0, BVB b1);
255  };
256 
263  template<class BV>
264  class TerOrTrue : public BoolBinary<BV,BV> {
265  protected:
266  using BoolBinary<BV,BV>::x0;
267  using BoolBinary<BV,BV>::x1;
269  BV x2;
271  TerOrTrue(Home home, BV b0, BV b1, BV b2);
273  TerOrTrue(Space& home, TerOrTrue& p);
274  public:
276  TerOrTrue(Space& home, Propagator& p,
277  BV b0, BV b1, BV b2);
279  virtual Actor* copy(Space& home);
281  virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
283  static ExecStatus post(Home home, BV b0, BV b1, BV b2);
285  virtual size_t dispose(Space& home);
286  };
287 
294  template<class BV>
295  class QuadOrTrue : public BoolBinary<BV,BV> {
296  protected:
297  using BoolBinary<BV,BV>::x0;
298  using BoolBinary<BV,BV>::x1;
300  BV x2;
302  BV x3;
304  QuadOrTrue(Home home, BV b0, BV b1, BV b2, BV b3);
306  QuadOrTrue(Space& home, QuadOrTrue& p);
307  public:
309  QuadOrTrue(Space& home, Propagator& p,
310  BV b0, BV b1, BV b2, BV b3);
312  virtual Actor* copy(Space& home);
314  virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
316  static ExecStatus post(Home home, BV b0, BV b1, BV b2, BV b3);
318  virtual size_t dispose(Space& home);
319  };
320 
327  template<class BVA, class BVB, class BVC>
328  class Or : public BoolTernary<BVA,BVB,BVC> {
329  protected:
334  Or(Home home, BVA b0, BVB b1, BVC b2);
336  Or(Space& home, Or& p);
337  public:
339  Or(Space& home, Propagator& p, BVA b0, BVB b1, BVC b2);
341  virtual Actor* copy(Space& home);
343  virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
345  static ExecStatus post(Home home, BVA b0, BVB b1, BVC b2);
346  };
347 
354  template<class VX,class VY>
355  class NaryOr
356  : public MixNaryOnePropagator<VX,PC_BOOL_NONE,VY,PC_BOOL_VAL> {
357  protected:
361  int n_zero;
365  NaryOr(Home home, ViewArray<VX>& x, VY y);
367  NaryOr(Space& home, NaryOr<VX,VY>& p);
368  public:
370  virtual Actor* copy(Space& home);
372  virtual ExecStatus advise(Space& home, Advisor& a, const Delta& d);
374  virtual PropCost cost(const Space& home, const ModEventDelta& med) const;
376  virtual void reschedule(Space& home);
378  virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
380  static ExecStatus post(Home home, ViewArray<VX>& x, VY y);
382  virtual size_t dispose(Space& home);
383  };
384 
385 
392  template<class BV>
393  class NaryOrTrue : public BinaryPropagator<BV,PC_BOOL_VAL> {
394  protected:
400  ExecStatus resubscribe(Space& home, BV& x0, BV x1);
402  NaryOrTrue(Home home, ViewArray<BV>& x);
404  NaryOrTrue(Space& home, NaryOrTrue<BV>& p);
405  public:
407  virtual Actor* copy(Space& home);
409  virtual PropCost cost(const Space& home, const ModEventDelta& med) const;
411  virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
413  static ExecStatus post(Home home, ViewArray<BV>& b);
415  virtual size_t dispose(Space& home);
416  };
417 
418 
425  template<class BVA, class BVB, class BVC>
426  class Eqv : public BoolTernary<BVA,BVB,BVC> {
427  protected:
432  Eqv(Space& home, Eqv& p);
434  Eqv(Home home, BVA b0 ,BVB b1, BVC b2);
435  public:
437  virtual Actor* copy(Space& home);
439  virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
441  static ExecStatus post(Home home, BVA b0, BVB b1, BVC b2);
442  };
443 
444 
453  class NaryEqv : public BinaryPropagator<BoolView,PC_BOOL_VAL> {
454  protected:
460  int pm2;
462  void resubscribe(Space& home, BoolView& x0);
464  NaryEqv(Home home, ViewArray<BoolView>& x, int pm2);
466  NaryEqv(Space& home, NaryEqv& p);
467  public:
470  virtual Actor* copy(Space& home);
473  virtual PropCost cost(const Space& home, const ModEventDelta& med) const;
476  virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
479  static ExecStatus post(Home home, ViewArray<BoolView>& x, int pm2);
481  virtual size_t dispose(Space& home);
482  };
483 
484 
491  template<class VX, class VY>
492  class Clause : public Propagator {
493  protected:
499  VX z;
501  int n_zero;
503  class Tagged : public Advisor {
504  public:
506  const bool x;
508  Tagged(Space& home, Propagator& p, Council<Tagged>& c, bool x);
510  Tagged(Space& home, Tagged& a);
511  };
515  void cancel(Space& home);
517  Clause(Home home, ViewArray<VX>& x, ViewArray<VY>& y, VX z);
519  Clause(Space& home, Clause<VX,VY>& p);
520  public:
522  virtual Actor* copy(Space& home);
524  virtual ExecStatus advise(Space& home, Advisor& a, const Delta& d);
526  virtual PropCost cost(const Space& home, const ModEventDelta& med) const;
528  virtual void reschedule(Space& home);
530  virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
532  static ExecStatus post(Home home, ViewArray<VX>& x, ViewArray<VY>& y,
533  VX z);
535  virtual size_t dispose(Space& home);
536  };
537 
538 
545  template<class VX, class VY>
547  : public MixBinaryPropagator<VX,PC_BOOL_VAL,VY,PC_BOOL_VAL> {
548  protected:
559  public:
561  virtual Actor* copy(Space& home);
563  virtual PropCost cost(const Space& home, const ModEventDelta& med) const;
565  virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
567  static ExecStatus post(Home home, ViewArray<VX>& x, ViewArray<VY>& y);
569  virtual size_t dispose(Space& home);
570  };
571 
572 
579  template<class V0, class V1, class V2, PropCond pc>
580  class IteBase : public Propagator {
581  protected:
585  V0 x0; V1 x1; V2 x2;
587  IteBase(Space& home, IteBase& p);
589  IteBase(Home home, BoolView b, V0 x0, V1 x1, V2 x2);
590  public:
592  virtual PropCost cost(const Space& home, const ModEventDelta& med) const;
594  virtual void reschedule(Space& home);
596  virtual size_t dispose(Space& home);
597  };
598 
605  template<class V0, class V1, class V2>
606  class IteBnd : public IteBase<V0,V1,V2,PC_INT_BND> {
607  protected:
613  IteBnd(Space& home, IteBnd& p);
615  IteBnd(Home home, BoolView b, V0 x0, V1 x1, V2 x2);
616  public:
618  virtual Actor* copy(Space& home);
620  virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
622  static ExecStatus post(Home home, BoolView b, V0 x0, V1 x1, V2 x2);
623  };
624 
631  template<class V0, class V1, class V2>
632  class IteDom : public IteBase<V0,V1,V2,PC_INT_DOM> {
633  protected:
639  IteDom(Space& home, IteDom& p);
641  IteDom(Home home, BoolView b, V0 x0, V1 x1, V2 x2);
642  public:
644  virtual Actor* copy(Space& home);
646  virtual PropCost cost(const Space& home, const ModEventDelta& med) const;
648  virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
650  static ExecStatus post(Home home, BoolView b, V0 x0, V1 x1, V2 x2);
651  };
652 
653 }}}
654 
655 #include <gecode/int/bool/base.hpp>
656 #include <gecode/int/bool/eq.hpp>
657 #include <gecode/int/bool/lq.hpp>
658 #include <gecode/int/bool/or.hpp>
659 #include <gecode/int/bool/eqv.hpp>
661 #include <gecode/int/bool/ite.hpp>
662 
663 #endif
664 
665 // STATISTICS: int-prop
666 
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:193
Council of advisors
Definition: core.hpp:154
If-then-else bounds-consistent propagator.
Definition: bool.hh:606
BVC x2
Boolean view Constructor for posting.
Definition: bool.hh:81
Boolean clause propagator (disjunctive, true)
Definition: bool.hh:546
ViewArray< VY > y
Positive views (origin from negative variables)
Definition: bool.hh:497
void cancel(Space &home, Propagator &p, IntSet &y)
Definition: rel.hpp:81
ExecStatus resubscribe(Space &home, Propagator &p, VX &x0, ViewArray< VX > &x, VY &x1, ViewArray< VY > &y)
Definition: clause.hpp:138
BV x2
Boolean view without subscription.
Definition: bool.hh:269
Mixed (n+1)-ary propagator.
Definition: pattern.hpp:272
Base-class for propagators.
Definition: core.hpp:1023
Base-class for advisors.
Definition: core.hpp:1251
virtual PropCost cost(const Space &home, const ModEventDelta &med) const
Cost function (defined as low unary)
Definition: base.hpp:67
Boolean clause propagator (disjunctive)
Definition: bool.hh:492
ViewArray< VX > x
Positive views.
Definition: bool.hh:495
BoolBinary(Home home, BVA b0, BVB b1)
Definition: base.hpp:42
Computation spaces.
Definition: core.hpp:1701
Quarternary Boolean disjunction propagator (true)
Definition: bool.hh:295
Base-class for both propagators and branchers.
Definition: core.hpp:627
Gecode::IntSet d(v, 7)
Gecode::FloatVal c(-8, 8)
Ternary Boolean disjunction propagator (true)
Definition: bool.hh:264
virtual size_t dispose(Space &home)
Delete propagator and return its size.
Definition: base.hpp:80
int p
Number of positive literals for node type.
Definition: bool-expr.cpp:232
If-then-else propagator base-class.
Definition: bool.hh:580
n-ary Boolean equality propagator
Definition: bool.hh:133
Boolean equivalence propagator.
Definition: bool.hh:426
Binary propagator.
Definition: pattern.hpp:84
Council< Advisor > c
The advisor council.
Definition: bool.hh:363
int n_zero
The number of views assigned to zero in x.
Definition: bool.hh:189
ViewArray< VX > x
Views not yet subscribed to.
Definition: bool.hh:552
ModEventDelta med
A set of modification events (used during propagation)
Definition: core.hpp:1034
Boolean disjunction propagator.
Definition: bool.hh:328
struct Gecode::@593::NNF::@62::@63 b
For binary nodes (and, or, eqv)
n-ary propagator
Definition: pattern.hpp:142
virtual ExecStatus advise(Space &home, Advisor &a, const Delta &d)
Advise function.
Definition: core.cpp:67
ViewArray< VY > y
Views not yet subscribed to (origin from negative variables)
Definition: bool.hh:554
Council< Tagged > c
The advisor council.
Definition: bool.hh:513
Boolean equality propagator.
Definition: bool.hh:105
Boolean n-ary equivalence propagator.
Definition: bool.hh:453
int n_zero
The number of views assigned to zero in x and y.
Definition: bool.hh:501
int n_one
The number of views assigned to one in x.
Definition: bool.hh:191
BVB x1
Boolean view.
Definition: bool.hh:80
bool run
Whether the propagator is currently running.
Definition: bool.hh:187
BV x2
Boolean view without subscription.
Definition: bool.hh:300
Boolean less or equal propagator.
Definition: bool.hh:159
BoolView b
View for condition.
Definition: bool.hh:583
If-then-else domain-consistent propagator.
Definition: bool.hh:632
Boolean n-ary disjunction propagator (true)
Definition: bool.hh:393
Post propagator for SetVar SetOpType SetVar y
Definition: set.hh:767
Boolean less propagator.
Definition: bool.hh:223
Nary Boolean less or equal propagator.
Definition: bool.hh:183
ViewArray< BV > x
Views not yet subscribed to.
Definition: bool.hh:398
BVB x1
Boolean view Constructor for posting.
Definition: bool.hh:58
Generic domain change information to be supplied to advisors.
Definition: core.hpp:203
Mixed binary propagator.
Definition: pattern.hpp:204
Propagation cost.
Definition: core.hpp:485
Boolean n-ary disjunction propagator.
Definition: bool.hh:355
Binary Boolean disjunction propagator (true)
Definition: bool.hh:237
ExecStatus
Definition: core.hpp:471
virtual void reschedule(Space &home)
Schedule function.
Definition: base.hpp:73
ViewArray< BoolView > x
Views not yet subscribed to.
Definition: bool.hh:458
Post propagator for SetVar x
Definition: set.hh:767
BVA x0
Boolean view.
Definition: bool.hh:79
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)=0
Propagation function.
BV x3
Boolean view without subscription.
Definition: bool.hh:302
Gecode toplevel namespace
Base-class for ternary Boolean propagators.
Definition: bool.hh:77
BVA x0
Boolean view.
Definition: bool.hh:57
Advisors for views (tagged whether for x or y)
Definition: bool.hh:503
#define GECODE_INT_EXPORT
Definition: int.hh:81
Base-class for binary Boolean propagators.
Definition: bool.hh:55
int ModEventDelta
Modification event deltas.
Definition: core.hpp:89
Home class for posting propagators
Definition: core.hpp:853
int pm2
Parity information mod 2.
Definition: bool.hh:460
virtual Actor * copy(Space &home)=0
Create copy.
struct Gecode::@593::NNF::@62::@64 a
For atomic nodes.
const bool x
Whether advises a view for x or y.
Definition: bool.hh:506
TFE post(PropagatorGroup g)
Only post functions (but not propagators) from g are considered.
Definition: filter.cpp:138
Boolean view for Boolean variables.
Definition: view.hpp:1380