Generated on Thu Mar 22 10:39:36 2012 for Gecode by doxygen 1.6.3

element.cpp

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  *
00006  *  Copyright:
00007  *     Christian Schulte, 2004
00008  *
00009  *  Last modified:
00010  *     $Date: 2010-03-03 17:40:32 +0100 (Wed, 03 Mar 2010) $ by $Author: schulte $
00011  *     $Revision: 10365 $
00012  *
00013  *  This file is part of Gecode, the generic constraint
00014  *  development environment:
00015  *     http://www.gecode.org
00016  *
00017  *  Permission is hereby granted, free of charge, to any person obtaining
00018  *  a copy of this software and associated documentation files (the
00019  *  "Software"), to deal in the Software without restriction, including
00020  *  without limitation the rights to use, copy, modify, merge, publish,
00021  *  distribute, sublicense, and/or sell copies of the Software, and to
00022  *  permit persons to whom the Software is furnished to do so, subject to
00023  *  the following conditions:
00024  *
00025  *  The above copyright notice and this permission notice shall be
00026  *  included in all copies or substantial portions of the Software.
00027  *
00028  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00029  *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00030  *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00031  *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
00032  *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
00033  *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00034  *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00035  *
00036  */
00037 
00038 #include <gecode/int/element.hh>
00039 
00040 namespace Gecode {
00041 
00042   using namespace Int;
00043 
00044   void
00045   element(Home home, IntSharedArray c, IntVar x0, IntVar x1,
00046           IntConLevel) {
00047     if (c.size() == 0)
00048       throw TooFewArguments("Int::element");
00049     if (home.failed()) return;
00050     for (int i = c.size(); i--; )
00051       Limits::check(c[i],"Int::element");
00052     GECODE_ES_FAIL((Element::post_int<IntView,IntView>(home,c,x0,x1)));
00053   }
00054 
00055   void
00056   element(Home home, IntSharedArray c, IntVar x0, BoolVar x1,
00057           IntConLevel) {
00058     if (c.size() == 0)
00059       throw TooFewArguments("Int::element");
00060     if (home.failed()) return;
00061     for (int i = c.size(); i--; )
00062       Limits::check(c[i],"Int::element");
00063     GECODE_ES_FAIL((Element::post_int<IntView,BoolView>(home,c,x0,x1)));
00064   }
00065 
00066   void
00067   element(Home home, IntSharedArray c, IntVar x0, int x1,
00068           IntConLevel) {
00069     if (c.size() == 0)
00070       throw TooFewArguments("Int::element");
00071     Limits::check(x1,"Int::element");
00072     if (home.failed()) return;
00073     for (int i = c.size(); i--; )
00074       Limits::check(c[i],"Int::element");
00075     ConstIntView cx1(x1);
00076     GECODE_ES_FAIL(
00077                    (Element::post_int<IntView,ConstIntView>(home,c,x0,cx1)));
00078   }
00079 
00080   void
00081   element(Home home, const IntVarArgs& c, IntVar x0, IntVar x1,
00082           IntConLevel icl) {
00083     if (c.size() == 0)
00084       throw TooFewArguments("Int::element");
00085     if (home.failed()) return;
00086     Element::IdxViewArray<IntView> iv(home,c);
00087     if ((icl == ICL_DOM) || (icl == ICL_DEF)) {
00088       GECODE_ES_FAIL((Element::ViewDom<IntView,IntView,IntView>
00089                            ::post(home,iv,x0,x1)));
00090     } else {
00091       GECODE_ES_FAIL((Element::ViewBnd<IntView,IntView,IntView>
00092                            ::post(home,iv,x0,x1)));
00093     }
00094   }
00095 
00096   void
00097   element(Home home, const IntVarArgs& c, IntVar x0, int x1,
00098           IntConLevel icl) {
00099     if (c.size() == 0)
00100       throw TooFewArguments("Int::element");
00101     Limits::check(x1,"Int::element");
00102     if (home.failed()) return;
00103     Element::IdxViewArray<IntView> iv(home,c);
00104     ConstIntView v1(x1);
00105     if ((icl == ICL_DOM) || (icl == ICL_DEF)) {
00106       GECODE_ES_FAIL((Element::ViewDom<IntView,IntView,ConstIntView>
00107                            ::post(home,iv,x0,v1)));
00108     } else {
00109       GECODE_ES_FAIL((Element::ViewBnd<IntView,IntView,ConstIntView>
00110                            ::post(home,iv,x0,v1)));
00111     }
00112   }
00113 
00114   void
00115   element(Home home, const BoolVarArgs& c, IntVar x0, BoolVar x1,
00116           IntConLevel) {
00117     if (c.size() == 0)
00118       throw TooFewArguments("Int::element");
00119     if (home.failed()) return;
00120     Element::IdxViewArray<BoolView> iv(home,c);
00121     GECODE_ES_FAIL((Element::ViewBnd<BoolView,IntView,BoolView>
00122                          ::post(home,iv,x0,x1)));
00123   }
00124 
00125   void
00126   element(Home home, const BoolVarArgs& c, IntVar x0, int x1,
00127           IntConLevel) {
00128     if (c.size() == 0)
00129       throw TooFewArguments("Int::element");
00130     Limits::check(x1,"Int::element");
00131     if (home.failed()) return;
00132     Element::IdxViewArray<BoolView> iv(home,c);
00133     ConstIntView v1(x1);
00134     GECODE_ES_FAIL((Element::ViewBnd<BoolView,IntView,ConstIntView>
00135                          ::post(home,iv,x0,v1)));
00136   }
00137 
00138   namespace {
00139     IntVar
00140     pair(Home home, IntVar x, int w, IntVar y, int h) {
00141       IntVar xy(home,0,w*h-1);
00142       if (Element::Pair::post(home,x,y,xy,w,h) != ES_OK)
00143         home.fail();
00144       return xy;
00145     }
00146   }
00147 
00148   void
00149   element(Home home, IntSharedArray a, 
00150           IntVar x, int w, IntVar y, int h, IntVar z,
00151           IntConLevel icl) {
00152     if (a.size() != w*h)
00153       throw Int::ArgumentSizeMismatch("Int::element");
00154     if (home.failed()) return;
00155     element(home, a, pair(home,x,w,y,h), z, icl);
00156   }
00157 
00158   void
00159   element(Home home, IntSharedArray a, 
00160           IntVar x, int w, IntVar y, int h, BoolVar z,
00161           IntConLevel icl) {
00162     if (a.size() != w*h)
00163       throw Int::ArgumentSizeMismatch("Int::element");
00164     if (home.failed()) return;
00165     element(home, a, pair(home,x,w,y,h), z, icl);
00166   }
00167 
00168   void
00169   element(Home home, const IntVarArgs& a, 
00170           IntVar x, int w, IntVar y, int h, IntVar z,
00171           IntConLevel icl) {
00172     if (a.size() != w*h)
00173       throw Int::ArgumentSizeMismatch("Int::element");
00174     if (home.failed()) return;
00175     element(home, a, pair(home,x,w,y,h), z, icl);
00176   }
00177 
00178   void
00179   element(Home home, const BoolVarArgs& a, 
00180           IntVar x, int w, IntVar y, int h, BoolVar z,
00181           IntConLevel icl) {
00182     if (a.size() != w*h)
00183       throw Int::ArgumentSizeMismatch("Int::element");
00184     if (home.failed()) return;
00185     element(home, a, pair(home,x,w,y,h), z, icl);
00186   }
00187 
00188 }
00189 
00190 // STATISTICS: int-post