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