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
00045 template<class _View, class _Val>
00046 class MeritBase {
00047 public:
00049 typedef _View View;
00051 typedef typename View::VarType Var;
00053 typedef _Val Val;
00055 MeritBase(Space& home, const VarBranch<Var>& vb);
00057 MeritBase(Space& home, MeritBase& mb);
00059 bool notice(void) const;
00061 void dispose(Space& home);
00062 };
00063
00067 template<class View>
00068 class MeritFunction : public MeritBase<View,double> {
00069 using typename MeritBase<View,double>::Var;
00070 public:
00072 typedef typename BranchTraits<Var>::Merit Function;
00073 protected:
00075 SharedData<Function> f;
00076 public:
00078 MeritFunction(Space& home, const VarBranch<Var>& vb);
00080 MeritFunction(Space& home, MeritFunction& mf);
00082 double operator ()(const Space& home, View x, int i);
00084 bool notice(void) const;
00086 void dispose(Space& home);
00087 };
00088
00092 template<class View>
00093 class MeritDegree : public MeritBase<View,unsigned int> {
00094 using typename MeritBase<View,unsigned int>::Var;
00095 public:
00097 MeritDegree(Space& home, const VarBranch<Var>& vb);
00099 MeritDegree(Space& home, MeritDegree& md);
00101 unsigned int operator ()(const Space& home, View x, int i);
00102 };
00103
00107 template<class View>
00108 class MeritAFC : public MeritBase<View,double> {
00109 using typename MeritBase<View,double>::Var;
00110 protected:
00112 AFC afc;
00113 public:
00115 MeritAFC(Space& home, const VarBranch<Var>& vb);
00117 MeritAFC(Space& home, MeritAFC& ma);
00119 double operator ()(const Space& home, View x, int i);
00121 bool notice(void) const;
00123 void dispose(Space& home);
00124 };
00125
00129 template<class View>
00130 class MeritAction : public MeritBase<View,double> {
00131 using typename MeritBase<View,double>::Var;
00132 protected:
00134 Action action;
00135 public:
00137 MeritAction(Space& home, const VarBranch<Var>& vb);
00139 MeritAction(Space& home, MeritAction& ma);
00141 double operator ()(const Space& home, View x, int i);
00143 bool notice(void) const;
00145 void dispose(Space& home);
00146 };
00148
00152 template<class View>
00153 class MeritCHB : public MeritBase<View,double> {
00154 using typename MeritBase<View,double>::Var;
00155 protected:
00157 CHB chb;
00158 public:
00160 MeritCHB(Space& home, const VarBranch<Var>& vb);
00162 MeritCHB(Space& home, MeritCHB& ma);
00164 double operator ()(const Space& home, View x, int i);
00166 bool notice(void) const;
00168 void dispose(Space& home);
00169 };
00171
00172
00173
00174 template<class View, class Val>
00175 forceinline
00176 MeritBase<View,Val>::MeritBase(Space&, const VarBranch<Var>&) {}
00177 template<class View, class Val>
00178 forceinline
00179 MeritBase<View,Val>::MeritBase(Space&, MeritBase&) {}
00180 template<class View, class Val>
00181 forceinline bool
00182 MeritBase<View,Val>::notice(void) const {
00183 return false;
00184 }
00185 template<class View, class Val>
00186 forceinline void
00187 MeritBase<View,Val>::dispose(Space&) {}
00188
00189
00190 template<class View>
00191 forceinline
00192 MeritFunction<View>::MeritFunction(Space& home, const VarBranch<Var>& vb)
00193 : MeritBase<View,double>(home,vb), f(vb.merit()) {
00194 if (!f())
00195 throw InvalidFunction("MeritFunction::MeritFunction");
00196 }
00197 template<class View>
00198 forceinline
00199 MeritFunction<View>::MeritFunction(Space& home, MeritFunction& mf)
00200 : MeritBase<View,double>(home,mf), f(mf.f) {
00201 }
00202 template<class View>
00203 forceinline double
00204 MeritFunction<View>::operator ()(const Space& home, View x, int i) {
00205 typename View::VarType y(x.varimp());
00206 GECODE_VALID_FUNCTION(f());
00207 return f()(home,y,i);
00208 }
00209 template<class View>
00210 forceinline bool
00211 MeritFunction<View>::notice(void) const {
00212 return true;
00213 }
00214 template<class View>
00215 forceinline void
00216 MeritFunction<View>::dispose(Space&) {
00217 f.~SharedData<Function>();
00218 }
00219
00220
00221
00222 template<class View>
00223 forceinline
00224 MeritDegree<View>::MeritDegree(Space& home, const VarBranch<Var>& vb)
00225 : MeritBase<View,unsigned int>(home,vb) {}
00226 template<class View>
00227 forceinline
00228 MeritDegree<View>::MeritDegree(Space& home, MeritDegree& md)
00229 : MeritBase<View,unsigned int>(home,md) {}
00230 template<class View>
00231 forceinline unsigned int
00232 MeritDegree<View>::operator ()(const Space&, View x, int) {
00233 return x.degree();
00234 }
00235
00236
00237 template<class View>
00238 forceinline
00239 MeritAFC<View>::MeritAFC(Space& home, const VarBranch<Var>& vb)
00240 : MeritBase<View,double>(home,vb), afc(vb.afc()) {}
00241 template<class View>
00242 forceinline
00243 MeritAFC<View>::MeritAFC(Space& home, MeritAFC& ma)
00244 : MeritBase<View,double>(home,ma), afc(ma.afc) {}
00245 template<class View>
00246 forceinline double
00247 MeritAFC<View>::operator ()(const Space&, View x, int) {
00248 return x.afc();
00249 }
00250 template<class View>
00251 forceinline bool
00252 MeritAFC<View>::notice(void) const {
00253
00254 return false;
00255 }
00256 template<class View>
00257 forceinline void
00258 MeritAFC<View>::dispose(Space&) {
00259
00260 afc.~AFC();
00261 }
00262
00263
00264
00265 template<class View>
00266 forceinline
00267 MeritAction<View>::MeritAction(Space& home, const VarBranch<Var>& vb)
00268 : MeritBase<View,double>(home,vb), action(vb.action()) {}
00269 template<class View>
00270 forceinline
00271 MeritAction<View>::MeritAction(Space& home, MeritAction& ma)
00272 : MeritBase<View,double>(home,ma), action(ma.action) {}
00273 template<class View>
00274 forceinline double
00275 MeritAction<View>::operator ()(const Space&, View, int i) {
00276 return action[i];
00277 }
00278 template<class View>
00279 forceinline bool
00280 MeritAction<View>::notice(void) const {
00281 return true;
00282 }
00283 template<class View>
00284 forceinline void
00285 MeritAction<View>::dispose(Space&) {
00286 action.~Action();
00287 }
00288
00289
00290 template<class View>
00291 forceinline
00292 MeritCHB<View>::MeritCHB(Space& home, const VarBranch<Var>& vb)
00293 : MeritBase<View,double>(home,vb), chb(vb.chb()) {}
00294 template<class View>
00295 forceinline
00296 MeritCHB<View>::MeritCHB(Space& home, MeritCHB& ma)
00297 : MeritBase<View,double>(home,ma), chb(ma.chb) {}
00298 template<class View>
00299 forceinline double
00300 MeritCHB<View>::operator ()(const Space&, View, int i) {
00301 return chb[i];
00302 }
00303 template<class View>
00304 forceinline bool
00305 MeritCHB<View>::notice(void) const {
00306 return true;
00307 }
00308 template<class View>
00309 forceinline void
00310 MeritCHB<View>::dispose(Space&) {
00311 chb.~CHB();
00312 }
00313
00314 }
00315
00316