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

linear.cpp

Go to the documentation of this file.
00001 /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
00002 /*
00003 o *  Main authors:
00004  *     Christian Schulte <schulte@gecode.org>
00005  *     Vincent Barichard <Vincent.Barichard@univ-angers.fr>
00006  *
00007  *  Copyright:
00008  *     Christian Schulte, 2002
00009  *     Vincent Barichard, 2012
00010  *
00011  *  This file is part of Gecode, the generic constraint
00012  *  development environment:
00013  *     http://www.gecode.org
00014  *
00015  *  Permission is hereby granted, free of charge, to any person obtaining
00016  *  a copy of this software and associated documentation files (the
00017  *  "Software"), to deal in the Software without restriction, including
00018  *  without limitation the rights to use, copy, modify, merge, publish,
00019  *  distribute, sublicense, and/or sell copies of the Software, and to
00020  *  permit persons to whom the Software is furnished to do so, subject to
00021  *  the following conditions:
00022  *
00023  *  The above copyright notice and this permission notice shall be
00024  *  included in all copies or substantial portions of the Software.
00025  *
00026  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00027  *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00028  *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00029  *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
00030  *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
00031  *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00032  *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00033  *
00034  */
00035 
00036 #include <gecode/float/linear.hh>
00037 
00038 namespace Gecode {
00039 
00040   void
00041   linear(Home home,
00042          const FloatVarArgs& x, FloatRelType frt, FloatVal c) {
00043     using namespace Float;
00044     GECODE_POST;
00045     Region re;
00046     Linear::Term* t = re.alloc<Linear::Term>(x.size());
00047     for (int i = x.size(); i--; ) {
00048       t[i].a=1.0; t[i].x=x[i];
00049     }
00050     Linear::post(home,t,x.size(),frt,c);
00051   }
00052 
00053   void
00054   linear(Home home,
00055          const FloatVarArgs& x, FloatRelType frt, FloatVal c, Reify r) {
00056     using namespace Float;
00057     GECODE_POST;
00058     Region re;
00059     Linear::Term* t = re.alloc<Linear::Term>(x.size());
00060     for (int i = x.size(); i--; ) {
00061       t[i].a=1.0; t[i].x=x[i];
00062     }
00063     Linear::post(home,t,x.size(),frt,c,r);
00064   }
00065 
00066   void
00067   linear(Home home,
00068          const FloatValArgs& a, const FloatVarArgs& x, FloatRelType frt,
00069          FloatVal c) {
00070     using namespace Float;
00071     if (a.size() != x.size())
00072       throw ArgumentSizeMismatch("Float::linear");
00073     GECODE_POST;
00074     Region re;
00075     Linear::Term* t = re.alloc<Linear::Term>(x.size());
00076     for (int i = x.size(); i--; ) {
00077       t[i].a=a[i]; t[i].x=x[i];
00078     }
00079     Linear::post(home,t,x.size(),frt,c);
00080   }
00081 
00082   void
00083   linear(Home home,
00084          const FloatValArgs& a, const FloatVarArgs& x, FloatRelType frt,
00085          FloatVal c, Reify r) {
00086     using namespace Float;
00087     if (a.size() != x.size())
00088       throw ArgumentSizeMismatch("Float::linear");
00089     GECODE_POST;
00090     Region re;
00091     Linear::Term* t = re.alloc<Linear::Term >(x.size());
00092     for (int i = x.size(); i--; ) {
00093       t[i].a=a[i]; t[i].x=x[i];
00094     }
00095     Linear::post(home,t,x.size(),frt,c,r);
00096   }
00097 
00098   void
00099   linear(Home home,
00100          const FloatVarArgs& x, FloatRelType frt, FloatVar y) {
00101     using namespace Float;
00102     GECODE_POST;
00103     Region re;
00104     Linear::Term* t = re.alloc<Linear::Term>(x.size()+1);
00105     for (int i = x.size(); i--; ) {
00106       t[i].a=1.0; t[i].x=x[i];
00107     }
00108     FloatNum min, max;
00109     estimate(t,x.size(),0.0,min,max);
00110     FloatView v(y);
00111     switch (frt) {
00112     case FRT_EQ:
00113       GECODE_ME_FAIL(v.gq(home,min)); GECODE_ME_FAIL(v.lq(home,max));
00114       break;
00115     case FRT_GQ: case FRT_GR:
00116       GECODE_ME_FAIL(v.lq(home,max));
00117       break;
00118     case FRT_LQ: case FRT_LE:
00119       GECODE_ME_FAIL(v.gq(home,min));
00120       break;
00121     default: ;
00122     }
00123     if (home.failed()) return;
00124     t[x.size()].a=-1.0; t[x.size()].x=y;
00125     Linear::post(home,t,x.size()+1,frt,0.0);
00126   }
00127 
00128   void
00129   linear(Home home,
00130          const FloatVarArgs& x, FloatRelType frt, FloatVar y, Reify r) {
00131     using namespace Float;
00132     GECODE_POST;
00133     Region re;
00134     Linear::Term* t = re.alloc<Linear::Term>(x.size()+1);
00135     for (int i = x.size(); i--; ) {
00136       t[i].a=1.0; t[i].x=x[i];
00137     }
00138     t[x.size()].a=-1; t[x.size()].x=y;
00139     Linear::post(home,t,x.size()+1,frt,0.0,r);
00140   }
00141 
00142   void
00143   linear(Home home,
00144          const FloatValArgs& a, const FloatVarArgs& x, FloatRelType frt,
00145          FloatVar y) {
00146     using namespace Float;
00147     if (a.size() != x.size())
00148       throw ArgumentSizeMismatch("Float::linear");
00149     GECODE_POST;
00150     Region re;
00151     Linear::Term* t = re.alloc<Linear::Term>(x.size()+1);
00152     for (int i = x.size(); i--; ) {
00153       t[i].a=a[i]; t[i].x=x[i];
00154     }
00155     FloatNum min, max;
00156     estimate(t,x.size(),0.0,min,max);
00157     FloatView v(y);
00158     switch (frt) {
00159     case FRT_EQ:
00160       GECODE_ME_FAIL(v.gq(home,min)); GECODE_ME_FAIL(v.lq(home,max));
00161       break;
00162     case FRT_GQ: case FRT_GR:
00163       GECODE_ME_FAIL(v.lq(home,max));
00164       break;
00165     case FRT_LQ: case FRT_LE:
00166       GECODE_ME_FAIL(v.gq(home,min));
00167       break;
00168     default: ;
00169     }
00170     if (home.failed()) return;
00171     t[x.size()].a=-1.0; t[x.size()].x=y;
00172     Linear::post(home,t,x.size()+1,frt,0.0);
00173   }
00174 
00175   void
00176   linear(Home home,
00177          const FloatValArgs& a, const FloatVarArgs& x, FloatRelType frt,
00178          FloatVar y, Reify r) {
00179     using namespace Float;
00180     if (a.size() != x.size())
00181       throw ArgumentSizeMismatch("Float::linear");
00182     GECODE_POST;
00183     Region re;
00184     Linear::Term* t = re.alloc<Linear::Term>(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.0; t[x.size()].x=y;
00189     Linear::post(home,t,x.size()+1,frt,0.0,r);
00190   }
00191 
00192 }
00193 
00194 // STATISTICS: float-post