Generated on Mon Aug 25 11:35:37 2008 for Gecode by doxygen 1.5.6

linear-bool.cc

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  *  Last modified:
00010  *     $Date: 2008-07-11 11:02:56 +0200 (Fri, 11 Jul 2008) $ by $Author: tack $
00011  *     $Revision: 7355 $
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/linear.hh"
00039 
00040 namespace Gecode {
00041 
00042   using namespace Int;
00043 
00044   void
00045   linear(Space* home, const BoolVarArgs& x, IntRelType r, int c,
00046          IntConLevel icl, PropKind pk) {
00047     if (home->failed()) return;
00048 
00049     int n=x.size();
00050     GECODE_AUTOARRAY(Linear::Term<BoolView>, t, n);
00051     for (int i=n; i--; ) {
00052       t[i].a=1; t[i].x=x[i];
00053     }
00054 
00055     Linear::post(home,t,n,r,c,icl,pk);
00056   }
00057 
00058   void
00059   linear(Space* home, const BoolVarArgs& x, IntRelType r, IntVar y,
00060          IntConLevel icl, PropKind pk) {
00061     if (home->failed()) return;
00062 
00063     int n=x.size();
00064     GECODE_AUTOARRAY(Linear::Term<BoolView>, t, n);
00065     for (int i=n; i--; ) {
00066       t[i].a=1; t[i].x=x[i];
00067     }
00068 
00069     Linear::post(home,t,n,r,y,0,icl,pk);
00070   }
00071 
00072   void
00073   linear(Space* home,
00074          const IntArgs& a, const BoolVarArgs& x, IntRelType r, int c,
00075          IntConLevel icl, PropKind pk) {
00076     if (a.size() != x.size())
00077       throw ArgumentSizeMismatch("Int::linear");
00078     if (home->failed()) 
00079       return;
00080 
00081     int n=x.size();
00082     GECODE_AUTOARRAY(Linear::Term<BoolView>, t, n);
00083     for (int i=n; i--; ) {
00084       t[i].a=a[i]; t[i].x=x[i];
00085     }
00086 
00087     Linear::post(home,t,n,r,c,icl,pk);
00088   }
00089 
00090   void
00091   linear(Space* home,
00092          const IntArgs& a, const BoolVarArgs& x, IntRelType r, IntVar y,
00093          IntConLevel icl, PropKind pk) {
00094     if (a.size() != x.size())
00095       throw ArgumentSizeMismatch("Int::linear");
00096     if (home->failed()) 
00097       return;
00098 
00099     int n=x.size();
00100     GECODE_AUTOARRAY(Linear::Term<BoolView>, t, n);
00101     for (int i=n; i--; ) {
00102       t[i].a=a[i]; t[i].x=x[i];
00103     }
00104     int min, max;
00105     estimate(static_cast<Linear::Term<BoolView>*>(t),n,0,min,max);
00106     IntView v(y);
00107     switch (r) {
00108     case IRT_EQ:
00109       GECODE_ME_FAIL(home,v.gq(home,min)); GECODE_ME_FAIL(home,v.lq(home,max));
00110       break;
00111     case IRT_GQ:
00112       GECODE_ME_FAIL(home,v.lq(home,max));
00113       break;
00114     case IRT_LQ:
00115       GECODE_ME_FAIL(home,v.gq(home,min));
00116       break;
00117     default: ;
00118     }
00119     if (home->failed()) return;
00120     Linear::post(home,t,n,r,y,0,icl,pk);
00121   }
00122 
00123   void
00124   linear(Space* home, const BoolVarArgs& x, IntRelType r, int c,
00125          BoolVar b, IntConLevel icl, PropKind pk) {
00126     if (home->failed()) return;
00127 
00128     int n=x.size();
00129     GECODE_AUTOARRAY(Linear::Term<BoolView>, t, n);
00130     for (int i=n; i--; ) {
00131       t[i].a=1; t[i].x=x[i];
00132     }
00133 
00134     Linear::post(home,t,n,r,c,b,icl,pk);
00135   }
00136 
00137   void
00138   linear(Space* home, const BoolVarArgs& x, IntRelType r, IntVar y,
00139          BoolVar b, IntConLevel icl, PropKind pk) {
00140     if (home->failed()) return;
00141 
00142     int n=x.size();
00143     GECODE_AUTOARRAY(Linear::Term<BoolView>, t, n);
00144     for (int i=n; i--; ) {
00145       t[i].a=1; t[i].x=x[i];
00146     }
00147 
00148     Linear::post(home,t,n,r,y,b,icl,pk);
00149   }
00150 
00151   void
00152   linear(Space* home,
00153          const IntArgs& a, const BoolVarArgs& x, IntRelType r, int c,
00154          BoolVar b, IntConLevel icl, PropKind pk) {
00155     if (a.size() != x.size())
00156       throw ArgumentSizeMismatch("Int::linear");
00157     if (home->failed()) return;
00158 
00159     int n=x.size();
00160     GECODE_AUTOARRAY(Linear::Term<BoolView>, t, n);
00161     for (int i=n; i--; ) {
00162       t[i].a=a[i]; t[i].x=x[i];
00163     }
00164 
00165     Linear::post(home,t,n,r,c,b,icl,pk);
00166   }
00167 
00168   void
00169   linear(Space* home,
00170          const IntArgs& a, const BoolVarArgs& x, IntRelType r, IntVar y,
00171          BoolVar b, IntConLevel icl, PropKind pk) {
00172     if (a.size() != x.size())
00173       throw ArgumentSizeMismatch("Int::linear");
00174     if (home->failed()) return;
00175 
00176     int n=x.size();
00177     GECODE_AUTOARRAY(Linear::Term<BoolView>, t, n);
00178     for (int i=n; i--; ) {
00179       t[i].a=a[i]; t[i].x=x[i];
00180     }
00181 
00182     Linear::post(home,t,n,r,y,b,icl,pk);
00183   }
00184 
00185 
00186   namespace {
00187     using namespace Int;
00188     GECODE_REGISTER1(Linear::EqBoolInt<BoolView>::Memory);
00189     GECODE_REGISTER1(Linear::EqBoolInt<BoolView>::Speed);
00190     GECODE_REGISTER3(Linear::EqBoolScale<Linear::EmptyScaleBoolArray,Linear::EmptyScaleBoolArray,IntView>);
00191     GECODE_REGISTER3(Linear::EqBoolScale<Linear::EmptyScaleBoolArray,Linear::EmptyScaleBoolArray,ZeroIntView>);
00192     GECODE_REGISTER3(Linear::EqBoolScale<Linear::EmptyScaleBoolArray,Linear::ScaleBoolArray,IntView>);
00193     GECODE_REGISTER3(Linear::EqBoolScale<Linear::EmptyScaleBoolArray,Linear::ScaleBoolArray,ZeroIntView>);
00194     GECODE_REGISTER3(Linear::EqBoolScale<Linear::ScaleBoolArray,Linear::EmptyScaleBoolArray,IntView>);
00195     GECODE_REGISTER3(Linear::EqBoolScale<Linear::ScaleBoolArray,Linear::EmptyScaleBoolArray,ZeroIntView>);
00196     GECODE_REGISTER3(Linear::EqBoolScale<Linear::ScaleBoolArray,Linear::ScaleBoolArray,IntView>);
00197     GECODE_REGISTER3(Linear::EqBoolScale<Linear::ScaleBoolArray,Linear::ScaleBoolArray,ZeroIntView>);
00198     GECODE_REGISTER2(Linear::EqBoolView<BoolView,IntView>);
00199     GECODE_REGISTER2(Linear::EqBoolView<BoolView,MinusView>);
00200     GECODE_REGISTER1(Linear::GqBoolInt<BoolView>::Memory);
00201     GECODE_REGISTER1(Linear::GqBoolInt<BoolView>::Speed);
00202     GECODE_REGISTER1(Linear::GqBoolInt<NegBoolView>::Memory);
00203     GECODE_REGISTER1(Linear::GqBoolInt<NegBoolView>::Speed);
00204     GECODE_REGISTER2(Linear::GqBoolView<BoolView,IntView>);
00205     GECODE_REGISTER2(Linear::GqBoolView<BoolView,MinusView>);
00206     GECODE_REGISTER2(Linear::GqBoolView<NegBoolView,IntView>);
00207     GECODE_REGISTER2(Linear::GqBoolView<NegBoolView,MinusView>);
00208     GECODE_REGISTER3(Linear::LqBoolScale<Linear::EmptyScaleBoolArray,Linear::EmptyScaleBoolArray,IntView>);
00209     GECODE_REGISTER3(Linear::LqBoolScale<Linear::EmptyScaleBoolArray,Linear::EmptyScaleBoolArray,MinusView>);
00210     GECODE_REGISTER3(Linear::LqBoolScale<Linear::EmptyScaleBoolArray,Linear::EmptyScaleBoolArray,ZeroIntView>);
00211     GECODE_REGISTER3(Linear::LqBoolScale<Linear::EmptyScaleBoolArray,Linear::ScaleBoolArray,IntView>);
00212     GECODE_REGISTER3(Linear::LqBoolScale<Linear::EmptyScaleBoolArray,Linear::ScaleBoolArray,MinusView>);
00213     GECODE_REGISTER3(Linear::LqBoolScale<Linear::EmptyScaleBoolArray,Linear::ScaleBoolArray,ZeroIntView>);
00214     GECODE_REGISTER3(Linear::LqBoolScale<Linear::ScaleBoolArray,Linear::EmptyScaleBoolArray,IntView>);
00215     GECODE_REGISTER3(Linear::LqBoolScale<Linear::ScaleBoolArray,Linear::EmptyScaleBoolArray,MinusView>);
00216     GECODE_REGISTER3(Linear::LqBoolScale<Linear::ScaleBoolArray,Linear::EmptyScaleBoolArray,ZeroIntView>);
00217     GECODE_REGISTER3(Linear::LqBoolScale<Linear::ScaleBoolArray,Linear::ScaleBoolArray,IntView>);
00218     GECODE_REGISTER3(Linear::LqBoolScale<Linear::ScaleBoolArray,Linear::ScaleBoolArray,MinusView>);
00219     GECODE_REGISTER3(Linear::LqBoolScale<Linear::ScaleBoolArray,Linear::ScaleBoolArray,ZeroIntView>);
00220     GECODE_REGISTER1(Linear::NqBoolInt<BoolView>);
00221     GECODE_REGISTER3(Linear::NqBoolScale<Linear::EmptyScaleBoolArray,Linear::EmptyScaleBoolArray,IntView>);
00222     GECODE_REGISTER3(Linear::NqBoolScale<Linear::EmptyScaleBoolArray,Linear::EmptyScaleBoolArray,ZeroIntView>);
00223     GECODE_REGISTER3(Linear::NqBoolScale<Linear::EmptyScaleBoolArray,Linear::ScaleBoolArray,IntView>);
00224     GECODE_REGISTER3(Linear::NqBoolScale<Linear::EmptyScaleBoolArray,Linear::ScaleBoolArray,ZeroIntView>);
00225     GECODE_REGISTER3(Linear::NqBoolScale<Linear::ScaleBoolArray,Linear::EmptyScaleBoolArray,IntView>);
00226     GECODE_REGISTER3(Linear::NqBoolScale<Linear::ScaleBoolArray,Linear::EmptyScaleBoolArray,ZeroIntView>);
00227     GECODE_REGISTER3(Linear::NqBoolScale<Linear::ScaleBoolArray,Linear::ScaleBoolArray,IntView>);
00228     GECODE_REGISTER3(Linear::NqBoolScale<Linear::ScaleBoolArray,Linear::ScaleBoolArray,ZeroIntView>);
00229     GECODE_REGISTER2(Linear::NqBoolView<BoolView,IntView>);
00230     GECODE_REGISTER2(Linear::NqBoolView<BoolView,MinusView>);
00231   }
00232 
00233 }
00234 
00235 // STATISTICS: int-post