Generated on Tue Apr 18 10:21:53 2017 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: 2016-05-23 22:18:23 +0200 (Mon, 23 May 2016) $ by $Author: schulte $
00011  *     $Revision: 15073 $
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   void
00043   element(Home home, IntSharedArray c, IntVar x0, IntVar x1,
00044           IntPropLevel) {
00045     using namespace Int;
00046     if (c.size() == 0)
00047       throw TooFewArguments("Int::element");
00048     GECODE_POST;
00049     for (int i = c.size(); i--; )
00050       Limits::check(c[i],"Int::element");
00051     GECODE_ES_FAIL((Element::post_int<IntView,IntView>(home,c,x0,x1)));
00052   }
00053 
00054   void
00055   element(Home home, IntSharedArray c, IntVar x0, BoolVar x1,
00056           IntPropLevel) {
00057     using namespace Int;
00058     if (c.size() == 0)
00059       throw TooFewArguments("Int::element");
00060     GECODE_POST;
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           IntPropLevel) {
00069     using namespace Int;
00070     if (c.size() == 0)
00071       throw TooFewArguments("Int::element");
00072     Limits::check(x1,"Int::element");
00073     GECODE_POST;
00074     for (int i = c.size(); i--; )
00075       Limits::check(c[i],"Int::element");
00076     ConstIntView cx1(x1);
00077     GECODE_ES_FAIL(
00078                    (Element::post_int<IntView,ConstIntView>(home,c,x0,cx1)));
00079   }
00080 
00081   void
00082   element(Home home, const IntVarArgs& c, IntVar x0, IntVar x1,
00083           IntPropLevel ipl) {
00084     using namespace Int;
00085     if (c.size() == 0)
00086       throw TooFewArguments("Int::element");
00087     GECODE_POST;
00088     IdxViewArray<IntView> iv(home,c);
00089     if ((vbd(ipl) == IPL_DOM) || (vbd(ipl) == IPL_DEF)) {
00090       GECODE_ES_FAIL((Element::ViewDom<IntView,IntView,IntView>
00091                            ::post(home,iv,x0,x1)));
00092     } else {
00093       GECODE_ES_FAIL((Element::ViewBnd<IntView,IntView,IntView>
00094                            ::post(home,iv,x0,x1)));
00095     }
00096   }
00097 
00098   void
00099   element(Home home, const IntVarArgs& c, IntVar x0, int x1,
00100           IntPropLevel ipl) {
00101     using namespace Int;
00102     if (c.size() == 0)
00103       throw TooFewArguments("Int::element");
00104     Limits::check(x1,"Int::element");
00105     GECODE_POST;
00106     IdxViewArray<IntView> iv(home,c);
00107     ConstIntView v1(x1);
00108     if ((vbd(ipl) == IPL_DOM) || (vbd(ipl) == IPL_DEF)) {
00109       GECODE_ES_FAIL((Element::ViewDom<IntView,IntView,ConstIntView>
00110                            ::post(home,iv,x0,v1)));
00111     } else {
00112       GECODE_ES_FAIL((Element::ViewBnd<IntView,IntView,ConstIntView>
00113                            ::post(home,iv,x0,v1)));
00114     }
00115   }
00116 
00117   void
00118   element(Home home, const BoolVarArgs& c, IntVar x0, BoolVar x1,
00119           IntPropLevel) {
00120     using namespace Int;
00121     if (c.size() == 0)
00122       throw TooFewArguments("Int::element");
00123     GECODE_POST;
00124     IdxViewArray<BoolView> iv(home,c);
00125     GECODE_ES_FAIL((Element::ViewBnd<BoolView,IntView,BoolView>
00126                          ::post(home,iv,x0,x1)));
00127   }
00128 
00129   void
00130   element(Home home, const BoolVarArgs& c, IntVar x0, int x1,
00131           IntPropLevel) {
00132     using namespace Int;
00133     if (c.size() == 0)
00134       throw TooFewArguments("Int::element");
00135     Limits::check(x1,"Int::element");
00136     GECODE_POST;
00137     IdxViewArray<BoolView> iv(home,c);
00138     ConstIntView v1(x1);
00139     GECODE_ES_FAIL((Element::ViewBnd<BoolView,IntView,ConstIntView>
00140                          ::post(home,iv,x0,v1)));
00141   }
00142 
00143   namespace {
00144     IntVar
00145     pair(Home home, IntVar x, int w, IntVar y, int h) {
00146       IntVar xy(home,0,w*h-1);
00147       if (Int::Element::Pair::post(home,x,y,xy,w,h) != ES_OK)
00148         home.fail();
00149       return xy;
00150     }
00151   }
00152 
00153   void
00154   element(Home home, IntSharedArray a,
00155           IntVar x, int w, IntVar y, int h, IntVar z,
00156           IntPropLevel ipl) {
00157     using namespace Int;
00158     if (a.size() != w*h)
00159       throw Int::ArgumentSizeMismatch("Int::element");
00160     GECODE_POST;
00161     element(home, a, pair(home,x,w,y,h), z, ipl);
00162   }
00163 
00164   void
00165   element(Home home, IntSharedArray a,
00166           IntVar x, int w, IntVar y, int h, BoolVar z,
00167           IntPropLevel ipl) {
00168     using namespace Int;
00169     if (a.size() != w*h)
00170       throw Int::ArgumentSizeMismatch("Int::element");
00171     GECODE_POST;
00172     element(home, a, pair(home,x,w,y,h), z, ipl);
00173   }
00174 
00175   void
00176   element(Home home, const IntVarArgs& a,
00177           IntVar x, int w, IntVar y, int h, IntVar z,
00178           IntPropLevel ipl) {
00179     using namespace Int;
00180     if (a.size() != w*h)
00181       throw Int::ArgumentSizeMismatch("Int::element");
00182     GECODE_POST;
00183     element(home, a, pair(home,x,w,y,h), z, ipl);
00184   }
00185 
00186   void
00187   element(Home home, const BoolVarArgs& a,
00188           IntVar x, int w, IntVar y, int h, BoolVar z,
00189           IntPropLevel ipl) {
00190     using namespace Int;
00191     if (a.size() != w*h)
00192       throw Int::ArgumentSizeMismatch("Int::element");
00193     GECODE_POST;
00194     element(home, a, pair(home,x,w,y,h), z, ipl);
00195   }
00196 
00197 }
00198 
00199 // STATISTICS: int-post