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