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
00041 #include "gecode/set/rel-op.hh"
00042
00043 namespace Gecode {
00044 using namespace Gecode::Set;
00045 using namespace Gecode::Set::Rel;
00046 using namespace Gecode::Set::RelOp;
00047
00048 void
00049 rel(Space* home, SetVar x, SetOpType op, SetVar y, SetRelType r, SetVar z) {
00050 rel_op_post<SetView,SetView,SetView>(home, x, op, y, r, z);
00051 }
00052
00053 void
00054 rel(Space* home, SetOpType op, const SetVarArgs& x, SetVar y) {
00055 if (home->failed()) return;
00056 ViewArray<SetView> xa(home,x);
00057 switch(op) {
00058 case SOT_UNION:
00059 GECODE_ES_FAIL(home,(RelOp::UnionN<SetView,SetView>::post(home, xa, y)));
00060 break;
00061 case SOT_DUNION:
00062 GECODE_ES_FAIL(home,
00063 (RelOp::PartitionN<SetView,SetView>::post(home, xa, y)));
00064 break;
00065 case SOT_INTER:
00066 {
00067 GECODE_ES_FAIL(home,
00068 (RelOp::IntersectionN<SetView,SetView>
00069 ::post(home, xa, y)));
00070 }
00071 break;
00072 case SOT_MINUS:
00073 throw InvalidRelation("rel minus");
00074 break;
00075 }
00076 }
00077
00078 void
00079 rel(Space* home, SetOpType op, const SetVarArgs& x, const IntSet& z, SetVar y) {
00080 if (home->failed()) return;
00081 Set::Limits::check(z, "Set::rel");
00082 ViewArray<SetView> xa(home,x);
00083 switch(op) {
00084 case SOT_UNION:
00085 GECODE_ES_FAIL(home,(RelOp::UnionN<SetView,SetView>::post(home, xa, z, y)));
00086 break;
00087 case SOT_DUNION:
00088 GECODE_ES_FAIL(home,
00089 (RelOp::PartitionN<SetView,SetView>::post(home, xa, z, y)));
00090 break;
00091 case SOT_INTER:
00092 {
00093 GECODE_ES_FAIL(home,
00094 (RelOp::IntersectionN<SetView,SetView>
00095 ::post(home, xa, z, y)));
00096 }
00097 break;
00098 case SOT_MINUS:
00099 throw InvalidRelation("rel minus");
00100 break;
00101 }
00102 }
00103
00104 void
00105 rel(Space* home, SetOpType op, const IntVarArgs& x, SetVar y) {
00106 if (home->failed()) return;
00107 ViewArray<SingletonView> xa(home,x.size());
00108 for (int i=x.size(); i--;) {
00109 Int::IntView iv(x[i]);
00110 SingletonView sv(iv);
00111 xa[i] = sv;
00112 }
00113
00114 switch(op) {
00115 case SOT_UNION:
00116 GECODE_ES_FAIL(home,(RelOp::UnionN<SingletonView,SetView>
00117 ::post(home, xa, y)));
00118 break;
00119 case SOT_DUNION:
00120 GECODE_ES_FAIL(home,(RelOp::PartitionN<SingletonView,SetView>
00121 ::post(home, xa, y)));
00122 break;
00123 case SOT_INTER:
00124 GECODE_ES_FAIL(home,
00125 (RelOp::IntersectionN<SingletonView,SetView>
00126 ::post(home, xa, y)));
00127 break;
00128 case SOT_MINUS:
00129 throw InvalidRelation("rel minus");
00130 break;
00131 }
00132 }
00133
00134 void
00135 rel(Space* home, SetOpType op, const IntVarArgs& x, const IntSet& z, SetVar y) {
00136 if (home->failed()) return;
00137 Set::Limits::check(z, "Set::rel");
00138 ViewArray<SingletonView> xa(home,x.size());
00139 for (int i=x.size(); i--;) {
00140 Int::IntView iv(x[i]);
00141 SingletonView sv(iv);
00142 xa[i] = sv;
00143 }
00144
00145 switch(op) {
00146 case SOT_UNION:
00147 GECODE_ES_FAIL(home,(RelOp::UnionN<SingletonView,SetView>
00148 ::post(home, xa, z, y)));
00149 break;
00150 case SOT_DUNION:
00151 GECODE_ES_FAIL(home,(RelOp::PartitionN<SingletonView,SetView>
00152 ::post(home, xa, z, y)));
00153 break;
00154 case SOT_INTER:
00155 GECODE_ES_FAIL(home,
00156 (RelOp::IntersectionN<SingletonView,SetView>
00157 ::post(home, xa, z, y)));
00158 break;
00159 case SOT_MINUS:
00160 throw InvalidRelation("rel minus");
00161 break;
00162 }
00163 }
00164
00165 namespace {
00166
00167 GECODE_REGISTER3(RelOp::Union<SingletonView, SingletonView, SetView>);
00168 GECODE_REGISTER3(RelOp::Union<SetView, SetView, ComplementView<SetView> >);
00169 GECODE_REGISTER3(RelOp::Union<SetView, SetView, SetView>);
00170
00171 GECODE_REGISTER2(Set::RelOp::UnionN<SetView,SetView>);
00172 GECODE_REGISTER2(Set::RelOp::UnionN<SingletonView,SetView>);
00173
00174 GECODE_REGISTER3(RelOp::Intersection<SingletonView, SingletonView, SetView>);
00175 GECODE_REGISTER3(RelOp::Intersection<SetView, ComplementView<SetView>, SetView>);
00176 GECODE_REGISTER3(RelOp::Intersection<SetView, ComplementView<SetView>, ComplementView<SetView> >);
00177 GECODE_REGISTER3(RelOp::Intersection<SetView, SetView, ComplementView<SetView> >);
00178 GECODE_REGISTER3(RelOp::Intersection<SetView, SetView, SetView>);
00179
00180 GECODE_REGISTER2(Set::RelOp::IntersectionN<SetView,SetView>);
00181 GECODE_REGISTER2(Set::RelOp::IntersectionN<SingletonView,SetView>);
00182
00183 GECODE_REGISTER2(Set::RelOp::PartitionN<SetView,SetView>);
00184 GECODE_REGISTER2(Set::RelOp::PartitionN<SingletonView,SetView>);
00185
00186 GECODE_REGISTER3(RelOp::SubOfUnion<SetView, SetView, SetView>);
00187
00188 GECODE_REGISTER3(RelOp::SuperOfInter<SetView, SingletonView, EmptyView>);
00189 GECODE_REGISTER3(RelOp::SuperOfInter<SetView, ComplementView<SetView>, SetView>);
00190 GECODE_REGISTER3(RelOp::SuperOfInter<SetView, SetView, EmptyView>);
00191 GECODE_REGISTER3(RelOp::SuperOfInter<SetView, SetView, SetView>);
00192
00193 }
00194
00195 }
00196
00197