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 { namespace Int { namespace Branch {
00035
00036 template<class View>
00037 forceinline
00038 ValSelMin<View>::ValSelMin(Space& home, const ValBranch<Var>& vb)
00039 : ValSel<View,int>(home,vb) {}
00040 template<class View>
00041 forceinline
00042 ValSelMin<View>::ValSelMin(Space& home, ValSelMin& vs)
00043 : ValSel<View,int>(home,vs) {}
00044 template<class View>
00045 forceinline int
00046 ValSelMin<View>::val(const Space&, View x, int) {
00047 return x.min();
00048 }
00049
00050 template<class View>
00051 forceinline
00052 ValSelMax<View>::ValSelMax(Space& home, const ValBranch<Var>& vb)
00053 : ValSel<View,int>(home,vb) {}
00054 template<class View>
00055 forceinline
00056 ValSelMax<View>::ValSelMax(Space& home, ValSelMax& vs)
00057 : ValSel<View,int>(home,vs) {}
00058 template<class View>
00059 forceinline int
00060 ValSelMax<View>::val(const Space&, View x, int) {
00061 return x.max();
00062 }
00063
00064 template<class View>
00065 forceinline
00066 ValSelMed<View>::ValSelMed(Space& home, const ValBranch<Var>& vb)
00067 : ValSel<View,int>(home,vb) {}
00068 template<class View>
00069 forceinline
00070 ValSelMed<View>::ValSelMed(Space& home, ValSelMed& vs)
00071 : ValSel<View,int>(home,vs) {}
00072 template<class View>
00073 forceinline int
00074 ValSelMed<View>::val(const Space&, View x, int) {
00075 return x.med();
00076 }
00077
00078 template<class View>
00079 forceinline
00080 ValSelAvg<View>::ValSelAvg(Space& home, const ValBranch<Var>& vb)
00081 : ValSel<View,int>(home,vb) {}
00082 template<class View>
00083 forceinline
00084 ValSelAvg<View>::ValSelAvg(Space& home, ValSelAvg& vs)
00085 : ValSel<View,int>(home,vs) {}
00086 template<class View>
00087 forceinline int
00088 ValSelAvg<View>::val(const Space&, View x, int) {
00089 return (x.width() == 2U) ? x.min() : ((x.min()+x.max()) / 2);
00090 }
00091
00092 template<class View>
00093 forceinline
00094 ValSelRnd<View>::ValSelRnd(Space& home, const ValBranch<Var>& vb)
00095 : ValSel<View,int>(home,vb), r(vb.rnd()) {}
00096 template<class View>
00097 forceinline
00098 ValSelRnd<View>::ValSelRnd(Space& home, ValSelRnd& vs)
00099 : ValSel<View,int>(home,vs), r(vs.r) {
00100 }
00101 template<class View>
00102 forceinline int
00103 ValSelRnd<View>::val(const Space&, View x, int) {
00104 unsigned int p = r(x.size());
00105 for (ViewRanges<View> i(x); i(); ++i) {
00106 if (i.width() > p)
00107 return i.min() + static_cast<int>(p);
00108 p -= i.width();
00109 }
00110 GECODE_NEVER;
00111 return 0;
00112 }
00113 template<class View>
00114 forceinline bool
00115 ValSelRnd<View>::notice(void) const {
00116 return true;
00117 }
00118 template<class View>
00119 forceinline void
00120 ValSelRnd<View>::dispose(Space&) {
00121 r.~Rnd();
00122 }
00123
00124 forceinline
00125 ValSelRangeMin::ValSelRangeMin(Space& home, const ValBranch<IntVar>& vb)
00126 : ValSel<IntView,int>(home,vb) {}
00127 forceinline
00128 ValSelRangeMin::ValSelRangeMin(Space& home, ValSelRangeMin& vs)
00129 : ValSel<IntView,int>(home,vs) {}
00130 forceinline int
00131 ValSelRangeMin::val(const Space&, IntView x, int) {
00132 if (x.range()) {
00133 return (x.width() == 2) ? x.min() : (x.min() + (x.max()-x.min())/2);
00134 } else {
00135 ViewRanges<View> r(x);
00136 return r.max();
00137 }
00138 }
00139
00140 forceinline
00141 ValSelRangeMax::ValSelRangeMax(Space& home, const ValBranch<IntVar>& vb)
00142 : ValSel<IntView,int>(home,vb) {}
00143 forceinline
00144 ValSelRangeMax::ValSelRangeMax(Space& home, ValSelRangeMax& vs)
00145 : ValSel<IntView,int>(home,vs) {}
00146 forceinline int
00147 ValSelRangeMax::val(const Space&, IntView x, int) {
00148 if (x.range()) {
00149 return (x.width() == 2) ? x.max() : (x.max() - (x.max()-x.min())/2);
00150 } else {
00151 int min;
00152 ViewRanges<IntView> r(x);
00153 do {
00154 min = r.min(); ++r;
00155 } while (r());
00156 return min;
00157 }
00158 }
00159
00160 }}}
00161
00162
00163