rel-op-singleton.cpp
Go to the documentation of this file.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(Home home, SetOpType op, const IntVarArgs& x, SetVar y) {
00050 if (home.failed()) return;
00051 ViewArray<SingletonView> xa(home,x.size());
00052 for (int i=x.size(); i--;) {
00053 Int::IntView iv(x[i]);
00054 SingletonView sv(iv);
00055 xa[i] = sv;
00056 }
00057
00058 switch (op) {
00059 case SOT_UNION:
00060 GECODE_ES_FAIL((RelOp::UnionN<SingletonView,SetView>
00061 ::post(home, xa, y)));
00062 break;
00063 case SOT_DUNION:
00064 GECODE_ES_FAIL((RelOp::PartitionN<SingletonView,SetView>
00065 ::post(home, xa, y)));
00066 break;
00067 case SOT_INTER:
00068 GECODE_ES_FAIL(
00069 (RelOp::IntersectionN<SingletonView,SetView>
00070 ::post(home, xa, y)));
00071 break;
00072 case SOT_MINUS:
00073 throw IllegalOperation("Set::rel");
00074 break;
00075 default:
00076 throw UnknownOperation("Set::rel");
00077 }
00078 }
00079
00080 void
00081 rel(Home home, SetOpType op, const IntVarArgs& x, const IntSet& z,
00082 SetVar y) {
00083 if (home.failed()) return;
00084 Set::Limits::check(z, "Set::rel");
00085 ViewArray<SingletonView> xa(home,x.size());
00086 for (int i=x.size(); i--;) {
00087 Int::IntView iv(x[i]);
00088 SingletonView sv(iv);
00089 xa[i] = sv;
00090 }
00091
00092 switch (op) {
00093 case SOT_UNION:
00094 GECODE_ES_FAIL((RelOp::UnionN<SingletonView,SetView>
00095 ::post(home, xa, z, y)));
00096 break;
00097 case SOT_DUNION:
00098 GECODE_ES_FAIL((RelOp::PartitionN<SingletonView,SetView>
00099 ::post(home, xa, z, y)));
00100 break;
00101 case SOT_INTER:
00102 GECODE_ES_FAIL(
00103 (RelOp::IntersectionN<SingletonView,SetView>
00104 ::post(home, xa, z, y)));
00105 break;
00106 case SOT_MINUS:
00107 throw IllegalOperation("set::rel");
00108 break;
00109 default:
00110 throw UnknownOperation("Set::rel");
00111 }
00112 }
00113 }
00114
00115