Generated on Sun Feb 17 15:24:07 2019 for Gecode by doxygen 1.6.3

var.hpp

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, 2012
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 #include <functional>
00035 
00036 namespace Gecode {
00037 
00047   typedef std::function<double(const Space& home, double w, double b)>
00048     BranchTbl;
00049 
00054   template<class Var>
00055   class VarBranch {
00056   public:
00058     typedef typename BranchTraits<Var>::Merit MeritFunction;
00059   protected:
00061     BranchTbl _tbl;
00063     Rnd _rnd;
00065     double _decay;
00067     AFC _afc;
00069     Action _act;
00071     CHB _chb;
00073     MeritFunction _mf;
00074   public:
00076     VarBranch(void);
00078     VarBranch(BranchTbl t);
00080     VarBranch(Rnd r);
00082     VarBranch(double d, BranchTbl t);
00084     VarBranch(AFC a, BranchTbl t);
00086     VarBranch(Action a, BranchTbl t);
00088     VarBranch(CHB c, BranchTbl t);
00090     VarBranch(MeritFunction f, BranchTbl t);
00092     BranchTbl tbl(void) const;
00094     Rnd rnd(void) const;
00096     double decay(void) const;
00098     AFC afc(void) const;
00100     void afc(AFC a);
00102     Action action(void) const;
00104     void action(Action a);
00106     CHB chb(void) const;
00108     void chb(CHB chb);
00110     MeritFunction merit(void) const;
00111   };
00112 
00113   // Variable branching
00114   template<class Var>
00115   inline
00116   VarBranch<Var>::VarBranch(void)
00117     : _tbl(nullptr), _decay(1.0) {}
00118 
00119   template<class Var>
00120   inline
00121   VarBranch<Var>::VarBranch(BranchTbl t)
00122     : _tbl(t), _decay(1.0) {}
00123 
00124   template<class Var>
00125   inline
00126   VarBranch<Var>::VarBranch(double d, BranchTbl t)
00127     : _tbl(t), _decay(d) {}
00128 
00129   template<class Var>
00130   inline
00131   VarBranch<Var>::VarBranch(AFC a, BranchTbl t)
00132     : _tbl(t), _decay(1.0), _afc(a) {
00133     if (!_afc)
00134       throw UninitializedAFC("VarBranch<Var>::VarBranch");
00135   }
00136 
00137   template<class Var>
00138   inline
00139   VarBranch<Var>::VarBranch(Action a, BranchTbl t)
00140     : _tbl(t), _decay(1.0), _act(a) {
00141     if (!_act)
00142       throw UninitializedAction("VarBranch<Var>::VarBranch");
00143   }
00144 
00145   template<class Var>
00146   inline
00147   VarBranch<Var>::VarBranch(CHB c, BranchTbl t)
00148     : _tbl(t), _decay(1.0), _chb(c) {
00149     if (!_chb)
00150       throw UninitializedCHB("VarBranch<Var>::VarBranch");
00151   }
00152 
00153   template<class Var>
00154   inline
00155   VarBranch<Var>::VarBranch(Rnd r)
00156     : _tbl(nullptr), _rnd(r), _decay(1.0) {
00157     if (!_rnd)
00158       throw UninitializedRnd("VarBranch<Var>::VarBranch");
00159   }
00160 
00161   template<class Var>
00162   inline
00163   VarBranch<Var>::VarBranch(MeritFunction f, BranchTbl t)
00164     : _tbl(t), _decay(1.0), _mf(f) {}
00165 
00166   template<class Var>
00167   inline BranchTbl
00168   VarBranch<Var>::tbl(void) const {
00169     return _tbl;
00170   }
00171 
00172   template<class Var>
00173   inline Rnd
00174   VarBranch<Var>::rnd(void) const {
00175     return _rnd;
00176   }
00177 
00178   template<class Var>
00179   inline double
00180   VarBranch<Var>::decay(void) const {
00181     return _decay;
00182   }
00183 
00184   template<class Var>
00185   inline AFC
00186   VarBranch<Var>::afc(void) const {
00187     return _afc;
00188   }
00189 
00190   template<class Var>
00191   inline void
00192   VarBranch<Var>::afc(AFC a) {
00193     _afc=a;
00194   }
00195 
00196   template<class Var>
00197   inline Action
00198   VarBranch<Var>::action(void) const {
00199     return _act;
00200   }
00201 
00202   template<class Var>
00203   inline void
00204   VarBranch<Var>::action(Action a) {
00205     _act=a;
00206   }
00207 
00208   template<class Var>
00209   inline CHB
00210   VarBranch<Var>::chb(void) const {
00211     return _chb;
00212   }
00213 
00214   template<class Var>
00215   inline void
00216   VarBranch<Var>::chb(CHB chb) {
00217     _chb=chb;
00218   }
00219 
00220   template<class Var>
00221   inline typename VarBranch<Var>::MeritFunction
00222   VarBranch<Var>::merit(void) const {
00223     return _mf;
00224   }
00225 
00226 }
00227 
00228 // STATISTICS: kernel-branch