Generated on Tue Apr 18 10:22:03 2017 for Gecode by doxygen 1.6.3

branch-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  *  Last modified:
00010  *     $Date: 2017-03-08 11:58:56 +0100 (Wed, 08 Mar 2017) $ by $Author: schulte $
00011  *     $Revision: 15562 $
00012  *
00013  *  This file is part of Gecode, the generic constraint
00014  *  development environment:
00015  *     http://www.gecode.org
00016  *
00017  *  Permission is hereby granted, free of charge, to any person obtaining
00018  *  a copy of this software and associated documentation files (the
00019  *  "Software"), to deal in the Software without restriction, including
00020  *  without limitation the rights to use, copy, modify, merge, publish,
00021  *  distribute, sublicense, and/or sell copies of the Software, and to
00022  *  permit persons to whom the Software is furnished to do so, subject to
00023  *  the following conditions:
00024  *
00025  *  The above copyright notice and this permission notice shall be
00026  *  included in all copies or substantial portions of the Software.
00027  *
00028  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00029  *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00030  *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00031  *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
00032  *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
00033  *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00034  *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00035  *
00036  */
00037 
00038 #include <functional>
00039 
00040 namespace Gecode {
00041 
00051   typedef std::function<double(const Space& home, double w, double b)>
00052     BranchTbl;
00053 
00058   template<class Var>
00059   class VarBranch {
00060   public:
00062     typedef typename BranchTraits<Var>::Merit MeritFunction;
00063   protected:
00065     BranchTbl _tbl;
00067     Rnd _rnd;
00069     double _decay;
00071     AFC _afc;
00073     Action _act;
00075     CHB _chb;
00077     MeritFunction _mf;
00078   public:
00080     VarBranch(void);
00082     VarBranch(BranchTbl t);
00084     VarBranch(Rnd r);
00086     VarBranch(double d, BranchTbl t);
00088     VarBranch(AFC a, BranchTbl t);
00090     VarBranch(Action a, BranchTbl t);
00092     VarBranch(CHB c, BranchTbl t);
00094     VarBranch(MeritFunction f, BranchTbl t);
00096     BranchTbl tbl(void) const;
00098     Rnd rnd(void) const;
00100     double decay(void) const;
00102     AFC afc(void) const;
00104     void afc(AFC a);
00106     Action action(void) const;
00108     void action(Action a);
00110     CHB chb(void) const;
00112     void chb(CHB chb);
00114     MeritFunction merit(void) const;
00115   };
00116 
00117   // Variable branching
00118   template<class Var>
00119   inline
00120   VarBranch<Var>::VarBranch(void)
00121     : _tbl(nullptr), _decay(1.0) {}
00122 
00123   template<class Var>
00124   inline
00125   VarBranch<Var>::VarBranch(BranchTbl t)
00126     : _tbl(t), _decay(1.0) {}
00127 
00128   template<class Var>
00129   inline
00130   VarBranch<Var>::VarBranch(double d, BranchTbl t)
00131     : _tbl(t), _decay(d) {}
00132 
00133   template<class Var>
00134   inline
00135   VarBranch<Var>::VarBranch(AFC a, BranchTbl t)
00136     : _tbl(t), _decay(1.0), _afc(a) {
00137     if (!_afc)
00138       throw UninitializedAFC("VarBranch<Var>::VarBranch");
00139   }
00140 
00141   template<class Var>
00142   inline
00143   VarBranch<Var>::VarBranch(Action a, BranchTbl t)
00144     : _tbl(t), _decay(1.0), _act(a) {
00145     if (!_act)
00146       throw UninitializedAction("VarBranch<Var>::VarBranch");
00147   }
00148 
00149   template<class Var>
00150   inline
00151   VarBranch<Var>::VarBranch(CHB c, BranchTbl t)
00152     : _tbl(t), _decay(1.0), _chb(c) {
00153     if (!_chb)
00154       throw UninitializedCHB("VarBranch<Var>::VarBranch");
00155   }
00156 
00157   template<class Var>
00158   inline
00159   VarBranch<Var>::VarBranch(Rnd r)
00160     : _tbl(nullptr), _rnd(r), _decay(1.0) {
00161     if (!_rnd)
00162       throw UninitializedRnd("VarBranch<Var>::VarBranch");
00163   }
00164 
00165   template<class Var>
00166   inline
00167   VarBranch<Var>::VarBranch(MeritFunction f, BranchTbl t)
00168     : _tbl(t), _decay(1.0), _mf(f) {}
00169 
00170   template<class Var>
00171   inline BranchTbl
00172   VarBranch<Var>::tbl(void) const {
00173     return _tbl;
00174   }
00175 
00176   template<class Var>
00177   inline Rnd
00178   VarBranch<Var>::rnd(void) const {
00179     return _rnd;
00180   }
00181 
00182   template<class Var>
00183   inline double
00184   VarBranch<Var>::decay(void) const {
00185     return _decay;
00186   }
00187 
00188   template<class Var>
00189   inline AFC
00190   VarBranch<Var>::afc(void) const {
00191     return _afc;
00192   }
00193 
00194   template<class Var>
00195   inline void
00196   VarBranch<Var>::afc(AFC a) {
00197     _afc=a;
00198   }
00199 
00200   template<class Var>
00201   inline Action
00202   VarBranch<Var>::action(void) const {
00203     return _act;
00204   }
00205 
00206   template<class Var>
00207   inline void
00208   VarBranch<Var>::action(Action a) {
00209     _act=a;
00210   }
00211 
00212   template<class Var>
00213   inline CHB
00214   VarBranch<Var>::chb(void) const {
00215     return _chb;
00216   }
00217 
00218   template<class Var>
00219   inline void
00220   VarBranch<Var>::chb(CHB chb) {
00221     _chb=chb;
00222   }
00223 
00224   template<class Var>
00225   inline typename VarBranch<Var>::MeritFunction
00226   VarBranch<Var>::merit(void) const {
00227     return _mf;
00228   }
00229 
00230 }
00231 
00232 // STATISTICS: kernel-branch