Generated on Fri Oct 19 11:25:07 2018 for Gecode by doxygen 1.6.3

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