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 #include "gecode/int/distinct.hh"
00025
00026 namespace Gecode {
00027
00028 using namespace Int;
00029
00030 void
00031 distinct(Space* home, const IntVarArgs& x, IntConLevel icl) {
00032 if (x.same())
00033 throw ArgumentSame("Int::distinct");
00034 if (home->failed()) return;
00035 ViewArray<IntView> xv(home,x);
00036 switch (icl) {
00037 case ICL_BND:
00038 GECODE_ES_FAIL(home,Distinct::Bnd<IntView>::post(home,xv));
00039 break;
00040 case ICL_DOM:
00041 GECODE_ES_FAIL(home,Distinct::Dom<IntView>::post(home,xv));
00042 break;
00043 default:
00044 GECODE_ES_FAIL(home,Distinct::Val<IntView>::post(home,xv));
00045 }
00046 }
00047
00048 void
00049 distinct(Space* home, const IntArgs& c, const IntVarArgs& x,
00050 IntConLevel icl) {
00051 if (x.same())
00052 throw ArgumentSame("Int::distinct");
00053 if (c.size() != x.size())
00054 throw ArgumentSizeMismatch("Int::distinct");
00055 if (home->failed()) return;
00056 ViewArray<OffsetView> cx(home,x.size());
00057 for (int i = c.size(); i--; )
00058 if ((c[i] < Limits::Int::int_min) || (c[i] > Limits::Int::int_max))
00059 throw NumericalOverflow("Int::distinct");
00060 else
00061 cx[i].init(x[i],c[i]);
00062 switch (icl) {
00063 case ICL_BND:
00064 GECODE_ES_FAIL(home,Distinct::Bnd<OffsetView>::post(home,cx));
00065 break;
00066 case ICL_DOM:
00067 GECODE_ES_FAIL(home,Distinct::Dom<OffsetView>::post(home,cx));
00068 break;
00069 default:
00070 GECODE_ES_FAIL(home,Distinct::Val<OffsetView>::post(home,cx));
00071 }
00072 }
00073
00074 }
00075
00076
00077