Generated on Mon Aug 25 11:35:33 2008 for Gecode by doxygen 1.5.6

distinct.cc

Go to the documentation of this file.
00001 /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
00002 /*
00003  *  Main authors:
00004  *     Christian Schulte <schulte@gecode.org>
00005  *     Gabor Szokoli <szokoli@gecode.org>
00006  *
00007  *  Copyright:
00008  *     Christian Schulte, 2002
00009  *     Gabor Szokoli, 2003
00010  *
00011  *  Last modified:
00012  *     $Date: 2008-01-31 21:06:01 +0100 (Thu, 31 Jan 2008) $ by $Author: schulte $
00013  *     $Revision: 6024 $
00014  *
00015  *  This file is part of Gecode, the generic constraint
00016  *  development environment:
00017  *     http://www.gecode.org
00018  *
00019  *  Permission is hereby granted, free of charge, to any person obtaining
00020  *  a copy of this software and associated documentation files (the
00021  *  "Software"), to deal in the Software without restriction, including
00022  *  without limitation the rights to use, copy, modify, merge, publish,
00023  *  distribute, sublicense, and/or sell copies of the Software, and to
00024  *  permit persons to whom the Software is furnished to do so, subject to
00025  *  the following conditions:
00026  *
00027  *  The above copyright notice and this permission notice shall be
00028  *  included in all copies or substantial portions of the Software.
00029  *
00030  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00031  *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00032  *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00033  *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
00034  *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
00035  *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00036  *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
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 // STATISTICS: int-post
00108