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/set/branch.hh>
00035
00036 namespace Gecode {
00037
00038 void
00039 branch(Home home, const SetVarArgs& x,
00040 SetVarBranch vars, SetValBranch vals,
00041 SetBranchFilter bf,
00042 SetVarValPrint vvp) {
00043 using namespace Set;
00044 if (home.failed()) return;
00045 vars.expand(home,x);
00046 ViewArray<SetView> xv(home,x);
00047 ViewSel<SetView>* vs[1] = {
00048 Branch::viewsel(home,vars)
00049 };
00050 postviewvalbrancher<SetView,1,int,2>
00051 (home,xv,vs,Branch::valselcommit(home,vals),bf,vvp);
00052 }
00053
00054 void
00055 branch(Home home, const SetVarArgs& x,
00056 TieBreak<SetVarBranch> vars, SetValBranch vals,
00057 SetBranchFilter bf,
00058 SetVarValPrint vvp) {
00059 using namespace Set;
00060 if (home.failed()) return;
00061 vars.a.expand(home,x);
00062 if ((vars.a.select() == SetVarBranch::SEL_NONE) ||
00063 (vars.a.select() == SetVarBranch::SEL_RND))
00064 vars.b = SET_VAR_NONE();
00065 vars.b.expand(home,x);
00066 if ((vars.b.select() == SetVarBranch::SEL_NONE) ||
00067 (vars.b.select() == SetVarBranch::SEL_RND))
00068 vars.c = SET_VAR_NONE();
00069 vars.c.expand(home,x);
00070 if ((vars.c.select() == SetVarBranch::SEL_NONE) ||
00071 (vars.c.select() == SetVarBranch::SEL_RND))
00072 vars.d = SET_VAR_NONE();
00073 vars.d.expand(home,x);
00074 if (vars.b.select() == SetVarBranch::SEL_NONE) {
00075 branch(home,x,vars.a,vals,bf,vvp);
00076 } else {
00077 ViewArray<SetView> xv(home,x);
00078 ValSelCommitBase<SetView,int>* vsc = Branch::valselcommit(home,vals);
00079 if (vars.c.select() == SetVarBranch::SEL_NONE) {
00080 ViewSel<SetView>* vs[2] = {
00081 Branch::viewsel(home,vars.a),Branch::viewsel(home,vars.b)
00082 };
00083 postviewvalbrancher<SetView,2,int,2>(home,xv,vs,vsc,bf,vvp);
00084 } else if (vars.d.select() == SetVarBranch::SEL_NONE) {
00085 ViewSel<SetView>* vs[3] = {
00086 Branch::viewsel(home,vars.a),Branch::viewsel(home,vars.b),
00087 Branch::viewsel(home,vars.c)
00088 };
00089 postviewvalbrancher<SetView,3,int,2>(home,xv,vs,vsc,bf,vvp);
00090 } else {
00091 ViewSel<SetView>* vs[4] = {
00092 Branch::viewsel(home,vars.a),Branch::viewsel(home,vars.b),
00093 Branch::viewsel(home,vars.c),Branch::viewsel(home,vars.d)
00094 };
00095 postviewvalbrancher<SetView,4,int,2>(home,xv,vs,vsc,bf,vvp);
00096 }
00097 }
00098 }
00099
00100 void
00101 branch(Home home, SetVar x, SetValBranch vals, SetVarValPrint vvp) {
00102 SetVarArgs xv(1); xv[0]=x;
00103 branch(home, xv, SET_VAR_NONE(), vals, nullptr, vvp);
00104 }
00105
00106
00107 void
00108 assign(Home home, const SetVarArgs& x,
00109 SetVarBranch vars, SetAssign vals,
00110 SetBranchFilter bf,
00111 SetVarValPrint vvp) {
00112 using namespace Set;
00113 if (home.failed()) return;
00114 ViewArray<SetView> xv(home,x);
00115 ViewSel<SetView>* vs[1] = {
00116 new (home) ViewSelNone<SetView>(home,vars)
00117 };
00118 postviewvalbrancher<SetView,1,int,1>
00119 (home,xv,vs,Branch::valselcommit(home,vals),bf,vvp);
00120 }
00121
00122 void
00123 assign(Home home, const SetVarArgs& x,
00124 TieBreak<SetVarBranch> vars, SetAssign vals,
00125 SetBranchFilter bf,
00126 SetVarValPrint vvp) {
00127 using namespace Set;
00128 if (home.failed()) return;
00129 vars.a.expand(home,x);
00130 if ((vars.a.select() == SetVarBranch::SEL_NONE) ||
00131 (vars.a.select() == SetVarBranch::SEL_RND))
00132 vars.b = SET_VAR_NONE();
00133 vars.b.expand(home,x);
00134 if ((vars.b.select() == SetVarBranch::SEL_NONE) ||
00135 (vars.b.select() == SetVarBranch::SEL_RND))
00136 vars.c = SET_VAR_NONE();
00137 vars.c.expand(home,x);
00138 if ((vars.c.select() == SetVarBranch::SEL_NONE) ||
00139 (vars.c.select() == SetVarBranch::SEL_RND))
00140 vars.d = SET_VAR_NONE();
00141 vars.d.expand(home,x);
00142 if (vars.b.select() == SetVarBranch::SEL_NONE) {
00143 assign(home,x,vars.a,vals,bf,vvp);
00144 } else {
00145 ViewArray<SetView> xv(home,x);
00146 ValSelCommitBase<SetView,int>* vsc = Branch::valselcommit(home,vals);
00147 if (vars.c.select() == SetVarBranch::SEL_NONE) {
00148 ViewSel<SetView>* vs[2] = {
00149 Branch::viewsel(home,vars.a),Branch::viewsel(home,vars.b)
00150 };
00151 postviewvalbrancher<SetView,2,int,1>(home,xv,vs,vsc,bf,vvp);
00152 } else if (vars.d.select() == SetVarBranch::SEL_NONE) {
00153 ViewSel<SetView>* vs[3] = {
00154 Branch::viewsel(home,vars.a),Branch::viewsel(home,vars.b),
00155 Branch::viewsel(home,vars.c)
00156 };
00157 postviewvalbrancher<SetView,3,int,1>(home,xv,vs,vsc,bf,vvp);
00158 } else {
00159 ViewSel<SetView>* vs[4] = {
00160 Branch::viewsel(home,vars.a),Branch::viewsel(home,vars.b),
00161 Branch::viewsel(home,vars.c),Branch::viewsel(home,vars.d)
00162 };
00163 postviewvalbrancher<SetView,4,int,1>(home,xv,vs,vsc,bf,vvp);
00164 }
00165 }
00166 }
00167
00168 void
00169 assign(Home home, SetVar x, SetAssign vars, SetVarValPrint vvp) {
00170 SetVarArgs xv(1); xv[0]=x;
00171 assign(home, xv, SET_VAR_NONE(), vars, nullptr, vvp);
00172 }
00173
00174 }
00175
00176