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
00039
00040
00041
00042 #include <gecode/int/branch.hh>
00043
00044 namespace Gecode { namespace Int { namespace Branch {
00045
00047 void
00048 virtualize(Gecode::Home home, IntVarBranch vars,
00049 const Gecode::VarBranchOptions& o_vars,
00050 Gecode::ViewSelVirtualBase<IntView>*& v) {
00051 switch (vars) {
00052 case INT_VAR_RND:
00053 v = new (home) ViewSelVirtual<ViewSelRnd<IntView> >(home,o_vars);
00054 break;
00055 case INT_VAR_MIN_MIN:
00056 v = new (home) ViewSelVirtual<ByMinMin>(home,o_vars);
00057 break;
00058 case INT_VAR_MIN_MAX:
00059 v = new (home) ViewSelVirtual<ByMinMax>(home,o_vars);
00060 break;
00061 case INT_VAR_MAX_MIN:
00062 v = new (home) ViewSelVirtual<ByMaxMin>(home,o_vars);
00063 break;
00064 case INT_VAR_MAX_MAX:
00065 v = new (home) ViewSelVirtual<ByMaxMax>(home,o_vars);
00066 break;
00067 case INT_VAR_SIZE_MIN:
00068 v = new (home) ViewSelVirtual<BySizeMin>(home,o_vars);
00069 break;
00070 case INT_VAR_SIZE_MAX:
00071 v = new (home) ViewSelVirtual<BySizeMax>(home,o_vars);
00072 break;
00073 case INT_VAR_DEGREE_MIN:
00074 v = new (home) ViewSelVirtual<ViewSelDegreeMin<IntView> >(home,o_vars);
00075 break;
00076 case INT_VAR_DEGREE_MAX:
00077 v = new (home) ViewSelVirtual<ViewSelDegreeMax<IntView> >(home,o_vars);
00078 break;
00079 case INT_VAR_AFC_MIN:
00080 v = new (home) ViewSelVirtual<ViewSelAfcMin<IntView> >(home,o_vars);
00081 break;
00082 case INT_VAR_AFC_MAX:
00083 v = new (home) ViewSelVirtual<ViewSelAfcMax<IntView> >(home,o_vars);
00084 break;
00085 case INT_VAR_SIZE_DEGREE_MIN:
00086 v = new (home) ViewSelVirtual<BySizeDegreeMin>(home,o_vars);
00087 break;
00088 case INT_VAR_SIZE_DEGREE_MAX:
00089 v = new (home) ViewSelVirtual<BySizeDegreeMax>(home,o_vars);
00090 break;
00091 case INT_VAR_SIZE_AFC_MIN:
00092 v = new (home) ViewSelVirtual<BySizeAfcMin>(home,o_vars);
00093 break;
00094 case INT_VAR_SIZE_AFC_MAX:
00095 v = new (home) ViewSelVirtual<BySizeAfcMax>(home,o_vars);
00096 break;
00097 case INT_VAR_REGRET_MIN_MIN:
00098 v = new (home) ViewSelVirtual<ByRegretMinMin>(home,o_vars);
00099 break;
00100 case INT_VAR_REGRET_MIN_MAX:
00101 v = new (home) ViewSelVirtual<ByRegretMinMax>(home,o_vars);
00102 break;
00103 case INT_VAR_REGRET_MAX_MIN:
00104 v = new (home) ViewSelVirtual<ByRegretMaxMin>(home,o_vars);
00105 break;
00106 case INT_VAR_REGRET_MAX_MAX:
00107 v = new (home) ViewSelVirtual<ByRegretMaxMax>(home,o_vars);
00108 break;
00109 default:
00110 throw UnknownBranching("Int::branch");
00111 }
00112 }
00113
00114 }}}
00115
00116 namespace Gecode {
00117
00118 void
00119 branch(Gecode::Home home, const IntVarArgs& x,
00120 IntVarBranch vars, IntValBranch vals,
00121 const Gecode::VarBranchOptions& o_vars,
00122 const Gecode::ValBranchOptions& o_vals) {
00123 using namespace Gecode;
00124 using namespace Gecode::Int;
00125 using namespace Gecode::Int::Branch;
00126
00127
00128 if (home.failed()) return;
00129 ViewArray<IntView> xv(home,x);
00130 switch (vars) {
00131 case INT_VAR_NONE:
00132 {
00133 ViewSelNone<IntView> v(home,o_vars);
00134 post(home,xv,v,vals,o_vals,o_vars.bf);
00135 }
00136 break;
00137 case INT_VAR_RND:
00138 {
00139 ViewSelRnd<IntView> v(home,o_vars);
00140 post(home,xv,v,vals,o_vals,o_vars.bf);
00141 }
00142 break;
00143 case INT_VAR_MIN_MIN:
00144 {
00145 ByMinMin v(home,o_vars);
00146 post(home,xv,v,vals,o_vals,o_vars.bf);
00147 }
00148 break;
00149 case INT_VAR_MIN_MAX:
00150 {
00151 ByMinMax v(home,o_vars);
00152 post(home,xv,v,vals,o_vals,o_vars.bf);
00153 }
00154 break;
00155 case INT_VAR_MAX_MIN:
00156 {
00157 ByMaxMin v(home,o_vars);
00158 post(home,xv,v,vals,o_vals,o_vars.bf);
00159 }
00160 break;
00161 case INT_VAR_MAX_MAX:
00162 {
00163 ByMaxMax v(home,o_vars);
00164 post(home,xv,v,vals,o_vals,o_vars.bf);
00165 }
00166 break;
00167 case INT_VAR_SIZE_MIN:
00168 {
00169 BySizeMin v(home,o_vars);
00170 post(home,xv,v,vals,o_vals,o_vars.bf);
00171 }
00172 break;
00173 case INT_VAR_SIZE_MAX:
00174 {
00175 BySizeMax v(home,o_vars);
00176 post(home,xv,v,vals,o_vals,o_vars.bf);
00177 }
00178 break;
00179 case INT_VAR_DEGREE_MIN:
00180 {
00181 ViewSelDegreeMin<IntView> v(home,o_vars);
00182 post(home,xv,v,vals,o_vals,o_vars.bf);
00183 }
00184 break;
00185 case INT_VAR_DEGREE_MAX:
00186 {
00187 ViewSelDegreeMax<IntView> v(home,o_vars);
00188 post(home,xv,v,vals,o_vals,o_vars.bf);
00189 }
00190 break;
00191 case INT_VAR_AFC_MIN:
00192 {
00193 ViewSelAfcMin<IntView> v(home,o_vars);
00194 post(home,xv,v,vals,o_vals,o_vars.bf);
00195 }
00196 break;
00197 case INT_VAR_AFC_MAX:
00198 {
00199 ViewSelAfcMax<IntView> v(home,o_vars);
00200 post(home,xv,v,vals,o_vals,o_vars.bf);
00201 }
00202 break;
00203 case INT_VAR_SIZE_DEGREE_MIN:
00204 {
00205 BySizeDegreeMin v(home,o_vars);
00206 post(home,xv,v,vals,o_vals,o_vars.bf);
00207 }
00208 break;
00209 case INT_VAR_SIZE_DEGREE_MAX:
00210 {
00211 BySizeDegreeMax v(home,o_vars);
00212 post(home,xv,v,vals,o_vals,o_vars.bf);
00213 }
00214 break;
00215 case INT_VAR_SIZE_AFC_MIN:
00216 {
00217 BySizeAfcMin v(home,o_vars);
00218 post(home,xv,v,vals,o_vals,o_vars.bf);
00219 }
00220 break;
00221 case INT_VAR_SIZE_AFC_MAX:
00222 {
00223 BySizeAfcMax v(home,o_vars);
00224 post(home,xv,v,vals,o_vals,o_vars.bf);
00225 }
00226 break;
00227 case INT_VAR_REGRET_MIN_MIN:
00228 {
00229 ByRegretMinMin v(home,o_vars);
00230 post(home,xv,v,vals,o_vals,o_vars.bf);
00231 }
00232 break;
00233 case INT_VAR_REGRET_MIN_MAX:
00234 {
00235 ByRegretMinMax v(home,o_vars);
00236 post(home,xv,v,vals,o_vals,o_vars.bf);
00237 }
00238 break;
00239 case INT_VAR_REGRET_MAX_MIN:
00240 {
00241 ByRegretMaxMin v(home,o_vars);
00242 post(home,xv,v,vals,o_vals,o_vars.bf);
00243 }
00244 break;
00245 case INT_VAR_REGRET_MAX_MAX:
00246 {
00247 ByRegretMaxMax v(home,o_vars);
00248 post(home,xv,v,vals,o_vals,o_vars.bf);
00249 }
00250 break;
00251 default:
00252 throw UnknownBranching("Int::branch");
00253 }
00254 }
00255
00256 void
00257 branch(Gecode::Home home, const IntVarArgs& x,
00258 const Gecode::TieBreakVarBranch<IntVarBranch>& vars,
00259 IntValBranch vals,
00260 const Gecode::TieBreakVarBranchOptions& o_vars,
00261 const Gecode::ValBranchOptions& o_vals) {
00262 using namespace Gecode;
00263 using namespace Gecode::Int;
00264 using namespace Gecode::Int::Branch;
00265
00266
00267 if (home.failed()) return;
00268 if ((vars.a == INT_VAR_NONE) || (vars.a == INT_VAR_RND) ||
00269 ((vars.b == INT_VAR_NONE) && (vars.c == INT_VAR_NONE) && (vars.d == INT_VAR_NONE))) {
00270 branch(home,x,vars.a,vals,o_vars.a,o_vals);
00271 return;
00272 }
00273 ViewArray<IntView> xv(home,x);
00274 Gecode::ViewSelVirtualBase<IntView>* tb[3];
00275 int n=0;
00276 if (vars.b != INT_VAR_NONE)
00277 virtualize(home,vars.b,o_vars.b,tb[n++]);
00278 if (vars.c != INT_VAR_NONE)
00279 virtualize(home,vars.c,o_vars.c,tb[n++]);
00280 if (vars.d != INT_VAR_NONE)
00281 virtualize(home,vars.d,o_vars.d,tb[n++]);
00282 assert(n > 0);
00283 ViewSelTieBreakDynamic<IntView> vbcd(home,tb,n);
00284 switch (vars.a) {
00285 case INT_VAR_MIN_MIN:
00286 {
00287 ByMinMin va(home,o_vars.a);
00288 ViewSelTieBreakStatic<ByMinMin,
00289 ViewSelTieBreakDynamic<IntView> > v(home,va,vbcd);
00290 post(home,xv,v,vals,o_vals,o_vars.a.bf);
00291 }
00292 break;
00293 case INT_VAR_MIN_MAX:
00294 {
00295 ByMinMax va(home,o_vars.a);
00296 ViewSelTieBreakStatic<ByMinMax,
00297 ViewSelTieBreakDynamic<IntView> > v(home,va,vbcd);
00298 post(home,xv,v,vals,o_vals,o_vars.a.bf);
00299 }
00300 break;
00301 case INT_VAR_MAX_MIN:
00302 {
00303 ByMaxMin va(home,o_vars.a);
00304 ViewSelTieBreakStatic<ByMaxMin,
00305 ViewSelTieBreakDynamic<IntView> > v(home,va,vbcd);
00306 post(home,xv,v,vals,o_vals,o_vars.a.bf);
00307 }
00308 break;
00309 case INT_VAR_MAX_MAX:
00310 {
00311 ByMaxMax va(home,o_vars.a);
00312 ViewSelTieBreakStatic<ByMaxMax,
00313 ViewSelTieBreakDynamic<IntView> > v(home,va,vbcd);
00314 post(home,xv,v,vals,o_vals,o_vars.a.bf);
00315 }
00316 break;
00317 case INT_VAR_SIZE_MIN:
00318 {
00319 BySizeMin va(home,o_vars.a);
00320 ViewSelTieBreakStatic<BySizeMin,
00321 ViewSelTieBreakDynamic<IntView> > v(home,va,vbcd);
00322 post(home,xv,v,vals,o_vals,o_vars.a.bf);
00323 }
00324 break;
00325 case INT_VAR_SIZE_MAX:
00326 {
00327 BySizeMax va(home,o_vars.a);
00328 ViewSelTieBreakStatic<BySizeMax,
00329 ViewSelTieBreakDynamic<IntView> > v(home,va,vbcd);
00330 post(home,xv,v,vals,o_vals,o_vars.a.bf);
00331 }
00332 break;
00333 case INT_VAR_DEGREE_MIN:
00334 {
00335 ViewSelDegreeMin<IntView> va(home,o_vars.a);
00336 ViewSelTieBreakStatic<ViewSelDegreeMin<IntView>,
00337 ViewSelTieBreakDynamic<IntView> > v(home,va,vbcd);
00338 post(home,xv,v,vals,o_vals,o_vars.a.bf);
00339 }
00340 break;
00341 case INT_VAR_DEGREE_MAX:
00342 {
00343 ViewSelDegreeMax<IntView> va(home,o_vars.a);
00344 ViewSelTieBreakStatic<ViewSelDegreeMax<IntView>,
00345 ViewSelTieBreakDynamic<IntView> > v(home,va,vbcd);
00346 post(home,xv,v,vals,o_vals,o_vars.a.bf);
00347 }
00348 break;
00349 case INT_VAR_AFC_MIN:
00350 {
00351 ViewSelAfcMin<IntView> va(home,o_vars.a);
00352 ViewSelTieBreakStatic<ViewSelAfcMin<IntView>,
00353 ViewSelTieBreakDynamic<IntView> > v(home,va,vbcd);
00354 post(home,xv,v,vals,o_vals,o_vars.a.bf);
00355 }
00356 break;
00357 case INT_VAR_AFC_MAX:
00358 {
00359 ViewSelAfcMax<IntView> va(home,o_vars.a);
00360 ViewSelTieBreakStatic<ViewSelAfcMax<IntView>,
00361 ViewSelTieBreakDynamic<IntView> > v(home,va,vbcd);
00362 post(home,xv,v,vals,o_vals,o_vars.a.bf);
00363 }
00364 break;
00365 case INT_VAR_SIZE_DEGREE_MIN:
00366 {
00367 BySizeDegreeMin va(home,o_vars.a);
00368 ViewSelTieBreakStatic<BySizeDegreeMin,
00369 ViewSelTieBreakDynamic<IntView> > v(home,va,vbcd);
00370 post(home,xv,v,vals,o_vals,o_vars.a.bf);
00371 }
00372 break;
00373 case INT_VAR_SIZE_DEGREE_MAX:
00374 {
00375 BySizeDegreeMax va(home,o_vars.a);
00376 ViewSelTieBreakStatic<BySizeDegreeMax,
00377 ViewSelTieBreakDynamic<IntView> > v(home,va,vbcd);
00378 post(home,xv,v,vals,o_vals,o_vars.a.bf);
00379 }
00380 break;
00381 case INT_VAR_SIZE_AFC_MIN:
00382 {
00383 BySizeAfcMin va(home,o_vars.a);
00384 ViewSelTieBreakStatic<BySizeAfcMin,
00385 ViewSelTieBreakDynamic<IntView> > v(home,va,vbcd);
00386 post(home,xv,v,vals,o_vals,o_vars.a.bf);
00387 }
00388 break;
00389 case INT_VAR_SIZE_AFC_MAX:
00390 {
00391 BySizeAfcMax va(home,o_vars.a);
00392 ViewSelTieBreakStatic<BySizeAfcMax,
00393 ViewSelTieBreakDynamic<IntView> > v(home,va,vbcd);
00394 post(home,xv,v,vals,o_vals,o_vars.a.bf);
00395 }
00396 break;
00397 case INT_VAR_REGRET_MIN_MIN:
00398 {
00399 ByRegretMinMin va(home,o_vars.a);
00400 ViewSelTieBreakStatic<ByRegretMinMin,
00401 ViewSelTieBreakDynamic<IntView> > v(home,va,vbcd);
00402 post(home,xv,v,vals,o_vals,o_vars.a.bf);
00403 }
00404 break;
00405 case INT_VAR_REGRET_MIN_MAX:
00406 {
00407 ByRegretMinMax va(home,o_vars.a);
00408 ViewSelTieBreakStatic<ByRegretMinMax,
00409 ViewSelTieBreakDynamic<IntView> > v(home,va,vbcd);
00410 post(home,xv,v,vals,o_vals,o_vars.a.bf);
00411 }
00412 break;
00413 case INT_VAR_REGRET_MAX_MIN:
00414 {
00415 ByRegretMaxMin va(home,o_vars.a);
00416 ViewSelTieBreakStatic<ByRegretMaxMin,
00417 ViewSelTieBreakDynamic<IntView> > v(home,va,vbcd);
00418 post(home,xv,v,vals,o_vals,o_vars.a.bf);
00419 }
00420 break;
00421 case INT_VAR_REGRET_MAX_MAX:
00422 {
00423 ByRegretMaxMax va(home,o_vars.a);
00424 ViewSelTieBreakStatic<ByRegretMaxMax,
00425 ViewSelTieBreakDynamic<IntView> > v(home,va,vbcd);
00426 post(home,xv,v,vals,o_vals,o_vars.a.bf);
00427 }
00428 break;
00429 default:
00430 throw UnknownBranching("Int::branch");
00431 }
00432 }
00433
00434 }
00435
00436
00437
00438