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

linear-bool.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, 2006
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/linear.hh>
00035 
00036 namespace Gecode {
00037 
00038   using namespace Int;
00039 
00040   void
00041   linear(Home home, const BoolVarArgs& x, IntRelType irt, int c,
00042          IntPropLevel ipl) {
00043     GECODE_POST;
00044 
00045     int n=x.size();
00046     Region re;
00047     Linear::Term<BoolView>* t = re.alloc<Linear::Term<BoolView>>(n);
00048     for (int i=0; i<n; i++) {
00049       t[i].a=1; t[i].x=x[i];
00050     }
00051 
00052     Linear::post(home,t,n,irt,c,ipl);
00053   }
00054 
00055   void
00056   linear(Home home, const BoolVarArgs& x, IntRelType irt, IntVar y,
00057          IntPropLevel ipl) {
00058     GECODE_POST;
00059 
00060     int n=x.size();
00061     Region re;
00062     Linear::Term<BoolView>* t = re.alloc<Linear::Term<BoolView>>(n);
00063     for (int i=0; i<n; i++) {
00064       t[i].a=1; t[i].x=x[i];
00065     }
00066 
00067     Linear::post(home,t,n,irt,y,0,ipl);
00068   }
00069 
00070   void
00071   linear(Home home,
00072          const IntArgs& a, const BoolVarArgs& x, IntRelType irt, int c,
00073          IntPropLevel ipl) {
00074     if (a.size() != x.size())
00075       throw ArgumentSizeMismatch("Int::linear");
00076 
00077     GECODE_POST;
00078 
00079     int n=x.size();
00080     Region re;
00081     Linear::Term<BoolView>* t = re.alloc<Linear::Term<BoolView>>(n);
00082     for (int i=0; i<n; i++) {
00083       t[i].a=a[i]; t[i].x=x[i];
00084     }
00085 
00086     Linear::post(home,t,n,irt,c,ipl);
00087   }
00088 
00089   void
00090   linear(Home home,
00091          const IntArgs& a, const BoolVarArgs& x, IntRelType irt, IntVar y,
00092          IntPropLevel ipl) {
00093     if (a.size() != x.size())
00094       throw ArgumentSizeMismatch("Int::linear");
00095 
00096     GECODE_POST;
00097 
00098     int n=x.size();
00099     Region re;
00100     Linear::Term<BoolView>* t =
00101       re.alloc<Linear::Term<BoolView>>(n);
00102     for (int i=0; i<n; i++) {
00103       t[i].a=a[i]; t[i].x=x[i];
00104     }
00105     int min, max;
00106     estimate(t,n,0,min,max);
00107     IntView v(y);
00108     switch (irt) {
00109     case IRT_EQ:
00110       GECODE_ME_FAIL(v.gq(home,min)); GECODE_ME_FAIL(v.lq(home,max));
00111       break;
00112     case IRT_GQ:
00113       GECODE_ME_FAIL(v.lq(home,max));
00114       break;
00115     case IRT_LQ:
00116       GECODE_ME_FAIL(v.gq(home,min));
00117       break;
00118     default: ;
00119     }
00120     if (home.failed()) return;
00121     Linear::post(home,t,n,irt,y,0,ipl);
00122   }
00123 
00124   void
00125   linear(Home home, const BoolVarArgs& x, IntRelType irt, int c,
00126          Reify r, IntPropLevel ipl) {
00127     GECODE_POST;
00128 
00129     int n=x.size();
00130     Region re;
00131     Linear::Term<BoolView>* t = re.alloc<Linear::Term<BoolView>>(n);
00132     for (int i=0; i<n; i++) {
00133       t[i].a=1; t[i].x=x[i];
00134     }
00135 
00136     Linear::post(home,t,n,irt,c,r,ipl);
00137   }
00138 
00139   void
00140   linear(Home home, const BoolVarArgs& x, IntRelType irt, IntVar y,
00141          Reify r, IntPropLevel ipl) {
00142     GECODE_POST;
00143 
00144     int n=x.size();
00145     Region re;
00146     Linear::Term<BoolView>* t = re.alloc<Linear::Term<BoolView>>(n);
00147     for (int i=0; i<n; i++) {
00148       t[i].a=1; t[i].x=x[i];
00149     }
00150 
00151     Linear::post(home,t,n,irt,y,r,ipl);
00152   }
00153 
00154   void
00155   linear(Home home,
00156          const IntArgs& a, const BoolVarArgs& x, IntRelType irt, int c,
00157          Reify r, IntPropLevel ipl) {
00158     if (a.size() != x.size())
00159       throw ArgumentSizeMismatch("Int::linear");
00160     GECODE_POST;
00161 
00162     int n=x.size();
00163     Region re;
00164     Linear::Term<BoolView>* t = re.alloc<Linear::Term<BoolView>>(n);
00165     for (int i=0; i<n; i++) {
00166       t[i].a=a[i]; t[i].x=x[i];
00167     }
00168 
00169     Linear::post(home,t,n,irt,c,r,ipl);
00170   }
00171 
00172   void
00173   linear(Home home,
00174          const IntArgs& a, const BoolVarArgs& x, IntRelType irt, IntVar y,
00175          Reify r, IntPropLevel ipl) {
00176     if (a.size() != x.size())
00177       throw ArgumentSizeMismatch("Int::linear");
00178     GECODE_POST;
00179 
00180     int n=x.size();
00181     Region re;
00182     Linear::Term<BoolView>* t = re.alloc<Linear::Term<BoolView>>(n);
00183     for (int i=0; i<n; i++) {
00184       t[i].a=a[i]; t[i].x=x[i];
00185     }
00186 
00187     Linear::post(home,t,n,irt,y,r,ipl);
00188   }
00189 
00190 }
00191 
00192 // STATISTICS: int-post