distinct.cc
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 #include "gecode/int/distinct.hh"
00041
00042 namespace Gecode {
00043
00044 using namespace Int;
00045
00046 void
00047 distinct(Space* home, const IntVarArgs& x, IntConLevel icl, PropKind) {
00048 if (x.same())
00049 throw ArgumentSame("Int::distinct");
00050 if (home->failed()) return;
00051 ViewArray<IntView> xv(home,x);
00052 switch (icl) {
00053 case ICL_BND:
00054 GECODE_ES_FAIL(home,Distinct::Bnd<IntView>::post(home,xv));
00055 break;
00056 case ICL_DOM:
00057 GECODE_ES_FAIL(home,Distinct::Dom<IntView>::post(home,xv));
00058 break;
00059 default:
00060 GECODE_ES_FAIL(home,Distinct::Val<IntView>::post(home,xv));
00061 }
00062 }
00063
00064 void
00065 distinct(Space* home, const IntArgs& c, const IntVarArgs& x,
00066 IntConLevel icl, PropKind) {
00067 if (x.same())
00068 throw ArgumentSame("Int::distinct");
00069 if (c.size() != x.size())
00070 throw ArgumentSizeMismatch("Int::distinct");
00071 if (home->failed()) return;
00072 ViewArray<OffsetView> cx(home,x.size());
00073 for (int i = c.size(); i--; ) {
00074 double cx_min = (static_cast<double>(c[i]) +
00075 static_cast<double>(x[i].min()));
00076 double cx_max = (static_cast<double>(c[i]) +
00077 static_cast<double>(x[i].max()));
00078 Limits::check(c[i],"Int::distinct");
00079 Limits::check(cx_min,"Int::distinct");
00080 Limits::check(cx_max,"Int::distinct");
00081 cx[i].init(x[i],c[i]);
00082 }
00083 switch (icl) {
00084 case ICL_BND:
00085 GECODE_ES_FAIL(home,Distinct::Bnd<OffsetView>::post(home,cx));
00086 break;
00087 case ICL_DOM:
00088 GECODE_ES_FAIL(home,Distinct::Dom<OffsetView>::post(home,cx));
00089 break;
00090 default:
00091 GECODE_ES_FAIL(home,Distinct::Val<OffsetView>::post(home,cx));
00092 }
00093 }
00094
00095 namespace {
00096 GECODE_REGISTER1(Distinct::Val<IntView>);
00097 GECODE_REGISTER1(Distinct::Val<OffsetView>);
00098 GECODE_REGISTER1(Distinct::Bnd<IntView>);
00099 GECODE_REGISTER1(Distinct::Bnd<OffsetView>);
00100 GECODE_REGISTER1(Distinct::Dom<IntView>);
00101 GECODE_REGISTER1(Distinct::Dom<OffsetView>);
00102 GECODE_REGISTER1(Distinct::TerDom<IntView>);
00103 GECODE_REGISTER1(Distinct::TerDom<OffsetView>);
00104 }
00105 }
00106
00107
00108