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 ValCommit {
00049 public:
00051 typedef _View View;
00053 typedef typename View::VarType Var;
00055 typedef _Val Val;
00056 public:
00058 ValCommit(Space& home, const ValBranch<Var>& vb);
00060 ValCommit(Space& home, bool shared, ValCommit<View,Val>& vs);
00062 bool notice(void) const;
00064 void dispose(Space& home);
00065 };
00066
00068 template<class View>
00069 class ValCommitFunction : public
00070 ValCommit<View,
00071 typename BranchTraits<typename View::VarType>::ValType> {
00072 typedef typename ValCommit<View,
00073 typename BranchTraits<typename View::VarType>
00074 ::ValType>::Val Val;
00075 public:
00077 typedef typename View::VarType Var;
00079 typedef typename BranchTraits<Var>::Commit CommitFunction;
00080 protected:
00082 SharedData<CommitFunction> c;
00083 public:
00085 ValCommitFunction(Space& home, const ValBranch<Var>& vb);
00087 ValCommitFunction(Space& home, bool shared, ValCommitFunction& vc);
00089 ModEvent commit(Space& home, unsigned int a, View x, int i, Val n);
00091 NGL* ngl(Space& home, unsigned int a, View x, Val n) const;
00093 void print(const Space& home, unsigned int a, View x, int i,
00094 const Val& n, std::ostream& o) const;
00096 bool notice(void) const;
00098 void dispose(Space& home);
00099 };
00101
00102
00103 template<class View, class Val>
00104 forceinline
00105 ValCommit<View,Val>::ValCommit(Space&, const ValBranch<Var>&) {}
00106 template<class View, class Val>
00107 forceinline
00108 ValCommit<View,Val>::ValCommit(Space&, bool, ValCommit<View,Val>&) {}
00109 template<class View, class Val>
00110 forceinline bool
00111 ValCommit<View,Val>::notice(void) const {
00112 return false;
00113 }
00114 template<class View, class Val>
00115 forceinline void
00116 ValCommit<View,Val>::dispose(Space&) {}
00117
00118
00119
00120 template<class View>
00121 forceinline
00122 ValCommitFunction<View>::ValCommitFunction(Space& home,
00123 const ValBranch<Var>& vb)
00124 : ValCommit<View,Val>(home,vb), c(vb.commit()) {
00125 if (!c())
00126 throw InvalidFunction("ValCommitFunction::ValCommitFunction");
00127 }
00128 template<class View>
00129 forceinline
00130 ValCommitFunction<View>::ValCommitFunction(Space& home, bool shared,
00131 ValCommitFunction<View>& vc)
00132 : ValCommit<View,Val>(home,shared,vc) {
00133 c.update(home,shared,vc.c);
00134 }
00135 template<class View>
00136 forceinline ModEvent
00137 ValCommitFunction<View>::commit(Space& home, unsigned int a, View x, int i,
00138 Val n) {
00139 typename View::VarType y(x.varimp());
00140 GECODE_VALID_FUNCTION(c());
00141 c()(home,a,y,i,n);
00142 return home.failed() ? ES_FAILED : ES_OK;
00143 }
00144 template<class View>
00145 forceinline NGL*
00146 ValCommitFunction<View>::ngl(Space&, unsigned int, View, Val) const {
00147 return NULL;
00148 }
00149 template<class View>
00150 forceinline void
00151 ValCommitFunction<View>::print(const Space&, unsigned int,
00152 View, int i, const Val&,
00153 std::ostream& o) const {
00154 o << "var[" << i << "] is user-defined.";
00155 }
00156 template<class View>
00157 forceinline bool
00158 ValCommitFunction<View>::notice(void) const {
00159 return true;
00160 }
00161 template<class View>
00162 forceinline void
00163 ValCommitFunction<View>::dispose(Space&) {
00164 c.~SharedData<CommitFunction>();
00165 }
00166
00167 }
00168
00169