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 #include <gecode/flatzinc/branch.hh>
00036
00037 namespace Gecode { namespace FlatZinc {
00038
00039 void
00040 PosIntChoice::archive(Archive& e) const {
00041 Choice::archive(e);
00042 e << _pos;
00043 e << _val;
00044 }
00045
00046
00047 bool
00048 IntBoolBrancherBase::status(const Space&) const {
00049 if (start < x.size()) {
00050 for (int i=start; i < x.size(); i++)
00051 if (!x[i].assigned()) {
00052 start = i;
00053 return true;
00054 }
00055 start = x.size();
00056 }
00057 for (int i=start-x.size(); i < y.size(); i++)
00058 if (!y[i].assigned()) {
00059 start = x.size() + i;
00060 return true;
00061 }
00062 return false;
00063 }
00064
00065 ExecStatus
00066 IntBoolBrancherBase::commit(Space& home, const Choice& _c,
00067 unsigned int b) {
00068 const PosIntChoice& c
00069 = static_cast<const PosIntChoice&>(_c);
00070 int p=c.pos(); int n=c.val();
00071 if (p < x.size()) {
00072 return me_failed(xvsc->commit(home,b,x[p],p,n)) ?
00073 ES_FAILED : ES_OK;
00074 } else {
00075 p -= x.size();
00076 return me_failed(yvsc->commit(home,b,y[p],p,n)) ?
00077 ES_FAILED : ES_OK;
00078 }
00079 }
00080
00081 NGL*
00082 IntBoolBrancherBase::ngl(Space& home, const Choice& _c,
00083 unsigned int b) const {
00084 const PosIntChoice& c
00085 = static_cast<const PosIntChoice&>(_c);
00086 int p=c.pos(); int n=c.val();
00087 if (p < x.size()) {
00088 return xvsc->ngl(home,b,x[p],n);
00089 } else {
00090 p -= x.size();
00091 return yvsc->ngl(home,b,y[p],n);
00092 }
00093 }
00094
00095 void
00096 IntBoolBrancherBase::print(const Space& home, const Choice& _c,
00097 unsigned int b,
00098 std::ostream& o) const {
00099 const PosIntChoice& c
00100 = static_cast<const PosIntChoice&>(_c);
00101 int p=c.pos(); int n=c.val();
00102 if (p < x.size()) {
00103 xvsc->print(home,b,x[p],p,n,o);
00104 } else {
00105 p -= x.size();
00106 yvsc->print(home,b,y[p],p,n,o);
00107 }
00108 }
00109
00110 const Choice*
00111 IntBoolBrancherBase::choice(const Space& home, Archive& e) {
00112 (void) home;
00113 int p; e >> p;
00114 int v; e >> v;
00115 return new PosIntChoice(*this,2,p,v);
00116 }
00117
00118
00119 void
00120 branch(Home home, const IntVarArgs& x, const BoolVarArgs& y,
00121 IntBoolVarBranch vars, IntValBranch vals) {
00122 if (home.failed()) return;
00123 vars.expand(home,x,y);
00124 ViewArray<Int::IntView> xv(home,x);
00125 ViewArray<Int::BoolView> yv(home,y);
00126 ValSelCommitBase<Int::IntView,int>* xvsc =
00127 Int::Branch::valselcommit(home,vals);
00128 ValSelCommitBase<Int::BoolView,int>* yvsc =
00129 Int::Branch::valselcommit(home,i2b(vals));
00130 switch (vars.select()) {
00131 case IntBoolVarBranch::SEL_AFC_MAX:
00132 {
00133 MeritMaxAFC m(home,vars);
00134 IntBoolBrancher<MeritMaxAFC>::post(home,xv,yv,m,xvsc,yvsc);
00135 }
00136 break;
00137 case IntBoolVarBranch::SEL_ACTION_MAX:
00138 {
00139 MeritMaxAction m(home,vars);
00140 IntBoolBrancher<MeritMaxAction>::post(home,xv,yv,m,xvsc,yvsc);
00141 }
00142 break;
00143 case IntBoolVarBranch::SEL_CHB_MAX:
00144 {
00145 MeritMaxCHB m(home,vars);
00146 IntBoolBrancher<MeritMaxCHB>::post(home,xv,yv,m,xvsc,yvsc);
00147 }
00148 break;
00149 case IntBoolVarBranch::SEL_AFC_SIZE_MAX:
00150 {
00151 MeritMaxAFCSize m(home,vars);
00152 IntBoolBrancher<MeritMaxAFCSize>::post(home,xv,yv,m,xvsc,yvsc);
00153 }
00154 break;
00155 case IntBoolVarBranch::SEL_ACTION_SIZE_MAX:
00156 {
00157 MeritMaxActionSize m(home,vars);
00158 IntBoolBrancher<MeritMaxActionSize>::post(home,xv,yv,m,xvsc,yvsc);
00159 }
00160 break;
00161 case IntBoolVarBranch::SEL_CHB_SIZE_MAX:
00162 {
00163 MeritMaxCHBSize m(home,vars);
00164 IntBoolBrancher<MeritMaxCHBSize>::post(home,xv,yv,m,xvsc,yvsc);
00165 }
00166 break;
00167 default:
00168 GECODE_NEVER;
00169 }
00170 }
00171
00172 }}
00173
00174
00175