brancher-val-sel.hpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 namespace Gecode {
00039
00046
00047 template<class _View, class _Val>
00048 class ValSel {
00049 public:
00051 typedef _View View;
00053 typedef typename View::VarType Var;
00055 typedef _Val Val;
00056 public:
00058 ValSel(Space& home, const ValBranch<Var>& vb);
00060 ValSel(Space& home, bool shared, ValSel<View,Val>& vs);
00062 bool notice(void) const;
00064 void dispose(Space& home);
00065 };
00066
00068 template<class View>
00069 class ValSelFunction :
00070 public ValSel<View,
00071 typename BranchTraits<typename View::VarType>::ValType> {
00072 using typename ValSel<View,
00073 typename BranchTraits<typename View::VarType>::ValType>::Var;
00074 public:
00076 typedef typename ValSel<View,
00077 typename BranchTraits<typename View::VarType>
00078 ::ValType>::Val Val;
00080 typedef typename BranchTraits<Var>::Val ValFunction;
00081 protected:
00083 SharedData<ValFunction> v;
00084 public:
00086 ValSelFunction(Space& home, const ValBranch<Var>& vb);
00088 ValSelFunction(Space& home, bool shared, ValSelFunction<View>& vs);
00090 Val val(const Space& home, View x, int i);
00092 bool notice(void) const;
00094 void dispose(Space& home);
00095 };
00097
00098
00099
00100 template<class View, class Val>
00101 forceinline
00102 ValSel<View,Val>::ValSel(Space&, const ValBranch<Var>&) {}
00103 template<class View, class Val>
00104 forceinline
00105 ValSel<View,Val>::ValSel(Space&, bool, ValSel<View,Val>&) {}
00106 template<class View, class Val>
00107 forceinline bool
00108 ValSel<View,Val>::notice(void) const {
00109 return false;
00110 }
00111 template<class View, class Val>
00112 forceinline void
00113 ValSel<View,Val>::dispose(Space&) {}
00114
00115
00116
00117 template<class View>
00118 forceinline
00119 ValSelFunction<View>::ValSelFunction(Space& home, const ValBranch<Var>& vb)
00120 : ValSel<View,Val>(home,vb), v(vb.val()) {
00121 if (!v())
00122 throw InvalidFunction("ValSelFunction::ValSelFunction");
00123 }
00124 template<class View>
00125 forceinline
00126 ValSelFunction<View>::ValSelFunction(Space& home, bool shared,
00127 ValSelFunction<View>& vs)
00128 : ValSel<View,Val>(home,shared,vs) {
00129 v.update(home,shared,vs.v);
00130 }
00131 template<class View>
00132 forceinline typename ValSelFunction<View>::Val
00133 ValSelFunction<View>::val(const Space& home, View x, int i) {
00134 typename View::VarType y(x.varimp());
00135 GECODE_VALID_FUNCTION(v());
00136 return v()(home,y,i);
00137 }
00138 template<class View>
00139 forceinline bool
00140 ValSelFunction<View>::notice(void) const {
00141 return true;
00142 }
00143 template<class View>
00144 forceinline void
00145 ValSelFunction<View>::dispose(Space&) {
00146 v.~SharedData<ValFunction>();
00147 }
00148
00149 }
00150
00151