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 #include <gecode/int/branch.hh>
00035
00036 namespace Gecode {
00037
00038 void
00039 branch(Home home, const IntVarArgs& x,
00040 IntVarBranch vars, IntValBranch vals,
00041 IntBranchFilter bf,
00042 IntVarValPrint vvp) {
00043 using namespace Int;
00044 if (home.failed()) return;
00045 vars.expand(home,x);
00046 ViewArray<IntView> xv(home,x);
00047 ViewSel<IntView>* vs[1] = {
00048 Branch::viewsel(home,vars)
00049 };
00050 switch (vals.select()) {
00051 case IntValBranch::SEL_VALUES_MIN:
00052 Branch::postviewvaluesbrancher<1,true>(home,xv,vs,bf,vvp);
00053 break;
00054 case IntValBranch::SEL_VALUES_MAX:
00055 Branch::postviewvaluesbrancher<1,false>(home,xv,vs,bf,vvp);
00056 break;
00057 default:
00058 postviewvalbrancher<IntView,1,int,2>
00059 (home,xv,vs,Branch::valselcommit(home,vals),bf,vvp);
00060 break;
00061 }
00062 }
00063
00064 void
00065 branch(Home home, const IntVarArgs& x,
00066 TieBreak<IntVarBranch> vars, IntValBranch vals,
00067 IntBranchFilter bf,
00068 IntVarValPrint vvp) {
00069 using namespace Int;
00070 if (home.failed()) return;
00071 vars.a.expand(home,x);
00072 if ((vars.a.select() == IntVarBranch::SEL_NONE) ||
00073 (vars.a.select() == IntVarBranch::SEL_RND))
00074 vars.b = INT_VAR_NONE();
00075 vars.b.expand(home,x);
00076 if ((vars.b.select() == IntVarBranch::SEL_NONE) ||
00077 (vars.b.select() == IntVarBranch::SEL_RND))
00078 vars.c = INT_VAR_NONE();
00079 vars.c.expand(home,x);
00080 if ((vars.c.select() == IntVarBranch::SEL_NONE) ||
00081 (vars.c.select() == IntVarBranch::SEL_RND))
00082 vars.d = INT_VAR_NONE();
00083 vars.d.expand(home,x);
00084 if (vars.b.select() == IntVarBranch::SEL_NONE) {
00085 branch(home,x,vars.a,vals,bf,vvp);
00086 } else {
00087 ViewArray<IntView> xv(home,x);
00088 if (vars.c.select() == IntVarBranch::SEL_NONE) {
00089 ViewSel<IntView>* vs[2] = {
00090 Branch::viewsel(home,vars.a),Branch::viewsel(home,vars.b)
00091 };
00092 switch (vals.select()) {
00093 case IntValBranch::SEL_VALUES_MIN:
00094 Branch::postviewvaluesbrancher<2,true>(home,xv,vs,bf,vvp);
00095 break;
00096 case IntValBranch::SEL_VALUES_MAX:
00097 Branch::postviewvaluesbrancher<2,false>(home,xv,vs,bf,vvp);
00098 break;
00099 default:
00100 postviewvalbrancher<IntView,2,int,2>
00101 (home,xv,vs,Branch::valselcommit(home,vals),bf,vvp);
00102 }
00103 } else if (vars.d.select() == IntVarBranch::SEL_NONE) {
00104 ViewSel<IntView>* vs[3] = {
00105 Branch::viewsel(home,vars.a),Branch::viewsel(home,vars.b),
00106 Branch::viewsel(home,vars.c)
00107 };
00108 switch (vals.select()) {
00109 case IntValBranch::SEL_VALUES_MIN:
00110 Branch::postviewvaluesbrancher<3,true>(home,xv,vs,bf,vvp);
00111 break;
00112 case IntValBranch::SEL_VALUES_MAX:
00113 Branch::postviewvaluesbrancher<3,false>(home,xv,vs,bf,vvp);
00114 break;
00115 default:
00116 postviewvalbrancher<IntView,3,int,2>
00117 (home,xv,vs,Branch::valselcommit(home,vals),bf,vvp);
00118 }
00119 } else {
00120 ViewSel<IntView>* vs[4] = {
00121 Branch::viewsel(home,vars.a),Branch::viewsel(home,vars.b),
00122 Branch::viewsel(home,vars.c),Branch::viewsel(home,vars.d)
00123 };
00124 switch (vals.select()) {
00125 case IntValBranch::SEL_VALUES_MIN:
00126 Branch::postviewvaluesbrancher<4,true>(home,xv,vs,bf,vvp);
00127 break;
00128 case IntValBranch::SEL_VALUES_MAX:
00129 Branch::postviewvaluesbrancher<4,false>(home,xv,vs,bf,vvp);
00130 break;
00131 default:
00132 postviewvalbrancher<IntView,4,int,2>
00133 (home,xv,vs,Branch::valselcommit(home,vals),bf,vvp);
00134 }
00135 }
00136 }
00137 }
00138
00139 void
00140 branch(Home home, IntVar x, IntValBranch vals, IntVarValPrint vvp) {
00141 IntVarArgs xv(1); xv[0]=x;
00142 branch(home, xv, INT_VAR_NONE(), vals, nullptr, vvp);
00143 }
00144
00145 void
00146 assign(Home home, const IntVarArgs& x, IntAssign ia,
00147 IntBranchFilter bf,
00148 IntVarValPrint vvp) {
00149 using namespace Int;
00150 if (home.failed()) return;
00151 ViewArray<IntView> xv(home,x);
00152 ViewSel<IntView>* vs[1] = {
00153 new (home) ViewSelNone<IntView>(home,INT_VAR_NONE())
00154 };
00155 postviewvalbrancher<IntView,1,int,1>
00156 (home,xv,vs,Branch::valselcommit(home,ia),bf,vvp);
00157 }
00158
00159 void
00160 assign(Home home, IntVar x, IntAssign ia, IntVarValPrint vvp) {
00161 IntVarArgs xv(1); xv[0]=x;
00162 assign(home, xv, ia, nullptr, vvp);
00163 }
00164
00165
00166 void
00167 branch(Home home, const BoolVarArgs& x,
00168 BoolVarBranch vars, BoolValBranch vals,
00169 BoolBranchFilter bf,
00170 BoolVarValPrint vvp) {
00171 using namespace Int;
00172 if (home.failed()) return;
00173 vars.expand(home,x);
00174 ViewArray<BoolView> xv(home,x);
00175 ViewSel<BoolView>* vs[1] = {
00176 Branch::viewsel(home,vars)
00177 };
00178 postviewvalbrancher<BoolView,1,int,2>
00179 (home,xv,vs,Branch::valselcommit(home,vals),bf,vvp);
00180 }
00181
00182 void
00183 branch(Home home, const BoolVarArgs& x,
00184 TieBreak<BoolVarBranch> vars, BoolValBranch vals,
00185 BoolBranchFilter bf,
00186 BoolVarValPrint vvp) {
00187 using namespace Int;
00188 if (home.failed()) return;
00189 vars.a.expand(home,x);
00190 if ((vars.a.select() == BoolVarBranch::SEL_NONE) ||
00191 (vars.a.select() == BoolVarBranch::SEL_RND))
00192 vars.b = BOOL_VAR_NONE();
00193 vars.b.expand(home,x);
00194 if ((vars.b.select() == BoolVarBranch::SEL_NONE) ||
00195 (vars.b.select() == BoolVarBranch::SEL_RND))
00196 vars.c = BOOL_VAR_NONE();
00197 vars.c.expand(home,x);
00198 if ((vars.c.select() == BoolVarBranch::SEL_NONE) ||
00199 (vars.c.select() == BoolVarBranch::SEL_RND))
00200 vars.d = BOOL_VAR_NONE();
00201 vars.d.expand(home,x);
00202 if (vars.b.select() == BoolVarBranch::SEL_NONE) {
00203 branch(home,x,vars.a,vals,bf,vvp);
00204 } else {
00205 ViewArray<BoolView> xv(home,x);
00206 ValSelCommitBase<BoolView,int>*
00207 vsc = Branch::valselcommit(home,vals);
00208 if (vars.c.select() == BoolVarBranch::SEL_NONE) {
00209 ViewSel<BoolView>* vs[2] = {
00210 Branch::viewsel(home,vars.a),Branch::viewsel(home,vars.b)
00211 };
00212 postviewvalbrancher<BoolView,2,int,2>(home,xv,vs,vsc,bf,vvp);
00213 } else if (vars.d.select() == BoolVarBranch::SEL_NONE) {
00214 ViewSel<BoolView>* vs[3] = {
00215 Branch::viewsel(home,vars.a),Branch::viewsel(home,vars.b),
00216 Branch::viewsel(home,vars.c)
00217 };
00218 postviewvalbrancher<BoolView,3,int,2>(home,xv,vs,vsc,bf,vvp);
00219 } else {
00220 ViewSel<BoolView>* vs[4] = {
00221 Branch::viewsel(home,vars.a),Branch::viewsel(home,vars.b),
00222 Branch::viewsel(home,vars.c),Branch::viewsel(home,vars.d)
00223 };
00224 postviewvalbrancher<BoolView,4,int,2>(home,xv,vs,vsc,bf,vvp);
00225 }
00226 }
00227 }
00228
00229 void
00230 branch(Home home, BoolVar x, BoolValBranch vals, BoolVarValPrint vvp) {
00231 BoolVarArgs xv(1); xv[0]=x;
00232 branch(home, xv, BOOL_VAR_NONE(), vals, nullptr, vvp);
00233 }
00234
00235 void
00236 assign(Home home, const BoolVarArgs& x, BoolAssign ba,
00237 BoolBranchFilter bf,
00238 BoolVarValPrint vvp) {
00239 using namespace Int;
00240 if (home.failed()) return;
00241 ViewArray<BoolView> xv(home,x);
00242 ViewSel<BoolView>* vs[1] = {
00243 new (home) ViewSelNone<BoolView>(home,BOOL_VAR_NONE())
00244 };
00245 postviewvalbrancher<BoolView,1,int,1>
00246 (home,xv,vs,Branch::valselcommit(home,ba),bf,vvp);
00247 }
00248
00249 void
00250 assign(Home home, BoolVar x, BoolAssign ba, BoolVarValPrint vvp) {
00251 BoolVarArgs xv(1); xv[0]=x;
00252 assign(home, xv, ba, nullptr, vvp);
00253 }
00254
00255 #ifdef GECODE_HAS_CBS
00256
00257 void
00258 cbsbranch(Home home, const IntVarArgs& x) {
00259 using namespace Int;
00260 if (home.failed()) return;
00261 ViewArray<IntView> y(home,x);
00262 Branch::CBSBrancher<IntView>::post(home,y);
00263 }
00264
00265 void
00266 cbsbranch(Home home, const BoolVarArgs& x) {
00267 using namespace Int;
00268 if (home.failed()) return;
00269 ViewArray<BoolView> y(home,x);
00270 Branch::CBSBrancher<BoolView>::post(home,y);
00271 }
00272
00273 #endif
00274
00275 }
00276
00277