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 #include <gecode/set/rel.hh>
00038 #include <gecode/set/rel-op.hh>
00039 #include <gecode/set/int.hh>
00040
00041 namespace Gecode { namespace Set {
00042
00043 template<class View0, class View1>
00044 forceinline void
00045 rel_post(Home home, View0 x0, SetRelType r, View1 x1) {
00046 using namespace Set::Rel;
00047 using namespace Set::RelOp;
00048 GECODE_POST;
00049 switch (r) {
00050 case SRT_EQ:
00051 GECODE_ES_FAIL((Eq<View0,View1>::post(home,x0,x1)));
00052 break;
00053 case SRT_NQ:
00054 GECODE_ES_FAIL((Distinct<View0,View1>::post(home,x0,x1)));
00055 break;
00056 case SRT_SUB:
00057 GECODE_ES_FAIL((Subset<View0,View1>::post(home, x0,x1)));
00058 break;
00059 case SRT_SUP:
00060 GECODE_ES_FAIL((Subset<View1,View0>::post(home, x1,x0)));
00061 break;
00062 case SRT_DISJ:
00063 {
00064 EmptyView emptyset;
00065 GECODE_ES_FAIL((SuperOfInter<View0,View1,EmptyView>
00066 ::post(home, x0, x1, emptyset)));
00067 }
00068 break;
00069 case SRT_CMPL:
00070 {
00071 ComplementView<View0> cx0(x0);
00072 GECODE_ES_FAIL((Eq<ComplementView<View0>, View1>
00073 ::post(home, cx0, x1)));
00074 }
00075 break;
00076 case SRT_LQ:
00077 GECODE_ES_FAIL((Lq<View0,View1,false>::post(home,x0,x1)));
00078 break;
00079 case SRT_LE:
00080 GECODE_ES_FAIL((Lq<View0,View1,true>::post(home,x0,x1)));
00081 break;
00082 case SRT_GQ:
00083 GECODE_ES_FAIL((Lq<View1,View0,false>::post(home,x1,x0)));
00084 break;
00085 case SRT_GR:
00086 GECODE_ES_FAIL((Lq<View1,View0,true>::post(home,x1,x0)));
00087 break;
00088 default:
00089 throw UnknownRelation("Set::rel");
00090 }
00091 }
00092
00093 template<class View0, class View1, ReifyMode rm>
00094 forceinline void
00095 rel_re(Home home, View0 x, SetRelType r, View1 y, BoolVar b) {
00096 using namespace Set::Rel;
00097 using namespace Set::RelOp;
00098 GECODE_POST;
00099 switch (r) {
00100 case SRT_EQ:
00101 GECODE_ES_FAIL((ReEq<View0,View1,Gecode::Int::BoolView,rm>
00102 ::post(home, x,y,b)));
00103 break;
00104 case SRT_NQ:
00105 {
00106 Gecode::Int::NegBoolView notb(b);
00107 switch (rm) {
00108 case RM_EQV:
00109 GECODE_ES_FAIL((ReEq<View0,View1,Gecode::Int::NegBoolView,RM_EQV>
00110 ::post(home,x,y,notb)));
00111 break;
00112 case RM_IMP:
00113 GECODE_ES_FAIL((ReEq<View0,View1,Gecode::Int::NegBoolView,RM_PMI>
00114 ::post(home,x,y,notb)));
00115 break;
00116 case RM_PMI:
00117 GECODE_ES_FAIL((ReEq<View0,View1,Gecode::Int::NegBoolView,RM_IMP>
00118 ::post(home,x,y,notb)));
00119 break;
00120 default: throw Gecode::Int::UnknownReifyMode("Set::rel");
00121 }
00122 }
00123 break;
00124 case SRT_SUB:
00125 GECODE_ES_FAIL((ReSubset<View0,View1,Gecode::Int::BoolView,rm>::post(home, x,y,b)));
00126 break;
00127 case SRT_SUP:
00128 GECODE_ES_FAIL((ReSubset<View1,View0,Gecode::Int::BoolView,rm>::post(home, y,x,b)));
00129 break;
00130 case SRT_DISJ:
00131 {
00132
00133
00134
00135 ComplementView<View0> xc(x);
00136 GECODE_ES_FAIL((ReSubset<View1,ComplementView<View0>,
00137 Gecode::Int::BoolView,rm>
00138 ::post(home, y, xc, b)));
00139 }
00140 break;
00141 case SRT_CMPL:
00142 {
00143 ComplementView<View0> xc(x);
00144 GECODE_ES_FAIL((ReEq<ComplementView<View0>,View1,
00145 Gecode::Int::BoolView,rm>
00146 ::post(home, xc, y, b)));
00147 }
00148 break;
00149 case SRT_LQ:
00150 GECODE_ES_FAIL((ReLq<View0,View1,rm,false>::post(home,x,y,b)));
00151 break;
00152 case SRT_LE:
00153 GECODE_ES_FAIL((ReLq<View0,View1,rm,true>::post(home,x,y,b)));
00154 break;
00155 case SRT_GQ:
00156 GECODE_ES_FAIL((ReLq<View1,View0,rm,false>::post(home,y,x,b)));
00157 break;
00158 case SRT_GR:
00159 GECODE_ES_FAIL((ReLq<View1,View0,rm,true>::post(home,y,x,b)));
00160 break;
00161 default:
00162 throw UnknownRelation("Set::rel");
00163 }
00164 }
00165
00166 }}
00167
00168 namespace Gecode {
00169
00170 void
00171 rel(Home home, SetVar x, SetRelType r, SetVar y) {
00172 using namespace Set;
00173 rel_post<SetView,SetView>(home,x,r,y);
00174 }
00175
00176 void
00177 rel(Home home, SetVar s, SetRelType r, IntVar x) {
00178 using namespace Set;
00179 Gecode::Int::IntView xv(x);
00180 SingletonView xsingle(xv);
00181 rel_post<SetView,SingletonView>(home,s,r,xv);
00182 }
00183
00184 void
00185 rel(Home home, IntVar x, SetRelType r, SetVar s) {
00186 using namespace Set;
00187 switch (r) {
00188 case SRT_SUB:
00189 rel(home, s, SRT_SUP, x);
00190 break;
00191 case SRT_SUP:
00192 rel(home, s, SRT_SUB, x);
00193 break;
00194 default:
00195 rel(home, s, r, x);
00196 }
00197 }
00198
00199 void
00200 rel(Home home, SetVar x, SetRelType rt, SetVar y, Reify r) {
00201 using namespace Set;
00202 switch (r.mode()) {
00203 case RM_EQV:
00204 rel_re<SetView,SetView,RM_EQV>(home,x,rt,y,r.var());
00205 break;
00206 case RM_IMP:
00207 rel_re<SetView,SetView,RM_IMP>(home,x,rt,y,r.var());
00208 break;
00209 case RM_PMI:
00210 rel_re<SetView,SetView,RM_PMI>(home,x,rt,y,r.var());
00211 break;
00212 default: throw Gecode::Int::UnknownReifyMode("Set::rel");
00213 }
00214 }
00215
00216 void
00217 rel(Home home, SetVar s, SetRelType rt, IntVar x, Reify r) {
00218 using namespace Set;
00219 Gecode::Int::IntView xv(x);
00220 SingletonView xsingle(xv);
00221 switch (r.mode()) {
00222 case RM_EQV:
00223 rel_re<SetView,SingletonView,RM_EQV>(home,s,rt,xsingle,r.var());
00224 break;
00225 case RM_IMP:
00226 rel_re<SetView,SingletonView,RM_IMP>(home,s,rt,xsingle,r.var());
00227 break;
00228 case RM_PMI:
00229 rel_re<SetView,SingletonView,RM_PMI>(home,s,rt,xsingle,r.var());
00230 break;
00231 default: throw Gecode::Int::UnknownReifyMode("Set::rel");
00232 }
00233 }
00234
00235 void
00236 rel(Home home, IntVar x, SetRelType rt, SetVar s, Reify r) {
00237 using namespace Set;
00238 switch (rt) {
00239 case SRT_SUB:
00240 rel(home, s, SRT_SUP, x, r);
00241 break;
00242 case SRT_SUP:
00243 rel(home, s, SRT_SUB, x, r);
00244 break;
00245 default:
00246 rel(home, s, rt, x, r);
00247 }
00248 }
00249
00250 }
00251
00252