Generated on Thu Apr 11 13:58:56 2019 for Gecode by doxygen 1.6.3

bool.hh

Go to the documentation of this file.
00001 /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
00002 /*
00003  *  Main authors:
00004  *     Christian Schulte <schulte@gecode.org>
00005  *     Guido Tack <tack@gecode.org>
00006  *
00007  *  Copyright:
00008  *     Christian Schulte, 2002
00009  *     Guido Tack, 2004
00010  *
00011  *  This file is part of Gecode, the generic constraint
00012  *  development environment:
00013  *     http://www.gecode.org
00014  *
00015  *  Permission is hereby granted, free of charge, to any person obtaining
00016  *  a copy of this software and associated documentation files (the
00017  *  "Software"), to deal in the Software without restriction, including
00018  *  without limitation the rights to use, copy, modify, merge, publish,
00019  *  distribute, sublicense, and/or sell copies of the Software, and to
00020  *  permit persons to whom the Software is furnished to do so, subject to
00021  *  the following conditions:
00022  *
00023  *  The above copyright notice and this permission notice shall be
00024  *  included in all copies or substantial portions of the Software.
00025  *
00026  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00027  *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00028  *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00029  *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
00030  *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
00031  *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00032  *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00033  *
00034  */
00035 
00036 #ifndef __GECODE_INT_BOOL_HH__
00037 #define __GECODE_INT_BOOL_HH__
00038 
00039 #include <gecode/int.hh>
00040 
00046 namespace Gecode { namespace Int { namespace Bool {
00047 
00048   /*
00049    * Base Classes
00050    *
00051    */
00052 
00054   template<class BVA, class BVB>
00055   class BoolBinary : public Propagator {
00056   protected:
00057     BVA x0; 
00058     BVB x1; 
00059 
00060     BoolBinary(Home home, BVA b0, BVB b1);
00062     BoolBinary(Space& home, BoolBinary& p);
00064     BoolBinary(Space& home, Propagator& p,
00065                BVA b0, BVB b1);
00066   public:
00068     virtual PropCost cost(const Space& home, const ModEventDelta& med) const;
00070     virtual void reschedule(Space& home);
00072     virtual size_t dispose(Space& home);
00073   };
00074 
00076   template<class BVA, class BVB, class BVC>
00077   class BoolTernary : public Propagator {
00078   protected:
00079     BVA x0; 
00080     BVB x1; 
00081     BVC x2; 
00082 
00083     BoolTernary(Home home, BVA b0, BVB b1, BVC b2);
00085     BoolTernary(Space& home, BoolTernary& p);
00086   public:
00088     BoolTernary(Space& home, Propagator& p,
00089                 BVA b0, BVB b1, BVC b2);
00091     virtual PropCost cost(const Space& home, const ModEventDelta& med) const;
00093     virtual void reschedule(Space& home);
00095     virtual size_t dispose(Space& home);
00096   };
00097 
00104   template<class BVA, class BVB>
00105   class Eq : public BoolBinary<BVA,BVB> {
00106   protected:
00107     using BoolBinary<BVA,BVB>::x0;
00108     using BoolBinary<BVA,BVB>::x1;
00110     Eq(Home home, BVA b0, BVB b1);
00112     Eq(Space& home, Eq& p);
00113   public:
00115     Eq(Space& home, Propagator& p,
00116        BVA b0, BVB b1);
00118     virtual Actor* copy(Space& home);
00120     virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
00122     static  ExecStatus post(Home home, BVA x0, BVB x1);
00123   };
00124 
00125 
00132   template<class BV>
00133   class NaryEq : public NaryPropagator<BV,PC_BOOL_VAL> {
00134   protected:
00135     using NaryPropagator<BV,PC_BOOL_VAL>::x;
00137     NaryEq(Home home, ViewArray<BV>& x);
00139     NaryEq(Space& home, NaryEq& p);
00140   public:
00142     virtual Actor* copy(Space& home);
00144     virtual PropCost cost(const Space& home, const ModEventDelta& med) const;
00146     virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
00148     static  ExecStatus post(Home home, ViewArray<BV>& x);
00149   };
00150 
00151 
00158   template<class BV>
00159   class Lq : public BoolBinary<BV,BV> {
00160   protected:
00161     using BoolBinary<BV,BV>::x0;
00162     using BoolBinary<BV,BV>::x1;
00164     Lq(Home home, BV b0, BV b1);
00166     Lq(Space& home, Lq& p);
00167   public:
00169     virtual Actor* copy(Space& home);
00171     virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
00173     static  ExecStatus post(Home home, BV b0, BV b1);
00174   };
00175 
00182   template<class VX>
00183   class NaryLq : public NaryPropagator<VX,PC_BOOL_NONE> {
00184   protected:
00185     using NaryPropagator<VX,PC_BOOL_NONE>::x;
00187     bool run;
00189     int n_zero;
00191     int n_one;
00193     Council<Advisor> c;
00195     NaryLq(Home home,  ViewArray<VX>& x);
00197     NaryLq(Space& home, NaryLq<VX>& p);
00198   public:
00200     virtual Actor* copy(Space& home);
00202     virtual ExecStatus advise(Space& home, Advisor& a, const Delta& d);
00204     virtual PropCost cost(const Space& home, const ModEventDelta& med) const;
00206     virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
00208     static  ExecStatus post(Home home, ViewArray<VX>& x);
00210     virtual size_t dispose(Space& home);
00211   };
00212 
00213 
00214 
00215 
00222   template<class BV>
00223   class Le {
00224   public:
00226     static  ExecStatus post(Home home, BV b0, BV b1);
00227   };
00228 
00229 
00236   template<class BVA, class BVB>
00237   class BinOrTrue : public BoolBinary<BVA,BVB> {
00238   protected:
00239     using BoolBinary<BVA,BVB>::x0;
00240     using BoolBinary<BVA,BVB>::x1;
00242     BinOrTrue(Home home, BVA b0, BVB b1);
00244     BinOrTrue(Space& home, BinOrTrue& p);
00245   public:
00247     BinOrTrue(Space& home, Propagator& p,
00248               BVA b0, BVB b1);
00250     virtual Actor* copy(Space& home);
00252     virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
00254     static  ExecStatus post(Home home, BVA b0, BVB b1);
00255   };
00256 
00263   template<class BV>
00264   class TerOrTrue : public BoolBinary<BV,BV> {
00265   protected:
00266     using BoolBinary<BV,BV>::x0;
00267     using BoolBinary<BV,BV>::x1;
00269     BV x2;
00271     TerOrTrue(Home home, BV b0, BV b1, BV b2);
00273     TerOrTrue(Space& home, TerOrTrue& p);
00274   public:
00276     TerOrTrue(Space& home, Propagator& p,
00277               BV b0, BV b1, BV b2);
00279     virtual Actor* copy(Space& home);
00281     virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
00283     static  ExecStatus post(Home home, BV b0, BV b1, BV b2);
00285     virtual size_t dispose(Space& home);
00286   };
00287 
00294   template<class BV>
00295   class QuadOrTrue : public BoolBinary<BV,BV> {
00296   protected:
00297     using BoolBinary<BV,BV>::x0;
00298     using BoolBinary<BV,BV>::x1;
00300     BV x2;
00302     BV x3;
00304     QuadOrTrue(Home home, BV b0, BV b1, BV b2, BV b3);
00306     QuadOrTrue(Space& home, QuadOrTrue& p);
00307   public:
00309     QuadOrTrue(Space& home, Propagator& p,
00310                BV b0, BV b1, BV b2, BV b3);
00312     virtual Actor* copy(Space& home);
00314     virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
00316     static  ExecStatus post(Home home, BV b0, BV b1, BV b2, BV b3);
00318     virtual size_t dispose(Space& home);
00319   };
00320 
00327   template<class BVA, class BVB, class BVC>
00328   class Or : public BoolTernary<BVA,BVB,BVC> {
00329   protected:
00330     using BoolTernary<BVA,BVB,BVC>::x0;
00331     using BoolTernary<BVA,BVB,BVC>::x1;
00332     using BoolTernary<BVA,BVB,BVC>::x2;
00334     Or(Home home, BVA b0, BVB b1, BVC b2);
00336     Or(Space& home, Or& p);
00337   public:
00339     Or(Space& home, Propagator& p, BVA b0, BVB b1, BVC b2);
00341     virtual Actor* copy(Space& home);
00343     virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
00345     static  ExecStatus post(Home home, BVA b0, BVB b1, BVC b2);
00346   };
00347 
00354   template<class VX,class VY>
00355   class NaryOr
00356     : public MixNaryOnePropagator<VX,PC_BOOL_NONE,VY,PC_BOOL_VAL> {
00357   protected:
00358     using MixNaryOnePropagator<VX,PC_BOOL_NONE,VY,PC_BOOL_VAL>::x;
00359     using MixNaryOnePropagator<VX,PC_BOOL_NONE,VY,PC_BOOL_VAL>::y;
00361     int n_zero;
00363     Council<Advisor> c;
00365     NaryOr(Home home,  ViewArray<VX>& x, VY y);
00367     NaryOr(Space& home, NaryOr<VX,VY>& p);
00368   public:
00370     virtual Actor* copy(Space& home);
00372     virtual ExecStatus advise(Space& home, Advisor& a, const Delta& d);
00374     virtual PropCost cost(const Space& home, const ModEventDelta& med) const;
00376     virtual void reschedule(Space& home);
00378     virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
00380     static  ExecStatus post(Home home, ViewArray<VX>& x, VY y);
00382     virtual size_t dispose(Space& home);
00383   };
00384 
00385 
00392   template<class BV>
00393   class NaryOrTrue : public BinaryPropagator<BV,PC_BOOL_VAL> {
00394   protected:
00395     using BinaryPropagator<BV,PC_BOOL_VAL>::x0;
00396     using BinaryPropagator<BV,PC_BOOL_VAL>::x1;
00398     ViewArray<BV> x;
00400     ExecStatus resubscribe(Space& home, BV& x0, BV x1);
00402     NaryOrTrue(Home home, ViewArray<BV>& x);
00404     NaryOrTrue(Space& home, NaryOrTrue<BV>& p);
00405   public:
00407     virtual Actor* copy(Space& home);
00409     virtual PropCost cost(const Space& home, const ModEventDelta& med) const;
00411     virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
00413     static  ExecStatus post(Home home, ViewArray<BV>& b);
00415     virtual size_t dispose(Space& home);
00416   };
00417 
00418 
00425   template<class BVA, class BVB, class BVC>
00426   class Eqv : public BoolTernary<BVA,BVB,BVC> {
00427   protected:
00428     using BoolTernary<BVA,BVB,BVC>::x0;
00429     using BoolTernary<BVA,BVB,BVC>::x1;
00430     using BoolTernary<BVA,BVB,BVC>::x2;
00432     Eqv(Space& home, Eqv& p);
00434     Eqv(Home home, BVA b0 ,BVB b1, BVC b2);
00435   public:
00437     virtual Actor* copy(Space& home);
00439     virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
00441     static  ExecStatus post(Home home, BVA b0, BVB b1, BVC b2);
00442   };
00443 
00444 
00453   class NaryEqv : public BinaryPropagator<BoolView,PC_BOOL_VAL> {
00454   protected:
00455     using BinaryPropagator<BoolView,PC_BOOL_VAL>::x0;
00456     using BinaryPropagator<BoolView,PC_BOOL_VAL>::x1;
00458     ViewArray<BoolView> x;
00460     int pm2;
00462     void resubscribe(Space& home, BoolView& x0);
00464     NaryEqv(Home home, ViewArray<BoolView>& x, int pm2);
00466     NaryEqv(Space& home, NaryEqv& p);
00467   public:
00469     GECODE_INT_EXPORT
00470     virtual Actor* copy(Space& home);
00472     GECODE_INT_EXPORT
00473     virtual PropCost cost(const Space& home, const ModEventDelta& med) const;
00475     GECODE_INT_EXPORT
00476     virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
00478     GECODE_INT_EXPORT
00479     static ExecStatus post(Home home, ViewArray<BoolView>& x, int pm2);
00481     virtual size_t dispose(Space& home);
00482   };
00483 
00484 
00491   template<class VX, class VY>
00492   class Clause : public Propagator {
00493   protected:
00495     ViewArray<VX> x;
00497     ViewArray<VY> y;
00499     VX z;
00501     int n_zero;
00503     class Tagged : public Advisor {
00504     public:
00506       const bool x;
00508       Tagged(Space& home, Propagator& p, Council<Tagged>& c, bool x);
00510       Tagged(Space& home, Tagged& a);
00511     };
00513     Council<Tagged> c;
00515     void cancel(Space& home);
00517     Clause(Home home,  ViewArray<VX>& x, ViewArray<VY>& y, VX z);
00519     Clause(Space& home, Clause<VX,VY>& p);
00520   public:
00522     virtual Actor* copy(Space& home);
00524     virtual ExecStatus advise(Space& home, Advisor& a, const Delta& d);
00526     virtual PropCost cost(const Space& home, const ModEventDelta& med) const;
00528     virtual void reschedule(Space& home);
00530     virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
00532     static  ExecStatus post(Home home, ViewArray<VX>& x, ViewArray<VY>& y,
00533                             VX z);
00535     virtual size_t dispose(Space& home);
00536   };
00537 
00538 
00545   template<class VX, class VY>
00546   class ClauseTrue
00547     : public MixBinaryPropagator<VX,PC_BOOL_VAL,VY,PC_BOOL_VAL> {
00548   protected:
00549     using MixBinaryPropagator<VX,PC_BOOL_VAL,VY,PC_BOOL_VAL>::x0;
00550     using MixBinaryPropagator<VX,PC_BOOL_VAL,VY,PC_BOOL_VAL>::x1;
00552     ViewArray<VX> x;
00554     ViewArray<VY> y;
00556     ClauseTrue(Home home, ViewArray<VX>& x, ViewArray<VY>& y);
00558     ClauseTrue(Space& home, ClauseTrue<VX,VY>& p);
00559   public:
00561     virtual Actor* copy(Space& home);
00563     virtual PropCost cost(const Space& home, const ModEventDelta& med) const;
00565     virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
00567     static  ExecStatus post(Home home, ViewArray<VX>& x, ViewArray<VY>& y);
00569     virtual size_t dispose(Space& home);
00570   };
00571 
00572 
00579   template<class V0, class V1, class V2, PropCond pc>
00580   class IteBase : public Propagator {
00581   protected:
00583     BoolView b;
00585     V0 x0; V1 x1; V2 x2;
00587     IteBase(Space& home, IteBase& p);
00589     IteBase(Home home, BoolView b, V0 x0, V1 x1, V2 x2);
00590   public:
00592     virtual PropCost cost(const Space& home, const ModEventDelta& med) const;
00594     virtual void reschedule(Space& home);
00596     virtual size_t dispose(Space& home);
00597   };
00598 
00605   template<class V0, class V1, class V2>
00606   class IteBnd : public IteBase<V0,V1,V2,PC_INT_BND> {
00607   protected:
00608     using IteBase<V0,V1,V2,PC_INT_BND>::b;
00609     using IteBase<V0,V1,V2,PC_INT_BND>::x0;
00610     using IteBase<V0,V1,V2,PC_INT_BND>::x1;
00611     using IteBase<V0,V1,V2,PC_INT_BND>::x2;
00613     IteBnd(Space& home, IteBnd& p);
00615     IteBnd(Home home, BoolView b, V0 x0, V1 x1, V2 x2);
00616   public:
00618     virtual Actor* copy(Space& home);
00620     virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
00622     static ExecStatus post(Home home, BoolView b, V0 x0, V1 x1, V2 x2);
00623   };
00624 
00631   template<class V0, class V1, class V2>
00632   class IteDom : public IteBase<V0,V1,V2,PC_INT_DOM> {
00633   protected:
00634     using IteBase<V0,V1,V2,PC_INT_DOM>::b;
00635     using IteBase<V0,V1,V2,PC_INT_DOM>::x0;
00636     using IteBase<V0,V1,V2,PC_INT_DOM>::x1;
00637     using IteBase<V0,V1,V2,PC_INT_DOM>::x2;
00639     IteDom(Space& home, IteDom& p);
00641     IteDom(Home home, BoolView b, V0 x0, V1 x1, V2 x2);
00642   public:
00644     virtual Actor* copy(Space& home);
00646     virtual PropCost cost(const Space& home, const ModEventDelta& med) const;
00648     virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
00650     static ExecStatus post(Home home, BoolView b, V0 x0, V1 x1, V2 x2);
00651   };
00652 
00653 }}}
00654 
00655 #include <gecode/int/bool/base.hpp>
00656 #include <gecode/int/bool/eq.hpp>
00657 #include <gecode/int/bool/lq.hpp>
00658 #include <gecode/int/bool/or.hpp>
00659 #include <gecode/int/bool/eqv.hpp>
00660 #include <gecode/int/bool/clause.hpp>
00661 #include <gecode/int/bool/ite.hpp>
00662 
00663 #endif
00664 
00665 // STATISTICS: int-prop
00666