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

branch.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  *
00006  *  Copyright:
00007  *     Christian Schulte, 2017
00008  *
00009  *  This file is part of Gecode, the generic constraint
00010  *  development environment:
00011  *     http://www.gecode.org
00012  *
00013  *  Permission is hereby granted, free of charge, to any person obtaining
00014  *  a copy of this software and associated documentation files (the
00015  *  "Software"), to deal in the Software without restriction, including
00016  *  without limitation the rights to use, copy, modify, merge, publish,
00017  *  distribute, sublicense, and/or sell copies of the Software, and to
00018  *  permit persons to whom the Software is furnished to do so, subject to
00019  *  the following conditions:
00020  *
00021  *  The above copyright notice and this permission notice shall be
00022  *  included in all copies or substantial portions of the Software.
00023  *
00024  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00025  *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00026  *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00027  *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
00028  *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
00029  *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00030  *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00031  *
00032  */
00033 
00034 #ifndef __GECODE_FLATZINC_BRANCH_HH__
00035 #define __GECODE_FLATZINC_BRANCH_HH__
00036 
00037 #include <gecode/int.hh>
00038 #include <gecode/int/branch.hh>
00039 #include <gecode/flatzinc.hh>
00040 
00041 namespace Gecode { namespace FlatZinc {
00042 
00044   class IntBoolVarBranch : public VarBranch<IntVar> {
00045   public:
00047     enum Select {
00048       SEL_AFC_MAX,         
00049       SEL_ACTION_MAX,      
00050       SEL_CHB_MAX,         
00051       SEL_AFC_SIZE_MAX,    
00052       SEL_ACTION_SIZE_MAX, 
00053       SEL_CHB_SIZE_MAX     
00054     };
00055   protected:
00057     Select s;
00059     IntAFC iafc;
00061     BoolAFC bafc;
00063     IntAction iaction;
00065     BoolAction baction;
00067     IntCHB ichb;
00069     BoolCHB bchb;
00070   public:
00072     IntBoolVarBranch(Select s, double d);
00074     IntBoolVarBranch(Select s, IntAFC i, BoolAFC b);
00076     IntBoolVarBranch(Select s, IntAction i, BoolAction b);
00078     IntBoolVarBranch(Select s, IntCHB i, BoolCHB b);
00080     Select select(void) const;
00082     IntAFC intafc(void) const;
00084     BoolAFC boolafc(void) const;
00086     IntAction intaction(void) const;
00088     BoolAction boolaction(void) const;
00090     IntCHB intchb(void) const;
00092     BoolCHB boolchb(void) const;
00094     void expand(Home home, const IntVarArgs& x, const BoolVarArgs& y);
00095   };
00096 
00098 
00099 
00100   IntBoolVarBranch INTBOOL_VAR_AFC_MAX(double d=1.0);
00102   IntBoolVarBranch INTBOOL_VAR_AFC_MAX(IntAFC ia, BoolAFC ba);
00104   IntBoolVarBranch INTBOOL_VAR_ACTION_MAX(double d=1.0);
00106   IntBoolVarBranch INTBOOL_VAR_ACTION_MAX(IntAction ia, BoolAction ba);
00108   IntBoolVarBranch INTBOOL_VAR_CHB_MAX(double d=1.0);
00110   IntBoolVarBranch INTBOOL_VAR_CHB_MAX(IntCHB ic, BoolCHB bc);
00112   IntBoolVarBranch INTBOOL_VAR_AFC_SIZE_MAX(double d=1.0);
00114   IntBoolVarBranch INTBOOL_VAR_AFC_SIZE_MAX(IntAFC ia, BoolAFC ba);
00116   IntBoolVarBranch INTBOOL_VAR_ACTION_SIZE_MAX(double d=1.0);
00118   IntBoolVarBranch INTBOOL_VAR_ACTION_SIZE_MAX(IntAction ia, BoolAction ba);
00120   IntBoolVarBranch INTBOOL_VAR_CHB_SIZE_MAX(double d=1.0);
00122   IntBoolVarBranch INTBOOL_VAR_CHB_SIZE_MAX(IntCHB ic, BoolCHB bc);
00124   
00126   class MeritMaxAFC {
00127   protected:
00129     IntAFC iafc;
00131     BoolAFC bafc;
00132   public:
00134     MeritMaxAFC(Space& home, const IntBoolVarBranch& ibvb);
00136     MeritMaxAFC(Space& home, MeritMaxAFC& m);
00138     double operator()(Int::IntView x, int i) const;
00140     double operator()(Int::BoolView x, int i) const;
00142     void dispose(void);
00143   };
00144 
00146   class MeritMaxAFCSize {
00147   protected:
00149     IntAFC iafc;
00151     BoolAFC bafc;
00152   public:
00154     MeritMaxAFCSize(Space& home, const IntBoolVarBranch& ibvb);
00156     MeritMaxAFCSize(Space& home, MeritMaxAFCSize& m);
00158     double operator()(Int::IntView x, int i) const;
00160     double operator()(Int::BoolView x, int i) const;
00162     void dispose(void);
00163   };
00164 
00166   class MeritMaxAction {
00167   protected:
00169     IntAction iaction;
00171     BoolAction baction;
00172   public:
00174     MeritMaxAction(Space& home, const IntBoolVarBranch& ibvb);
00176     MeritMaxAction(Space& home, MeritMaxAction& m);
00178     double operator()(Int::IntView x, int i) const;
00180     double operator()(Int::BoolView x, int i) const;
00182     void dispose(void);
00183   };
00184 
00186   class MeritMaxActionSize {
00187   protected:
00189     IntAction iaction;
00191     BoolAction baction;
00192   public:
00194     MeritMaxActionSize(Space& home, const IntBoolVarBranch& ibvb);
00196     MeritMaxActionSize(Space& home, MeritMaxActionSize& m);
00198     double operator()(Int::IntView x, int i) const;
00200     double operator()(Int::BoolView x, int i) const;
00202     void dispose(void);
00203   };
00204 
00206   class MeritMaxCHB {
00207   protected:
00209     IntCHB ichb;
00211     BoolCHB bchb;
00212   public:
00214     MeritMaxCHB(Space& home, const IntBoolVarBranch& ibvb);
00216     MeritMaxCHB(Space& home, MeritMaxCHB& m);
00218     double operator()(Int::IntView x, int i) const;
00220     double operator()(Int::BoolView x, int i) const;
00222     void dispose(void);
00223   };
00224 
00226   class MeritMaxCHBSize {
00227   protected:
00229     IntCHB ichb;
00231     BoolCHB bchb;
00232   public:
00234     MeritMaxCHBSize(Space& home, const IntBoolVarBranch& ibvb);
00236     MeritMaxCHBSize(Space& home, MeritMaxCHBSize& m);
00238     double operator()(Int::IntView x, int i) const;
00240     double operator()(Int::BoolView x, int i) const;
00242     void dispose(void);
00243   };
00244 
00246   class GECODE_VTABLE_EXPORT PosIntChoice : public Choice {
00247   private:
00249     int _pos;
00251     int _val;
00252   public:
00254     PosIntChoice(const Brancher& b, unsigned int a, int p, int n);
00256     int pos(void) const;
00258     int val(void) const;
00260     virtual void archive(Archive& e) const;
00261   };
00262 
00264   class IntBoolBrancherBase : public Brancher {
00265   protected:
00267     ViewArray<Int::IntView> x;
00269     ViewArray<Int::BoolView> y;
00271     mutable int start;
00273     ValSelCommitBase<Int::IntView,int>* xvsc;
00275     ValSelCommitBase<Int::BoolView,int>* yvsc;
00277     IntBoolBrancherBase(Space& home, IntBoolBrancherBase& b);
00279     IntBoolBrancherBase(Home home,
00280                         ViewArray<Int::IntView> x, ViewArray<Int::BoolView> y,
00281                         ValSelCommitBase<Int::IntView,int>* xvsc,
00282                         ValSelCommitBase<Int::BoolView,int>* yvsc);
00283   public:
00285     virtual bool status(const Space& home) const;
00287     virtual const Choice* choice(Space& home) = 0;
00289     virtual const Choice* choice(const Space& home, Archive& e);
00291     virtual ExecStatus commit(Space& home, const Choice& c, unsigned int b);
00293     virtual NGL* ngl(Space& home, const Choice& c, unsigned int b) const;
00295     virtual void print(const Space& home, const Choice& c, unsigned int b,
00296                        std::ostream& o) const;
00298     virtual size_t dispose(Space& home);
00299   };
00300 
00302   template<class Merit>
00303   class IntBoolBrancher : public IntBoolBrancherBase {
00304   protected:
00306     Merit merit;
00308     IntBoolBrancher(Space& home, IntBoolBrancher& b);
00310     IntBoolBrancher(Home home,
00311                     ViewArray<Int::IntView> x, ViewArray<Int::BoolView> y,
00312                     Merit& m,
00313                     ValSelCommitBase<Int::IntView,int>* xvsc,
00314                     ValSelCommitBase<Int::BoolView,int>* yvsc);
00315   public:
00317     virtual const Choice* choice(Space& home);
00319     virtual Actor* copy(Space& home);
00321     static void post(Home home,
00322                      ViewArray<Int::IntView> x, ViewArray<Int::BoolView> y,
00323                      Merit& m,
00324                      ValSelCommitBase<Int::IntView,int>* xvsc,
00325                      ValSelCommitBase<Int::BoolView,int>* yvsc);
00327     virtual size_t dispose(Space& home);
00328   };
00329 
00331   BoolValBranch i2b(const IntValBranch& ivb);
00332 
00334   GECODE_FLATZINC_EXPORT void
00335   branch(Home home, const IntVarArgs& x, const BoolVarArgs& y,
00336          IntBoolVarBranch vars, IntValBranch vals);
00337 
00338 }}
00339 
00340 #include <gecode/flatzinc/branch.hpp>
00341 
00342 #endif
00343 
00344 // STATISTICS: flatzinc-branch