Generated on Thu Apr 11 13:58:58 2019 for Gecode by doxygen 1.6.3

dom.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 
00035 #include <gecode/int/dom.hh>
00036 #include <gecode/int/rel.hh>
00037 
00038 namespace Gecode {
00039 
00040   void
00041   dom(Home home, IntVar x, int n, IntPropLevel) {
00042     using namespace Int;
00043     Limits::check(n,"Int::dom");
00044     GECODE_POST;
00045     IntView xv(x);
00046     GECODE_ME_FAIL(xv.eq(home,n));
00047   }
00048 
00049   void
00050   dom(Home home, const IntVarArgs& x, int n, IntPropLevel) {
00051     using namespace Int;
00052     Limits::check(n,"Int::dom");
00053     GECODE_POST;
00054     for (int i=0; i<x.size(); i++) {
00055       IntView xv(x[i]);
00056       GECODE_ME_FAIL(xv.eq(home,n));
00057     }
00058   }
00059 
00060   void
00061   dom(Home home, IntVar x, int min, int max, IntPropLevel) {
00062     using namespace Int;
00063     Limits::check(min,"Int::dom");
00064     Limits::check(max,"Int::dom");
00065     GECODE_POST;
00066     IntView xv(x);
00067     GECODE_ME_FAIL(xv.gq(home,min));
00068     GECODE_ME_FAIL(xv.lq(home,max));
00069   }
00070 
00071   void
00072   dom(Home home, const IntVarArgs& x, int min, int max, IntPropLevel) {
00073     using namespace Int;
00074     Limits::check(min,"Int::dom");
00075     Limits::check(max,"Int::dom");
00076     GECODE_POST;
00077     for (int i=0; i<x.size(); i++) {
00078       IntView xv(x[i]);
00079       GECODE_ME_FAIL(xv.gq(home,min));
00080       GECODE_ME_FAIL(xv.lq(home,max));
00081     }
00082   }
00083 
00084   void
00085   dom(Home home, IntVar x, const IntSet& is, IntPropLevel) {
00086     using namespace Int;
00087     Limits::check(is.min(),"Int::dom");
00088     Limits::check(is.max(),"Int::dom");
00089     GECODE_POST;
00090     IntView xv(x);
00091     IntSetRanges ris(is);
00092     GECODE_ME_FAIL(xv.inter_r(home,ris,false));
00093   }
00094 
00095   void
00096   dom(Home home, const IntVarArgs& x, const IntSet& is, IntPropLevel) {
00097     using namespace Int;
00098     Limits::check(is.min(),"Int::dom");
00099     Limits::check(is.max(),"Int::dom");
00100     GECODE_POST;
00101     for (int i=0; i<x.size(); i++) {
00102       IntSetRanges ris(is);
00103       IntView xv(x[i]);
00104       GECODE_ME_FAIL(xv.inter_r(home,ris,false));
00105     }
00106   }
00107 
00108   void
00109   dom(Home home, IntVar x, int n, Reify r, IntPropLevel) {
00110     using namespace Int;
00111     Limits::check(n,"Int::dom");
00112     GECODE_POST;
00113     switch (r.mode()) {
00114     case RM_EQV:
00115       GECODE_ES_FAIL((Rel::ReEqDomInt<IntView,BoolView,RM_EQV>
00116                       ::post(home,x,n,r.var())));
00117       break;
00118     case RM_IMP:
00119       GECODE_ES_FAIL((Rel::ReEqDomInt<IntView,BoolView,RM_IMP>
00120                       ::post(home,x,n,r.var())));
00121       break;
00122     case RM_PMI:
00123       GECODE_ES_FAIL((Rel::ReEqDomInt<IntView,BoolView,RM_PMI>
00124                       ::post(home,x,n,r.var())));
00125       break;
00126     default: throw UnknownReifyMode("Int::dom");
00127     }
00128   }
00129 
00130   void
00131   dom(Home home, IntVar x, int min, int max, Reify r, IntPropLevel) {
00132     using namespace Int;
00133     Limits::check(min,"Int::dom");
00134     Limits::check(max,"Int::dom");
00135     GECODE_POST;
00136     switch (r.mode()) {
00137     case RM_EQV:
00138       GECODE_ES_FAIL((Dom::ReRange<IntView,RM_EQV>
00139                       ::post(home,x,min,max,r.var())));
00140       break;
00141     case RM_IMP:
00142       GECODE_ES_FAIL((Dom::ReRange<IntView,RM_IMP>
00143                       ::post(home,x,min,max,r.var())));
00144       break;
00145     case RM_PMI:
00146       GECODE_ES_FAIL((Dom::ReRange<IntView,RM_PMI>
00147                       ::post(home,x,min,max,r.var())));
00148       break;
00149     default: throw UnknownReifyMode("Int::dom");
00150     }
00151   }
00152 
00153 
00154   void
00155   dom(Home home, IntVar x, const IntSet& is, Reify r, IntPropLevel) {
00156     using namespace Int;
00157     Limits::check(is.min(),"Int::dom");
00158     Limits::check(is.max(),"Int::dom");
00159     GECODE_POST;
00160     switch (r.mode()) {
00161     case RM_EQV:
00162       GECODE_ES_FAIL((Dom::ReIntSet<IntView,RM_EQV>::post(home,x,is,r.var())));
00163       break;
00164     case RM_IMP:
00165       GECODE_ES_FAIL((Dom::ReIntSet<IntView,RM_IMP>::post(home,x,is,r.var())));
00166       break;
00167     case RM_PMI:
00168       GECODE_ES_FAIL((Dom::ReIntSet<IntView,RM_PMI>::post(home,x,is,r.var())));
00169       break;
00170     default: throw UnknownReifyMode("Int::dom");
00171     }
00172   }
00173 
00174   void
00175   dom(Home home, IntVar x, IntVar d, IntPropLevel) {
00176     using namespace Int;
00177     GECODE_POST;
00178     IntView xv(x), dv(d);
00179     if (xv != dv) {
00180       ViewRanges<IntView> r(dv);
00181       GECODE_ME_FAIL(xv.inter_r(home,r,false));
00182     }
00183   }
00184 
00185   void
00186   dom(Home home, BoolVar x, BoolVar d, IntPropLevel) {
00187     using namespace Int;
00188     GECODE_POST;
00189     if (d.one())
00190       GECODE_ME_FAIL(BoolView(x).one(home));
00191     else if (d.zero())
00192       GECODE_ME_FAIL(BoolView(x).zero(home));
00193   }
00194 
00195   void
00196   dom(Home home, const IntVarArgs& x, const IntVarArgs& d, IntPropLevel) {
00197     using namespace Int;
00198     if (x.size() != d.size())
00199       throw ArgumentSizeMismatch("Int::dom");
00200     for (int i=0; i<x.size(); i++) {
00201       GECODE_POST;
00202       IntView xv(x[i]), dv(d[i]);
00203       if (xv != dv) {
00204         ViewRanges<IntView> r(dv);
00205         GECODE_ME_FAIL(xv.inter_r(home,r,false));
00206       }
00207     }
00208   }
00209 
00210   void
00211   dom(Home home, const BoolVarArgs& x, const BoolVarArgs& d, IntPropLevel) {
00212     using namespace Int;
00213     if (x.size() != d.size())
00214       throw ArgumentSizeMismatch("Int::dom");
00215     for (int i=0; i<x.size(); i++) {
00216       GECODE_POST;
00217       if (d[i].one())
00218         GECODE_ME_FAIL(BoolView(x[i]).one(home));
00219       else if (d[i].zero())
00220         GECODE_ME_FAIL(BoolView(x[i]).zero(home));
00221     }
00222   }
00223 
00224 }
00225 
00226 // STATISTICS: int-post
00227