Generated on Wed Jan 4 17:49:10 2006 for Gecode by doxygen 1.4.6

linear.cc

Go to the documentation of this file.
00001 /*
00002  *  Main authors:
00003  *     Christian Schulte <schulte@gecode.org>
00004  *
00005  *  Copyright:
00006  *     Christian Schulte, 2002
00007  *
00008  *  Last modified:
00009  *     $Date: 2005-08-03 17:17:11 +0200 (Wed, 03 Aug 2005) $ by $Author: schulte $
00010  *     $Revision: 2126 $
00011  *
00012  *  This file is part of Gecode, the generic constraint
00013  *  development environment:
00014  *     http://www.gecode.org
00015  *
00016  *  See the file "LICENSE" for information on usage and
00017  *  redistribution of this file, and for a
00018  *     DISCLAIMER OF ALL WARRANTIES.
00019  *
00020  */
00021 
00022 #include "int/linear.hh"
00023 
00024 namespace Gecode {
00025 
00026   using namespace Int;
00027 
00028   /*
00029    * Exported post functions
00030    *
00031    */
00032 
00033   void
00034   linear(Space* home,
00035          const IntVarArgs& x, IntRelType r, int c, IntConLevel) {
00036     if (home->failed()) return;
00037     GECODE_AUTOARRAY(Linear::Term, t, x.size());
00038     for (int i = x.size(); i--; ) {
00039       t[i].a=1; t[i].x=x[i];
00040     }
00041     Linear::post(home,t,x.size(),r,c);
00042   }
00043 
00044   void
00045   linear(Space* home,
00046          const IntVarArgs& x, IntRelType r, int c, BoolVar b, IntConLevel) {
00047     if (home->failed()) return;
00048     GECODE_AUTOARRAY(Linear::Term, t, x.size());
00049     for (int i = x.size(); i--; ) {
00050       t[i].a=1; t[i].x=x[i];
00051     }
00052     Linear::post(home,t,x.size(),r,c,b);
00053   }
00054 
00055   void
00056   linear(Space* home,
00057          const IntArgs& a, const IntVarArgs& x, IntRelType r, int c, 
00058          IntConLevel) {
00059     if (a.size() != x.size())
00060       throw ArgumentSizeMismatch("Int::linear");
00061     if (home->failed()) return;
00062     GECODE_AUTOARRAY(Linear::Term, t, x.size());
00063     for (int i = x.size(); i--; ) {
00064       t[i].a=a[i]; t[i].x=x[i];
00065     }
00066     Linear::post(home,t,x.size(),r,c);
00067   }
00068 
00069   void
00070   linear(Space* home,
00071          const IntArgs& a, const IntVarArgs& x, IntRelType r, int c, BoolVar b,
00072          IntConLevel) {
00073     if (a.size() != x.size())
00074       throw ArgumentSizeMismatch("Int::linear");
00075     if (home->failed()) return;
00076     GECODE_AUTOARRAY(Linear::Term, t, x.size());
00077     for (int i = x.size(); i--; ) {
00078       t[i].a=a[i]; t[i].x=x[i];
00079     }
00080     Linear::post(home,t,x.size(),r,c,b);
00081   }
00082 
00083   void
00084   linear(Space* home,
00085          const IntVarArgs& x, IntRelType r, IntVar y, IntConLevel) {
00086     if (home->failed()) return;
00087     GECODE_AUTOARRAY(Linear::Term, t, x.size()+1);
00088     for (int i = x.size(); i--; ) {
00089       t[i].a=1; t[i].x=x[i];
00090     }
00091     t[x.size()].a=-1; t[x.size()].x=y;
00092     Linear::post(home,t,x.size()+1,r,0);
00093   }
00094 
00095   void
00096   linear(Space* home,
00097          const IntVarArgs& x, IntRelType r, IntVar y, BoolVar b, 
00098          IntConLevel) {
00099     if (home->failed()) return;
00100     GECODE_AUTOARRAY(Linear::Term, t, x.size()+1);
00101     for (int i = x.size(); i--; ) {
00102       t[i].a=1; t[i].x=x[i];
00103     }
00104     t[x.size()].a=-1; t[x.size()].x=y;
00105     Linear::post(home,t,x.size()+1,r,0,b);
00106   }
00107 
00108   void
00109   linear(Space* home,
00110          const IntArgs& a, const IntVarArgs& x, IntRelType r, IntVar y, 
00111          IntConLevel) {
00112     if (a.size() != x.size())
00113       throw ArgumentSizeMismatch("Int::linear");
00114     if (home->failed()) return;
00115     GECODE_AUTOARRAY(Linear::Term, t, x.size()+1);
00116     for (int i = x.size(); i--; ) {
00117       t[i].a=a[i]; t[i].x=x[i];
00118     }
00119     t[x.size()].a=-1; t[x.size()].x=y;
00120     Linear::post(home,t,x.size()+1,r,0);
00121   }
00122 
00123   void
00124   linear(Space* home,
00125          const IntArgs& a, const IntVarArgs& x, IntRelType r, IntVar y, 
00126          BoolVar b, IntConLevel) {
00127     if (a.size() != x.size())
00128       throw ArgumentSizeMismatch("Int::linear");
00129     if (home->failed()) return;
00130     GECODE_AUTOARRAY(Linear::Term, t, x.size()+1);
00131     for (int i = x.size(); i--; ) {
00132       t[i].a=a[i]; t[i].x=x[i];
00133     }
00134     t[x.size()].a=-1; t[x.size()].x=y;
00135     Linear::post(home,t,x.size()+1,r,0,b);
00136   }
00137 
00138   void
00139   linear(Space* home, const BoolVarArgs& x, IntRelType r, int c,
00140          IntConLevel) {
00141     if (home->failed()) return;
00142     ViewArray<BoolView> xv(home,x);
00143     ConstIntView cv(c);
00144     switch (r) {
00145     case IRT_EQ:
00146       GECODE_ES_FAIL(home,Linear::EqBool<ConstIntView>::post(home,xv,0,cv));
00147       break;
00148     case IRT_NQ:
00149       GECODE_ES_FAIL(home,Linear::NqBool<ConstIntView>::post(home,xv,0,cv));
00150       break;
00151     case IRT_LQ:
00152       GECODE_ES_FAIL(home,Linear::LqBool<ConstIntView>::post(home,xv,0,cv));
00153       break;
00154     case IRT_LE:
00155       GECODE_ES_FAIL(home,Linear::LqBool<ConstIntView>::post(home,xv,-1,cv));
00156       break;
00157     case IRT_GQ:
00158       GECODE_ES_FAIL(home,Linear::GqBool<ConstIntView>::post(home,xv,0,cv));
00159       break;
00160     case IRT_GR:
00161       GECODE_ES_FAIL(home,Linear::GqBool<ConstIntView>::post(home,xv,1,cv));
00162       break;
00163     default:
00164       throw UnknownRelation("Int::linear");
00165     }
00166   }
00167 
00168   void
00169   linear(Space* home, const BoolVarArgs& x, IntRelType r, IntVar y,
00170          IntConLevel) {
00171     if (home->failed()) return;
00172     ViewArray<BoolView> xv(home,x);
00173     switch (r) {
00174     case IRT_EQ:
00175       GECODE_ES_FAIL(home,Linear::EqBool<IntView>::post(home,xv,0,y));
00176       break;
00177     case IRT_NQ:
00178       GECODE_ES_FAIL(home,Linear::NqBool<IntView>::post(home,xv,0,y));
00179       break;
00180     case IRT_LQ:
00181       GECODE_ES_FAIL(home,Linear::LqBool<IntView>::post(home,xv,0,y));
00182       break;
00183     case IRT_LE:
00184       GECODE_ES_FAIL(home,Linear::LqBool<IntView>::post(home,xv,-1,y));
00185       break;
00186     case IRT_GQ:
00187       GECODE_ES_FAIL(home,Linear::GqBool<IntView>::post(home,xv,0,y));
00188       break;
00189     case IRT_GR:
00190       GECODE_ES_FAIL(home,Linear::GqBool<IntView>::post(home,xv,1,y));
00191       break;
00192     default:
00193       throw UnknownRelation("Int::linear");
00194     }
00195   }
00196 
00197 }
00198 
00199 // STATISTICS: int-post
00200