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 void
00107 assign(Home home, const SetVarArgs& x, SetAssign sa,
00108 SetBranchFilter bf,
00109 SetVarValPrint vvp) {
00110 using namespace Set;
00111 if (home.failed()) return;
00112 ViewArray<SetView> xv(home,x);
00113 ViewSel<SetView>* vs[1] = {
00114 new (home) ViewSelNone<SetView>(home,SET_VAR_NONE())
00115 };
00116 postviewvalbrancher<SetView,1,int,1>
00117 (home,xv,vs,Branch::valselcommit(home,sa),bf,vvp);
00118 }
00119
00120 void
00121 assign(Home home, SetVar x, SetAssign sa, SetVarValPrint vvp) {
00122 SetVarArgs xv(1); xv[0]=x;
00123 assign(home, xv, sa, nullptr, vvp);
00124 }
00125
00126 }
00127
00128