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 ValSelCommitBase {
00045 public:
00047 typedef _View View;
00049 typedef typename View::VarType Var;
00051 typedef _Val Val;
00052 public:
00054 ValSelCommitBase(Space& home, const ValBranch<Var>& vb);
00056 ValSelCommitBase(Space& home, ValSelCommitBase<View,Val>& vsc);
00058 virtual Val val(const Space& home, View x, int i) = 0;
00060 virtual ModEvent commit(Space& home, unsigned int a,
00061 View x, int i, Val n) = 0;
00063 virtual NGL* ngl(Space& home, unsigned int a,
00064 View x, Val n) const = 0;
00066 virtual void print(const Space& home, unsigned int a,
00067 View x, int i, const Val& n,
00068 std::ostream& o) const = 0;
00070 virtual ValSelCommitBase<View,Val>* copy(Space& home) = 0;
00072 virtual bool notice(void) const = 0;
00074 virtual void dispose(Space& home) = 0;
00076 virtual ~ValSelCommitBase(void);
00078
00079
00080 static void* operator new(size_t s, Space& home);
00082 static void operator delete(void* p, Space& home);
00084 static void operator delete(void* p);
00086 };
00087
00089 template<class ValSel, class ValCommit>
00090 class ValSelCommit
00091 : public ValSelCommitBase<typename ValSel::View,typename ValSel::Val> {
00092 protected:
00093 typedef typename ValSelCommitBase<typename ValSel::View,
00094 typename ValSel::Val>::Var Var;
00095 typedef typename ValSelCommitBase<typename ValSel::View,
00096 typename ValSel::Val>::Val Val;
00097 typedef typename ValSelCommitBase<typename ValSel::View,
00098 typename ValSel::Val>::View View;
00100 ValSel s;
00102 ValCommit c;
00103 public:
00105 ValSelCommit(Space& home, const ValBranch<Var>& vb);
00107 ValSelCommit(Space& home, ValSelCommit<ValSel,ValCommit>& vsc);
00109 virtual Val val(const Space& home, View x, int i);
00111 virtual ModEvent commit(Space& home, unsigned int a, View x, int i, Val n);
00113 virtual NGL* ngl(Space& home, unsigned int a,
00114 View x, Val n) const;
00116 virtual void print(const Space& home, unsigned int a,
00117 View x, int i, const Val& n,
00118 std::ostream& o) const;
00120 virtual ValSelCommit<ValSel,ValCommit>* copy(Space& home);
00122 virtual bool notice(void) const;
00124 virtual void dispose(Space& home);
00125 };
00127
00128
00129 template<class View, class Val>
00130 forceinline
00131 ValSelCommitBase<View,Val>::ValSelCommitBase(Space&,
00132 const ValBranch<Var>&) {}
00133 template<class View, class Val>
00134 forceinline
00135 ValSelCommitBase<View,Val>::
00136 ValSelCommitBase(Space&, ValSelCommitBase<View,Val>&) {}
00137 template<class View, class Val>
00138 ValSelCommitBase<View,Val>::~ValSelCommitBase(void) {}
00139
00140 template<class View, class Val>
00141 forceinline void
00142 ValSelCommitBase<View,Val>::operator delete(void*) {}
00143 template<class View, class Val>
00144 forceinline void
00145 ValSelCommitBase<View,Val>::operator delete(void*, Space&) {}
00146 template<class View, class Val>
00147 forceinline void*
00148 ValSelCommitBase<View,Val>::operator new(size_t s, Space& home) {
00149 return home.ralloc(s);
00150 }
00151
00152
00153
00154
00155 template<class ValSel, class ValCommit>
00156 forceinline
00157 ValSelCommit<ValSel,ValCommit>::ValSelCommit(Space& home,
00158 const ValBranch<Var>& vb)
00159 : ValSelCommitBase<View,Val>(home,vb), s(home,vb), c(home,vb) {}
00160
00161 template<class ValSel, class ValCommit>
00162 forceinline
00163 ValSelCommit<ValSel,ValCommit>::ValSelCommit(Space& home,
00164 ValSelCommit<ValSel,ValCommit>& vsc)
00165 : ValSelCommitBase<View,Val>(home,vsc),
00166 s(home,vsc.s), c(home,vsc.c) {}
00167
00168 template<class ValSel, class ValCommit>
00169 typename ValSelCommit<ValSel,ValCommit>::Val
00170 ValSelCommit<ValSel,ValCommit>::val(const Space& home, View x, int i) {
00171 return s.val(home,x,i);
00172 }
00173
00174 template<class ValSel, class ValCommit>
00175 ModEvent
00176 ValSelCommit<ValSel,ValCommit>::commit(Space& home, unsigned int a,
00177 View x, int i, Val n) {
00178 return c.commit(home,a,x,i,n);
00179 }
00180
00181 template<class ValSel, class ValCommit>
00182 NGL*
00183 ValSelCommit<ValSel,ValCommit>::ngl(Space& home, unsigned int a,
00184 View x, Val n) const {
00185 return c.ngl(home, a, x, n);
00186 }
00187
00188 template<class ValSel, class ValCommit>
00189 void
00190 ValSelCommit<ValSel,ValCommit>::print(const Space& home, unsigned int a,
00191 View x, int i, const Val& n,
00192 std::ostream& o) const {
00193 c.print(home,a,x,i,n,o);
00194 }
00195
00196 template<class ValSel, class ValCommit>
00197 ValSelCommit<ValSel,ValCommit>*
00198 ValSelCommit<ValSel,ValCommit>::copy(Space& home) {
00199 return new (home) ValSelCommit<ValSel,ValCommit>(home,*this);
00200 }
00201
00202 template<class ValSel, class ValCommit>
00203 bool
00204 ValSelCommit<ValSel,ValCommit>::notice(void) const {
00205 return s.notice() || c.notice();
00206 }
00207
00208 template<class ValSel, class ValCommit>
00209 void
00210 ValSelCommit<ValSel,ValCommit>::dispose(Space& home) {
00211 s.dispose(home);
00212 c.dispose(home);
00213 }
00214
00215 }
00216
00217