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