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