Generated on Tue Mar 5 2013 22:37:16 for Gecode by doxygen 1.8.3.1
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: 2011-10-07 20:28:27 +1100 (Fri, 07 Oct 2011) $ by $Author: schulte $
13  * $Revision: 12427 $
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 
64  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 
85  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);
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 
569 }}}
570 
571 #include <gecode/int/bool/base.hpp>
572 #include <gecode/int/bool/eq.hpp>
573 #include <gecode/int/bool/lq.hpp>
574 #include <gecode/int/bool/or.hpp>
575 #include <gecode/int/bool/eqv.hpp>
577 
578 #endif
579 
580 // STATISTICS: int-prop
581