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
00039
00040 #include "gecode/set.hh"
00041
00042 #include "gecode/set/int.hh"
00043 #include "gecode/set/rel.hh"
00044
00045 using namespace Gecode::Int;
00046
00047 namespace Gecode {
00048
00049 void
00050 rel(Space* home, SetVar s, IntRelType r, IntVar x) {
00051 if (home->failed()) return;
00052 switch(r) {
00053 case IRT_EQ:
00054 {
00055 Gecode::Int::IntView xv(x);
00056 Set::SingletonView xsingle(xv);
00057 GECODE_ES_FAIL(home,
00058 (Set::Rel::Eq<Set::SetView,Set::SingletonView>
00059 ::post(home,s,xsingle)));
00060
00061 }
00062 break;
00063 case IRT_NQ:
00064 {
00065 Gecode::Set::SetView sv(s);
00066 GECODE_ME_FAIL(home, sv.cardMin(home, 1));
00067 Gecode::Int::IntView xv(x);
00068 Set::SingletonView xsingle(xv);
00069 GECODE_ES_FAIL(home,
00070 (Set::Rel::NoSubSet<Set::SingletonView,Set::SetView>
00071 ::post(home,xsingle,sv)));
00072
00073 }
00074 break;
00075 case IRT_LQ:
00076 {
00077 IntVar tmp(home, Int::Limits::min, Int::Limits::max);
00078 rel(home, tmp, IRT_LQ, x);
00079 GECODE_ES_FAIL(home,Set::Int::MaxElement<Set::SetView>::post(home,s,tmp));
00080 }
00081 break;
00082 case IRT_LE:
00083 {
00084 IntVar tmp(home, Int::Limits::min, Int::Limits::max);
00085 rel(home, tmp, IRT_LE, x);
00086 GECODE_ES_FAIL(home,Set::Int::MaxElement<Set::SetView>::post(home,s,tmp));
00087 }
00088 break;
00089 case IRT_GQ:
00090 {
00091 IntVar tmp(home, Int::Limits::min, Int::Limits::max);
00092 rel(home, tmp, IRT_GQ, x);
00093 GECODE_ES_FAIL(home,Set::Int::MinElement<Set::SetView>::post(home,s,tmp));
00094 }
00095 break;
00096 case IRT_GR:
00097 {
00098 IntVar tmp(home, Int::Limits::min, Int::Limits::max);
00099 rel(home, tmp, IRT_GR, x);
00100 GECODE_ES_FAIL(home,Set::Int::MinElement<Set::SetView>::post(home,s,tmp));
00101 }
00102 break;
00103 }
00104
00105 }
00106
00107 void
00108 rel(Space* home, IntVar x, IntRelType r, SetVar s) {
00109 IntRelType rr;
00110 switch (r) {
00111 case IRT_LE: rr=IRT_GR; break;
00112 case IRT_LQ: rr=IRT_GQ; break;
00113 case IRT_GR: rr=IRT_LE; break;
00114 case IRT_GQ: rr=IRT_LQ; break;
00115 default: rr=r;
00116 }
00117 rel(home, s, rr, x);
00118 }
00119
00120 void
00121 min(Space* home, SetVar s, IntVar x){
00122 if (home->failed()) return;
00123 GECODE_ES_FAIL(home,Set::Int::MinElement<Set::SetView>::post(home,s,x));
00124 }
00125 void
00126 max(Space* home, SetVar s, IntVar x){
00127 if (home->failed()) return;
00128 GECODE_ES_FAIL(home,Set::Int::MaxElement<Set::SetView>::post(home,s,x));
00129 }
00130
00131 void
00132 match(Space* home, SetVar s, const IntVarArgs& x) {
00133 if (home->failed()) return;
00134 ViewArray<IntView> xa(home,x);
00135 GECODE_ES_FAIL(home,Set::Int::Match<Set::SetView>::post(home,s,xa));
00136 }
00137
00138 void
00139 channel(Space* home, const IntVarArgs& x, const SetVarArgs& y) {
00140 if (home->failed()) return;
00141 ViewArray<Int::IntView> xa(home,x);
00142 ViewArray<Set::SetView> ya(home,y);
00143 GECODE_ES_FAIL(home,(Set::Int::ChannelInt<Set::SetView>
00144 ::post(home,xa,ya)));
00145 }
00146
00147 void
00148 channel(Space* home, const BoolVarArgs& x, SetVar y) {
00149 if (home->failed()) return;
00150 ViewArray<Int::BoolView> xv(home,x);
00151 Set::SetView yv(y);
00152 GECODE_ES_FAIL(home,(Set::Int::ChannelBool<Set::SetView>
00153 ::post(home,xv,yv)));
00154 }
00155
00156 void weights(Space* home, const IntArgs& elements, const IntArgs& weights,
00157 SetVar x, IntVar y) {
00158 if (home->failed()) return;
00159 Set::SetView xv(x);
00160 Int::IntView yv(y);
00161 GECODE_ES_FAIL(home,Set::Int::Weights<Set::SetView>::post(home,elements,
00162 weights,x,y));
00163 }
00164
00165 namespace {
00166 GECODE_REGISTER1(Set::Int::MinElement<Set::SetView>);
00167 GECODE_REGISTER1(Set::Int::MaxElement<Set::SetView>);
00168 GECODE_REGISTER1(Set::Int::Card<Set::SetView>);
00169 GECODE_REGISTER1(Set::Int::Match<Set::SetView>);
00170 GECODE_REGISTER1(Set::Int::ChannelInt<Set::SetView>);
00171 GECODE_REGISTER1(Set::Int::ChannelBool<Set::SetView>);
00172 GECODE_REGISTER1(Set::Int::Weights<Set::SetView>);
00173 }
00174
00175 }
00176
00177