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 #include <gecode/set/branch.hh>
00039
00040 namespace Gecode {
00041 BrancherHandle
00042 branch(Home home, const SetVarArgs& x,
00043 SetVarBranch vars, SetValBranch vals,
00044 SetBranchFilter bf, SetVarValPrint vvp) {
00045 using namespace Set;
00046 if (home.failed()) return BrancherHandle();
00047 vars.expand(home,x);
00048 ViewArray<SetView> xv(home,x);
00049 ViewSel<SetView>* vs[1] = {
00050 Branch::viewsel(home,vars)
00051 };
00052 return ViewValBrancher<SetView,1,int,2>::post
00053 (home,xv,vs,Branch::valselcommit(home,vals),bf,vvp);
00054 }
00055
00056 BrancherHandle
00057 branch(Home home, const SetVarArgs& x,
00058 TieBreak<SetVarBranch> vars, SetValBranch vals,
00059 SetBranchFilter bf, SetVarValPrint vvp) {
00060 using namespace Set;
00061 if (home.failed()) return BrancherHandle();
00062 vars.a.expand(home,x);
00063 if ((vars.a.select() == SetVarBranch::SEL_NONE) ||
00064 (vars.a.select() == SetVarBranch::SEL_RND))
00065 vars.b = SET_VAR_NONE();
00066 vars.b.expand(home,x);
00067 if ((vars.b.select() == SetVarBranch::SEL_NONE) ||
00068 (vars.b.select() == SetVarBranch::SEL_RND))
00069 vars.c = SET_VAR_NONE();
00070 vars.c.expand(home,x);
00071 if ((vars.c.select() == SetVarBranch::SEL_NONE) ||
00072 (vars.c.select() == SetVarBranch::SEL_RND))
00073 vars.d = SET_VAR_NONE();
00074 vars.d.expand(home,x);
00075 if (vars.b.select() == SetVarBranch::SEL_NONE) {
00076 return branch(home,x,vars.a,vals,bf,vvp);
00077 } else {
00078 ViewArray<SetView> xv(home,x);
00079 ValSelCommitBase<SetView,int>* vsc = Branch::valselcommit(home,vals);
00080 if (vars.c.select() == SetVarBranch::SEL_NONE) {
00081 ViewSel<SetView>* vs[2] = {
00082 Branch::viewsel(home,vars.a),Branch::viewsel(home,vars.b)
00083 };
00084 return ViewValBrancher<SetView,2,int,2>::post(home,xv,vs,vsc,bf,vvp);
00085 } else if (vars.d.select() == SetVarBranch::SEL_NONE) {
00086 ViewSel<SetView>* vs[3] = {
00087 Branch::viewsel(home,vars.a),Branch::viewsel(home,vars.b),
00088 Branch::viewsel(home,vars.c)
00089 };
00090 return ViewValBrancher<SetView,3,int,2>::post(home,xv,vs,vsc,bf,vvp);
00091 } else {
00092 ViewSel<SetView>* vs[4] = {
00093 Branch::viewsel(home,vars.a),Branch::viewsel(home,vars.b),
00094 Branch::viewsel(home,vars.c),Branch::viewsel(home,vars.d)
00095 };
00096 return ViewValBrancher<SetView,4,int,2>::post(home,xv,vs,vsc,bf,vvp);
00097 }
00098 }
00099 }
00100
00101 BrancherHandle
00102 branch(Home home, SetVar x, SetValBranch vals, SetVarValPrint vvp) {
00103 SetVarArgs xv(1); xv[0]=x;
00104 return branch(home, xv, SET_VAR_NONE(), vals, NULL, vvp);
00105 }
00106
00107 BrancherHandle
00108 assign(Home home, const SetVarArgs& x, SetAssign sa,
00109 SetBranchFilter bf, SetVarValPrint vvp) {
00110 using namespace Set;
00111 if (home.failed()) return BrancherHandle();
00112 ViewArray<SetView> xv(home,x);
00113 ViewSel<SetView>* vs[1] = {
00114 new (home) ViewSelNone<SetView>(home,SET_VAR_NONE())
00115 };
00116 return ViewValBrancher<SetView,1,int,1>::post
00117 (home,xv,vs,Branch::valselcommit(home,sa),bf,vvp);
00118 }
00119
00120 BrancherHandle
00121 assign(Home home, SetVar x, SetAssign sa, SetVarValPrint vvp) {
00122 SetVarArgs xv(1); xv[0]=x;
00123 return assign(home, xv, sa, NULL, vvp);
00124 }
00125
00126 }
00127
00128