Generated on Sun Mar 19 2017 08:30:25 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  * Last modified:
12  * $Date: 2013-04-17 17:17:53 +0200 (Wed, 17 Apr 2013) $ by $Author: schulte $
13  * $Revision: 13580 $
14  *
15  * This file is part of Gecode, the generic constraint
16  * development environment:
17  * http://www.gecode.org
18  *
19  * Permission is hereby granted, free of charge, to any person obtaining
20  * a copy of this software and associated documentation files (the
21  * "Software"), to deal in the Software without restriction, including
22  * without limitation the rights to use, copy, modify, merge, publish,
23  * distribute, sublicense, and/or sell copies of the Software, and to
24  * permit persons to whom the Software is furnished to do so, subject to
25  * the following conditions:
26  *
27  * The above copyright notice and this permission notice shall be
28  * included in all copies or substantial portions of the Software.
29  *
30  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
31  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
32  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
33  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
34  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
35  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
36  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
37  *
38  */
39 
40 #ifndef __GECODE_INT_BOOL_HH__
41 #define __GECODE_INT_BOOL_HH__
42 
43 #include <gecode/int.hh>
44 
50 namespace Gecode { namespace Int { namespace Bool {
51 
52  /*
53  * Base Classes
54  *
55  */
56 
58  template<class BVA, class BVB>
59  class BoolBinary : public Propagator {
60  protected:
61  BVA x0;
62  BVB x1;
63  BoolBinary(Home home, BVA b0, BVB b1);
66  BoolBinary(Space& home, bool share, BoolBinary& p);
68  BoolBinary(Space& home, bool share, Propagator& p,
69  BVA b0, BVB b1);
70  public:
72  virtual PropCost cost(const Space& home, const ModEventDelta& med) const;
74  virtual size_t dispose(Space& home);
75  };
76 
78  template<class BVA, class BVB, class BVC>
79  class BoolTernary : public Propagator {
80  protected:
81  BVA x0;
82  BVB x1;
83  BVC x2;
84  BoolTernary(Home home, BVA b0, BVB b1, BVC b2);
87  BoolTernary(Space& home, bool share, BoolTernary& p);
88  public:
90  BoolTernary(Space& home, bool share, Propagator& p,
91  BVA b0, BVB b1, BVC b2);
93  virtual PropCost cost(const Space& home, const ModEventDelta& med) const;
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, bool share, Eq& p);
113  public:
115  Eq(Space& home, bool share, Propagator& p,
116  BVA b0, BVB b1);
118  virtual Actor* copy(Space& home, bool share);
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, bool share, NaryEq& p);
140  public:
142  virtual Actor* copy(Space& home, bool share);
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, bool share, Lq& p);
167  public:
169  virtual Actor* copy(Space& home, bool share);
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, bool share, NaryLq<VX>& p);
198  public:
200  virtual Actor* copy(Space& home, bool share);
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, bool share, BinOrTrue& p);
245  public:
247  BinOrTrue(Space& home, bool share, Propagator& p,
248  BVA b0, BVB b1);
250  virtual Actor* copy(Space& home, bool share);
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, bool share, TerOrTrue& p);
274  public:
276  TerOrTrue(Space& home, bool share, Propagator& p,
277  BV b0, BV b1, BV b2);
279  virtual Actor* copy(Space& home, bool share);
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, bool share, QuadOrTrue& p);
307  public:
309  QuadOrTrue(Space& home, bool share, Propagator& p,
310  BV b0, BV b1, BV b2, BV b3);
312  virtual Actor* copy(Space& home, bool share);
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, bool share, Or& p);
337  public:
339  Or(Space& home, bool share, Propagator& p, BVA b0, BVB b1, BVC b2);
341  virtual Actor* copy(Space& home, bool share);
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, bool share, NaryOr<VX,VY>& p);
368  public:
370  virtual Actor* copy(Space& home, bool share);
372  virtual ExecStatus advise(Space& home, Advisor& a, const Delta& d);
374  virtual PropCost cost(const Space& home, const ModEventDelta& med) const;
376  virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
378  static ExecStatus post(Home home, ViewArray<VX>& x, VY y);
380  virtual size_t dispose(Space& home);
381  };
382 
383 
390  template<class BV>
391  class NaryOrTrue : public BinaryPropagator<BV,PC_BOOL_VAL> {
392  protected:
398  ExecStatus resubscribe(Space& home, BV& x0, BV x1);
400  NaryOrTrue(Home home, ViewArray<BV>& x);
402  NaryOrTrue(Space& home, bool share, NaryOrTrue<BV>& p);
403  public:
405  virtual Actor* copy(Space& home, bool share);
407  virtual PropCost cost(const Space& home, const ModEventDelta& med) const;
409  virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
411  static ExecStatus post(Home home, ViewArray<BV>& b);
413  virtual size_t dispose(Space& home);
414  };
415 
416 
423  template<class BVA, class BVB, class BVC>
424  class Eqv : public BoolTernary<BVA,BVB,BVC> {
425  protected:
430  Eqv(Space& home, bool share, Eqv& p);
432  Eqv(Home home, BVA b0 ,BVB b1, BVC b2);
433  public:
435  virtual Actor* copy(Space& home, bool share);
437  virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
439  static ExecStatus post(Home home, BVA b0, BVB b1, BVC b2);
440  };
441 
442 
451  class NaryEqv : public BinaryPropagator<BoolView,PC_BOOL_VAL> {
452  protected:
458  int pm2;
460  void resubscribe(Space& home, BoolView& x0);
462  NaryEqv(Home home, ViewArray<BoolView>& x, int pm2);
464  NaryEqv(Space& home, bool share, NaryEqv& p);
465  public:
468  virtual Actor* copy(Space& home, bool share);
471  virtual PropCost cost(const Space& home, const ModEventDelta& med) const;
474  virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
477  static ExecStatus post(Home home, ViewArray<BoolView>& x, int pm2);
479  virtual size_t dispose(Space& home);
480  };
481 
482 
489  template<class VX, class VY>
490  class Clause : public Propagator {
491  protected:
497  VX z;
499  int n_zero;
501  class Tagged : public Advisor {
502  public:
504  const bool x;
506  Tagged(Space& home, Propagator& p, Council<Tagged>& c, bool x);
508  Tagged(Space& home, bool share, Tagged& a);
509  };
513  void cancel(Space& home);
515  Clause(Home home, ViewArray<VX>& x, ViewArray<VY>& y, VX z);
517  Clause(Space& home, bool share, Clause<VX,VY>& p);
518  public:
520  virtual Actor* copy(Space& home, bool share);
522  virtual ExecStatus advise(Space& home, Advisor& a, const Delta& d);
524  virtual PropCost cost(const Space& home, const ModEventDelta& med) const;
526  virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
528  static ExecStatus post(Home home, ViewArray<VX>& x, ViewArray<VY>& y,
529  VX z);
531  virtual size_t dispose(Space& home);
532  };
533 
534 
541  template<class VX, class VY>
543  : public MixBinaryPropagator<VX,PC_BOOL_VAL,VY,PC_BOOL_VAL> {
544  protected:
554  ClauseTrue(Space& home, bool share, ClauseTrue<VX,VY>& p);
555  public:
557  virtual Actor* copy(Space& home, bool share);
559  virtual PropCost cost(const Space& home, const ModEventDelta& med) const;
561  virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
563  static ExecStatus post(Home home, ViewArray<VX>& x, ViewArray<VY>& y);
565  virtual size_t dispose(Space& home);
566  };
567 
568 
575  template<class View, PropCond pc>
576  class IteBase : public Propagator {
577  protected:
581  View x0, x1, x2;
583  IteBase(Space& home, bool share, IteBase& p);
585  IteBase(Home home, BoolView b, View x0, View x1, View x2);
586  public:
588  virtual PropCost cost(const Space& home, const ModEventDelta& med) const;
590  virtual size_t dispose(Space& home);
591  };
592 
599  template<class View>
600  class IteBnd : public IteBase<View,PC_INT_BND> {
601  protected:
607  IteBnd(Space& home, bool share, IteBnd& p);
609  IteBnd(Home home, BoolView b, View x0, View x1, View x2);
610  public:
612  virtual Actor* copy(Space& home, bool share);
614  virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
616  static ExecStatus post(Home home, BoolView b, View x0, View x1, View x2);
617  };
618 
625  template<class View>
626  class IteDom : public IteBase<View,PC_INT_DOM> {
627  protected:
633  IteDom(Space& home, bool share, IteDom& p);
635  IteDom(Home home, BoolView b, View x0, View x1, View x2);
636  public:
638  virtual Actor* copy(Space& home, bool share);
640  virtual PropCost cost(const Space& home, const ModEventDelta& med) const;
642  virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
644  static ExecStatus post(Home home, BoolView b, View x0, View x1, View x2);
645  };
646 
647 }}}
648 
649 #include <gecode/int/bool/base.hpp>
650 #include <gecode/int/bool/eq.hpp>
651 #include <gecode/int/bool/lq.hpp>
652 #include <gecode/int/bool/or.hpp>
653 #include <gecode/int/bool/eqv.hpp>
655 #include <gecode/int/bool/ite.hpp>
656 
657 #endif
658 
659 // STATISTICS: int-prop
660 
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:226
If-then-else bounds-consistent propagator.
Definition: bool.hh:600
BVC x2
Boolean view Constructor for posting.
Definition: bool.hh:83
Boolean clause propagator (disjunctive, true)
Definition: bool.hh:542
void post(Home home, Term *t, int n, FloatRelType frt, FloatVal c)
Post propagator for linear constraint over floats.
Definition: post.cpp:228
ViewArray< VY > y
Positive views (origin from negative variables)
Definition: bool.hh:495
virtual Actor * copy(Space &home, bool share)=0
Create copy.
void cancel(Space &home, Propagator &p, IntSet &y)
Definition: rel.hpp:84
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
Mixed (n+1)-ary propagator.
Definition: propagator.hpp:268
Base-class for propagators.
Definition: core.hpp:755
Base-class for advisors.
Definition: core.hpp:926
virtual PropCost cost(const Space &home, const ModEventDelta &med) const
Cost function (defined as low unary)
Definition: base.hpp:72
Boolean clause propagator (disjunctive)
Definition: bool.hh:490
ViewArray< VX > x
Positive views.
Definition: bool.hh:493
BoolBinary(Home home, BVA b0, BVB b1)
Definition: base.hpp:46
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
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:78
int p
Number of positive literals for node type.
Definition: bool-expr.cpp:236
If-then-else propagator base-class.
Definition: bool.hh:576
n-ary Boolean equality propagator
Definition: bool.hh:133
Boolean equivalence propagator.
Definition: bool.hh:424
Binary propagator.
Definition: propagator.hpp:87
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:548
ModEventDelta med
A set of modification events (used during propagation)
Definition: core.hpp:764
Boolean disjunction propagator.
Definition: bool.hh:328
n-ary propagator
Definition: propagator.hpp:143
virtual ExecStatus advise(Space &home, Advisor &a, const Delta &d)
Advise function.
Definition: core.cpp:71
struct Gecode::@519::NNF::@60::@62 a
For atomic nodes.
ViewArray< VY > y
Views not yet subscribed to (origin from negative variables)
Definition: bool.hh:550
Council< Tagged > c
The advisor council.
Definition: bool.hh:511
Boolean equality propagator.
Definition: bool.hh:105
Boolean n-ary equivalence propagator.
Definition: bool.hh:451
int n_zero
The number of views assigned to zero in x and y.
Definition: bool.hh:499
int n_one
The number of views assigned to one in x.
Definition: bool.hh:191
BVB x1
Boolean view.
Definition: bool.hh:82
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
If-then-else domain-consistent propagator.
Definition: bool.hh:626
Boolean n-ary disjunction propagator (true)
Definition: bool.hh:391
struct Gecode::@519::NNF::@60::@61 b
For binary nodes (and, or, eqv)
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:396
BVB x1
Boolean view Constructor for posting.
Definition: bool.hh:62
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
Mixed binary propagator.
Definition: propagator.hpp:203
Propagation cost.
Definition: core.hpp:537
Boolean n-ary disjunction propagator.
Definition: bool.hh:355
Binary Boolean disjunction propagator (true)
Definition: bool.hh:237
ExecStatus
Definition: core.hpp:523
ViewArray< BoolView > x
Views not yet subscribed to.
Definition: bool.hh:456
BVA x0
Boolean view.
Definition: bool.hh:81
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)=0
Propagation function.
BV x3
Boolean view without subscription.
Definition: bool.hh:302
BoolView b
View for condition.
Definition: bool.hh:579
Gecode toplevel namespace
Base-class for ternary Boolean propagators.
Definition: bool.hh:79
BVA x0
Boolean view.
Definition: bool.hh:61
Advisors for views (tagged whether for x or y)
Definition: bool.hh:501
#define GECODE_INT_EXPORT
Definition: int.hh:78
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
int pm2
Parity information mod 2.
Definition: bool.hh:458
const bool x
Whether advises a view for x or y.
Definition: bool.hh:504
Boolean view for Boolean variables.
Definition: view.hpp:1315