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 { namespace Int { namespace Branch {
00039
00040 template<class View>
00041 forceinline int
00042 ValMin<View>::val(const Space*, View x) const {
00043 return x.min();
00044 }
00045 template<class View>
00046 forceinline ModEvent
00047 ValMin<View>::tell(Space* home, unsigned int a, View x, int n) {
00048 return (a == 0) ? x.eq(home,n) : x.gr(home,n);
00049 }
00050 template<class View>
00051 inline Support::Symbol
00052 ValMin<View>::type(void) {
00053 return Support::Symbol("Gecode::Int::Branch::ValMin");
00054 }
00055 template <class View>
00056 forceinline void
00057 ValMin<View>::branchingSpec(const Space* home,
00058 Reflection::VarMap& m,
00059 Reflection::BranchingSpec& bs,
00060 int alt, View x, int n) const {
00061 assert(alt <= 2);
00062 Reflection::ArrayArg* a0 = Reflection::Arg::newArray(2);
00063 std::stringstream s;
00064 s << n;
00065 (*a0)[0] = x.spec(home, m);
00066 (*a0)[1] = Reflection::Arg::newString((std::string("=")+s.str()).c_str());
00067 bs[0] = a0;
00068 if (alt == 2) {
00069 Reflection::ArrayArg* a1 = Reflection::Arg::newArray(2);
00070 (*a1)[0] = x.spec(home, m);
00071 (*a1)[1] =
00072 Reflection::Arg::newString((std::string(">")+s.str()).c_str());
00073 bs[1] = a1;
00074 }
00075 }
00076
00077 template<class View>
00078 forceinline int
00079 ValMed<View>::val(const Space*, View x) const {
00080 return x.med();
00081 }
00082 template<class View>
00083 forceinline ModEvent
00084 ValMed<View>::tell(Space* home, unsigned int a, View x, int n) {
00085 return (a == 0) ? x.eq(home,n) : x.nq(home,n);
00086 }
00087 template<class View>
00088 inline Support::Symbol
00089 ValMed<View>::type(void) {
00090 return Support::Symbol("Gecode::Int::Branch::ValMed");
00091 }
00092 template <class View>
00093 forceinline void
00094 ValMed<View>::branchingSpec(const Space* home,
00095 Reflection::VarMap& m,
00096 Reflection::BranchingSpec& bs,
00097 int alt, View x, int n) const {
00098 assert(alt <= 2);
00099 Reflection::ArrayArg* a0 = Reflection::Arg::newArray(2);
00100 std::stringstream s;
00101 s << n;
00102 (*a0)[0] = x.spec(home, m);
00103 (*a0)[1] = Reflection::Arg::newString((std::string("=")+s.str()).c_str());
00104 bs[0] = a0;
00105 if (alt == 2) {
00106 Reflection::ArrayArg* a1 = Reflection::Arg::newArray(2);
00107 (*a1)[0] = x.spec(home, m);
00108 (*a1)[1] =
00109 Reflection::Arg::newString((std::string("!=")+s.str()).c_str());
00110 bs[1] = a1;
00111 }
00112 }
00113
00114
00115 template<class View>
00116 forceinline int
00117 ValMax<View>::val(const Space*, View x) const {
00118 return x.max();
00119 }
00120 template<class View>
00121 forceinline ModEvent
00122 ValMax<View>::tell(Space* home, unsigned int a, View x, int n) {
00123 return (a == 0) ? x.eq(home,n) : x.le(home,n);
00124 }
00125 template<class View>
00126 inline Support::Symbol
00127 ValMax<View>::type(void) {
00128 return Support::Symbol("Gecode::Int::Branch::ValMax");
00129 }
00130 template <class View>
00131 forceinline void
00132 ValMax<View>::branchingSpec(const Space* home,
00133 Reflection::VarMap& m,
00134 Reflection::BranchingSpec& bs,
00135 int alt, View x, int n) const {
00136 assert(alt <= 2);
00137 Reflection::ArrayArg* a0 = Reflection::Arg::newArray(2);
00138 std::stringstream s;
00139 s << n;
00140 (*a0)[0] = x.spec(home, m);
00141 (*a0)[1] = Reflection::Arg::newString((std::string("=")+s.str()).c_str());
00142 bs[0] = a0;
00143 if (alt == 2) {
00144 Reflection::ArrayArg* a1 = Reflection::Arg::newArray(2);
00145 (*a1)[0] = x.spec(home, m);
00146 (*a1)[1] =
00147 Reflection::Arg::newString((std::string("<")+s.str()).c_str());
00148 bs[1] = a1;
00149 }
00150 }
00151
00152
00153 template<class View>
00154 forceinline int
00155 ValSplitMin<View>::val(const Space*, View x) const {
00156 return (x.width() == 2) ? x.min() : ((x.min()+x.max()) / 2);
00157 }
00158 template<class View>
00159 forceinline ModEvent
00160 ValSplitMin<View>::tell(Space* home, unsigned int a, View x, int n) {
00161 return (a == 0) ? x.lq(home,n) : x.gr(home,n);
00162 }
00163 template<class View>
00164 inline Support::Symbol
00165 ValSplitMin<View>::type(void) {
00166 return Support::Symbol("Gecode::Int::Branch::ValSplitMin");
00167 }
00168 template <class View>
00169 forceinline void
00170 ValSplitMin<View>::branchingSpec(const Space* home,
00171 Reflection::VarMap& m,
00172 Reflection::BranchingSpec& bs,
00173 int alt, View x, int n) const {
00174 assert(alt <= 2);
00175 Reflection::ArrayArg* a0 = Reflection::Arg::newArray(2);
00176 std::stringstream s;
00177 s << n;
00178 (*a0)[0] = x.spec(home, m);
00179 (*a0)[1] = Reflection::Arg::newString((std::string("=")+s.str()).c_str());
00180 bs[0] = a0;
00181 if (alt == 2) {
00182 Reflection::ArrayArg* a1 = Reflection::Arg::newArray(2);
00183 (*a1)[0] = x.spec(home, m);
00184 (*a1)[1] =
00185 Reflection::Arg::newString((std::string(">")+s.str()).c_str());
00186 bs[1] = a1;
00187 }
00188 }
00189
00190
00191 template<class View>
00192 forceinline int
00193 ValSplitMax<View>::val(const Space*, View x) const {
00194 return (x.width() == 2) ? x.min() : ((x.min()+x.max()) / 2);
00195 }
00196 template<class View>
00197 forceinline ModEvent
00198 ValSplitMax<View>::tell(Space* home, unsigned int a, View x, int n) {
00199 return (a == 0) ? x.gr(home,n) : x.lq(home,n);
00200 }
00201 template<class View>
00202 inline Support::Symbol
00203 ValSplitMax<View>::type(void) {
00204 return Support::Symbol("Gecode::Int::Branch::ValSplitMax");
00205 }
00206 template <class View>
00207 forceinline void
00208 ValSplitMax<View>::branchingSpec(const Space* home,
00209 Reflection::VarMap& m,
00210 Reflection::BranchingSpec& bs,
00211 int alt, View x, int n) const {
00212 assert(alt <= 2);
00213 Reflection::ArrayArg* a0 = Reflection::Arg::newArray(2);
00214 std::stringstream s;
00215 s << n;
00216 (*a0)[0] = x.spec(home, m);
00217 (*a0)[1] = Reflection::Arg::newString((std::string(">")+s.str()).c_str());
00218 bs[0] = a0;
00219 if (alt == 2) {
00220 Reflection::ArrayArg* a1 = Reflection::Arg::newArray(2);
00221 (*a1)[0] = x.spec(home, m);
00222 (*a1)[1] =
00223 Reflection::Arg::newString((std::string("<=")+s.str()).c_str());
00224 bs[1] = a1;
00225 }
00226 }
00227
00228
00229 template<class View, template <class> class SelView>
00230 void
00231 create(Space* home, ViewArray<View>& x, IntValBranch vals) {
00232 switch (vals) {
00233 case INT_VAL_MIN:
00234 (void) new (home)
00235 ViewValBranching<View,int,SelView<View>,ValMin<View> >(home,x);
00236 break;
00237 case INT_VAL_MED:
00238 (void) new (home)
00239 ViewValBranching<View,int,SelView<View>,ValMed<View> >(home,x);
00240 break;
00241 case INT_VAL_MAX:
00242 (void) new (home)
00243 ViewValBranching<View,int,SelView<View>,ValMax<View> >(home,x);
00244 break;
00245 case INT_VAL_SPLIT_MIN:
00246 (void) new (home)
00247 ViewValBranching<View,int,SelView<View>,ValSplitMin<View> >(home,x);
00248 break;
00249 case INT_VAL_SPLIT_MAX:
00250 (void) new (home)
00251 ViewValBranching<View,int,SelView<View>,ValSplitMax<View> >(home,x);
00252 break;
00253 default:
00254 throw UnknownBranching("Int::branch");
00255 }
00256 }
00257
00258 inline Support::Symbol
00259 NoValue::type(void) {
00260 return Support::Symbol("Gecode::Int::Branch::NoValue");
00261 }
00262
00263 template<class View>
00264 forceinline NoValue
00265 ValZeroOne<View>::val(const Space*, View) const {
00266 NoValue n; return n;
00267 }
00268 template<class View>
00269 forceinline ModEvent
00270 ValZeroOne<View>::tell(Space* home, unsigned int a, View x, NoValue) {
00271 return (a == 0) ? x.zero(home) : x.one(home);
00272 }
00273 template<class View>
00274 inline Support::Symbol
00275 ValZeroOne<View>::type(void) {
00276 return Support::Symbol("Gecode::Int::Branch::ValZeroOne");
00277 }
00278 template <class View>
00279 forceinline void
00280 ValZeroOne<View>::branchingSpec(const Space* home,
00281 Reflection::VarMap& m,
00282 Reflection::BranchingSpec& bs,
00283 int alt, View x, NoValue) const {
00284 assert(alt <= 2);
00285 Reflection::ArrayArg* a0 = Reflection::Arg::newArray(2);
00286 (*a0)[0] = x.spec(home, m);
00287 (*a0)[1] = Reflection::Arg::newString("= 0");
00288 bs[0] = a0;
00289 if (alt == 2) {
00290 Reflection::ArrayArg* a1 = Reflection::Arg::newArray(2);
00291 (*a1)[0] = x.spec(home, m);
00292 (*a1)[1] = Reflection::Arg::newString("= 1");
00293 bs[1] = a1;
00294 }
00295 }
00296
00297
00298
00299 template<class View>
00300 forceinline NoValue
00301 ValOneZero<View>::val(const Space*, View) const {
00302 NoValue n; return n;
00303 }
00304 template<class View>
00305 forceinline ModEvent
00306 ValOneZero<View>::tell(Space* home, unsigned int a, View x, NoValue) {
00307 return (a == 0) ? x.one(home) : x.zero(home);
00308 }
00309 template<class View>
00310 inline Support::Symbol
00311 ValOneZero<View>::type(void) {
00312 return Support::Symbol("Gecode::Int::Branch::ValOneZero");
00313 }
00314 template <class View>
00315 forceinline void
00316 ValOneZero<View>::branchingSpec(const Space* home,
00317 Reflection::VarMap& m,
00318 Reflection::BranchingSpec& bs,
00319 int alt, View x, NoValue) const {
00320 assert(alt <= 2);
00321 Reflection::ArrayArg* a0 = Reflection::Arg::newArray(2);
00322 (*a0)[0] = x.spec(home, m);
00323 (*a0)[1] = Reflection::Arg::newString("= 1");
00324 bs[0] = a0;
00325 if (alt == 2) {
00326 Reflection::ArrayArg* a1 = Reflection::Arg::newArray(2);
00327 (*a1)[0] = x.spec(home, m);
00328 (*a1)[1] = Reflection::Arg::newString("= 0");
00329 bs[1] = a1;
00330 }
00331 }
00332
00333
00334 }}}
00335
00336
00337
00338