Generated on Wed Nov 1 15:04:33 2006 for Gecode by doxygen 1.4.5

distinct.cc

Go to the documentation of this file.
00001 /*
00002  *  Main authors:
00003  *     Christian Schulte <schulte@gecode.org>
00004  *     Gabor Szokoli <szokoli@gecode.org>
00005  *
00006  *  Copyright:
00007  *     Christian Schulte, 2002
00008  *     Gabor Szokoli, 2003
00009  *
00010  *  Last modified:
00011  *     $Date: 2006-08-04 16:03:26 +0200 (Fri, 04 Aug 2006) $ by $Author: schulte $
00012  *     $Revision: 3512 $
00013  *
00014  *  This file is part of Gecode, the generic constraint
00015  *  development environment:
00016  *     http://www.gecode.org
00017  *
00018  *  See the file "LICENSE" for information on usage and
00019  *  redistribution of this file, and for a
00020  *     DISCLAIMER OF ALL WARRANTIES.
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 // STATISTICS: int-post
00077