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
00049 template<class _View, class _Val>
00050 class MeritBase {
00051 public:
00053 typedef _View View;
00055 typedef _Val Val;
00057 MeritBase(Space& home, const VarBranch& vb);
00059 MeritBase(Space& home, bool share, MeritBase& mb);
00061 bool notice(void) const;
00063 void dispose(Space& home);
00064 };
00065
00069 template<class View>
00070 class MeritFunction : public MeritBase<View,double> {
00071 public:
00073 typedef typename View::VarType Var;
00075 typedef typename BranchTraits<Var>::Merit Function;
00076 protected:
00078 Function f;
00079 public:
00081 MeritFunction(Space& home, const VarBranch& vb);
00083 MeritFunction(Space& home, bool shared, MeritFunction& mf);
00085 double operator ()(const Space& home, View x, int i);
00086 };
00087
00091 template<class View>
00092 class MeritDegree : public MeritBase<View,unsigned int> {
00093 public:
00095 MeritDegree(Space& home, const VarBranch& vb);
00097 MeritDegree(Space& home, bool shared, MeritDegree& md);
00099 unsigned int operator ()(const Space& home, View x, int i);
00100 };
00101
00105 template<class View>
00106 class MeritAFC : public MeritBase<View,double> {
00107 protected:
00109 AFC afc;
00110 public:
00112 MeritAFC(Space& home, const VarBranch& vb);
00114 MeritAFC(Space& home, bool shared, MeritAFC& ma);
00116 double operator ()(const Space& home, View x, int i);
00118 bool notice(void) const;
00120 void dispose(Space& home);
00121 };
00122
00126 template<class View>
00127 class MeritActivity : public MeritBase<View,double> {
00128 protected:
00130 Activity activity;
00131 public:
00133 MeritActivity(Space& home, const VarBranch& vb);
00135 MeritActivity(Space& home, bool shared, MeritActivity& ma);
00137 double operator ()(const Space& home, View x, int i);
00139 bool notice(void) const;
00141 void dispose(Space& home);
00142 };
00144
00145
00146
00147 template<class View, class Val>
00148 forceinline
00149 MeritBase<View,Val>::MeritBase(Space&, const VarBranch&) {}
00150 template<class View, class Val>
00151 forceinline
00152 MeritBase<View,Val>::MeritBase(Space&, bool, MeritBase&) {}
00153 template<class View, class Val>
00154 forceinline bool
00155 MeritBase<View,Val>::notice(void) const {
00156 return false;
00157 }
00158 template<class View, class Val>
00159 forceinline void
00160 MeritBase<View,Val>::dispose(Space&) {}
00161
00162
00163 template<class View>
00164 forceinline
00165 MeritFunction<View>::MeritFunction(Space& home, const VarBranch& vb)
00166 : MeritBase<View,double>(home,vb),
00167 f(function_cast<Function>(vb.merit())) {}
00168 template<class View>
00169 forceinline
00170 MeritFunction<View>::MeritFunction(Space& home, bool shared,
00171 MeritFunction& mf)
00172 : MeritBase<View,double>(home,shared,mf), f(mf.f) {}
00173 template<class View>
00174 forceinline double
00175 MeritFunction<View>::operator ()(const Space& home, View x, int i) {
00176 typename View::VarType y(x.varimp());
00177 return f(home,y,i);
00178 }
00179
00180
00181 template<class View>
00182 forceinline
00183 MeritDegree<View>::MeritDegree(Space& home, const VarBranch& vb)
00184 : MeritBase<View,unsigned int>(home,vb) {}
00185 template<class View>
00186 forceinline
00187 MeritDegree<View>::MeritDegree(Space& home, bool shared,
00188 MeritDegree& md)
00189 : MeritBase<View,unsigned int>(home,shared,md) {}
00190 template<class View>
00191 forceinline unsigned int
00192 MeritDegree<View>::operator ()(const Space&, View x, int) {
00193 return x.degree();
00194 }
00195
00196
00197 template<class View>
00198 forceinline
00199 MeritAFC<View>::MeritAFC(Space& home, const VarBranch& vb)
00200 : MeritBase<View,double>(home,vb), afc(vb.afc()) {}
00201 template<class View>
00202 forceinline
00203 MeritAFC<View>::MeritAFC(Space& home, bool shared,
00204 MeritAFC& ma)
00205 : MeritBase<View,double>(home,shared,ma) {
00206 afc.update(home,shared,ma.afc);
00207 }
00208 template<class View>
00209 forceinline double
00210 MeritAFC<View>::operator ()(const Space& home, View x, int) {
00211 return x.afc(home);
00212 }
00213 template<class View>
00214 forceinline bool
00215 MeritAFC<View>::notice(void) const {
00216 return true;
00217 }
00218 template<class View>
00219 forceinline void
00220 MeritAFC<View>::dispose(Space&) {
00221 afc.~AFC();
00222 }
00223
00224
00225
00226 template<class View>
00227 forceinline
00228 MeritActivity<View>::MeritActivity(Space& home, const VarBranch& vb)
00229 : MeritBase<View,double>(home,vb), activity(vb.activity()) {}
00230 template<class View>
00231 forceinline
00232 MeritActivity<View>::MeritActivity(Space& home, bool shared,
00233 MeritActivity& ma)
00234 : MeritBase<View,double>(home,shared,ma) {
00235 activity.update(home, shared, ma.activity);
00236 }
00237 template<class View>
00238 forceinline double
00239 MeritActivity<View>::operator ()(const Space&, View, int i) {
00240 return activity[i];
00241 }
00242 template<class View>
00243 forceinline bool
00244 MeritActivity<View>::notice(void) const {
00245 return true;
00246 }
00247 template<class View>
00248 forceinline void
00249 MeritActivity<View>::dispose(Space&) {
00250 activity.~Activity();
00251 }
00252
00253 }
00254
00255