Generated on Tue Apr 18 10:21:40 2017 for Gecode by doxygen 1.6.3

rel.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  *     Vincent Barichard <Vincent.Barichard@univ-angers.fr>
00006  *
00007  *  Copyright:
00008  *     Christian Schulte, 2005
00009  *     Vincent Barichard, 2012
00010  *
00011  *  Last modified:
00012  *     $Date: 2016-04-19 17:19:45 +0200 (Tue, 19 Apr 2016) $ by $Author: schulte $
00013  *     $Revision: 14967 $
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 "test/float.hh"
00041 
00042 #include <gecode/minimodel.hh>
00043 
00044 namespace Test { namespace Float {
00045 
00047    namespace Rel {
00048 
00054 
00055      class FloatVarXY : public Test {
00056      protected:
00058        Gecode::FloatRelType frt;
00059      public:
00061        FloatVarXY(Gecode::FloatRelType frt0, int n, Gecode::FloatNum st)
00062          : Test("Rel::Float::Var::XY::"+str(frt0)+"::"+str(n),
00063                 n+1,-3,3,st,CPLT_ASSIGNMENT,n==1),
00064            frt(frt0) {
00065          testsubsumed = false;
00066        }
00068        virtual MaybeType solution(const Assignment& x) const {
00069          if (x.size() == 2) {
00070            return cmp(x[0],frt,x[1]);
00071          } else {
00072            MaybeType r1 = cmp(x[0],frt,x[2]);
00073            MaybeType r2 = cmp(x[1],frt,x[2]);
00074            if ((r1 == MT_TRUE) && (r2 == MT_TRUE)) return MT_TRUE;
00075            else if ((r1 == MT_FALSE) || (r2 == MT_FALSE)) return MT_FALSE;
00076            else return MT_MAYBE;
00077          }
00078        }
00080        virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
00081          using namespace Gecode;
00082          if (x.size() == 2) {
00083            rel(home, x[0], frt, x[1]);
00084          } else {
00085            FloatVarArgs y(2);
00086            y[0]=x[0]; y[1]=x[1];
00087            rel(home, y, frt, x[2]);
00088          }
00089        }
00091        virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x,
00092                          Gecode::Reify r) {
00093          assert(x.size() == 2);
00094          Gecode::rel(home, x[0], frt, x[1], r);
00095        }
00096      };
00097 
00099      class FloatVarXX : public Test {
00100      protected:
00102        Gecode::FloatRelType frt;
00103      public:
00105        FloatVarXX(Gecode::FloatRelType frt0, Gecode::FloatNum st)
00106          : Test("Rel::Float::Var::XX::"+str(frt0),
00107                 1,-3,3,st,CPLT_ASSIGNMENT,true),
00108            frt(frt0) {
00109          testsubsumed = false;
00110        }
00112        virtual MaybeType solution(const Assignment& x) const {
00113          return cmp(x[0],frt,x[0]);
00114        }
00116        virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
00117          Gecode::rel(home, x[0], frt, x[0]);
00118        }
00120        virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x,
00121                          Gecode::Reify r) {
00122          Gecode::rel(home, x[0], frt, x[0], r);
00123        }
00124      };
00125 
00127      class FloatFloat : public Test {
00128      protected:
00130        Gecode::FloatRelType frt;
00132        Gecode::FloatVal c;
00133      public:
00135        FloatFloat(Gecode::FloatRelType frt0, int n, Gecode::FloatNum c0,
00136                   Gecode::FloatNum st)
00137          : Test("Rel::Float::Float::"+str(frt0)+"::"+str(n)+"::"+str(c0),
00138                 n,-3,3,st,CPLT_ASSIGNMENT,n==1),
00139            frt(frt0), c(c0) {
00140          testsubsumed = false;
00141        }
00143        virtual MaybeType solution(const Assignment& x) const {
00144          if (x.size() == 1) {
00145            return cmp(x[0],frt,c);
00146          } else {
00147            return cmp(x[0],frt,c) & cmp(x[1],frt,c);
00148          }
00149        }
00151        virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
00152          using namespace Gecode;
00153          if (x.size() == 1)
00154            rel(home, x[0], frt, c);
00155          else
00156            rel(home, x, frt, c);
00157        }
00159        virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x,
00160                          Gecode::Reify r) {
00161          assert(x.size() == 1);
00162          Gecode::rel(home, x[0], frt, c, r);
00163        }
00164      };
00165 
00167      class Create {
00168      public:
00170        Create(void) {
00171          using namespace Gecode;
00172          Gecode::FloatNum step = 0.7;
00173          for (FloatRelTypes frts; frts(); ++frts) {
00174           (void) new FloatVarXY(frts.frt(),1,step);
00175           (void) new FloatVarXY(frts.frt(),2,step);
00176           (void) new FloatVarXX(frts.frt(),step);
00177            for (int c=-4; c<=4; c++) {
00178              (void) new FloatFloat(frts.frt(),1,c,step);
00179              (void) new FloatFloat(frts.frt(),2,c,step);
00180            }
00181          }
00182        }
00183      };
00184 
00185      Create c;
00187 
00188    }
00189 
00190 }}
00191 
00192 // STATISTICS: test-float