Generated on Sun Feb 17 15:24:09 2019 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  *  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 "test/float.hh"
00037 
00038 #include <gecode/minimodel.hh>
00039 
00040 namespace Test { namespace Float {
00041 
00043    namespace Rel {
00044 
00050 
00051      class FloatVarXY : public Test {
00052      protected:
00054        Gecode::FloatRelType frt;
00055      public:
00057        FloatVarXY(Gecode::FloatRelType frt0, int n, Gecode::FloatNum st)
00058          : Test("Rel::Float::Var::XY::"+str(frt0)+"::"+str(n),
00059                 n+1,-3,3,st,CPLT_ASSIGNMENT,n==1),
00060            frt(frt0) {
00061          testsubsumed = false;
00062        }
00064        virtual MaybeType solution(const Assignment& x) const {
00065          if (x.size() == 2) {
00066            return cmp(x[0],frt,x[1]);
00067          } else {
00068            MaybeType r1 = cmp(x[0],frt,x[2]);
00069            MaybeType r2 = cmp(x[1],frt,x[2]);
00070            if ((r1 == MT_TRUE) && (r2 == MT_TRUE)) return MT_TRUE;
00071            else if ((r1 == MT_FALSE) || (r2 == MT_FALSE)) return MT_FALSE;
00072            else return MT_MAYBE;
00073          }
00074        }
00076        virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
00077          using namespace Gecode;
00078          if (x.size() == 2) {
00079            rel(home, x[0], frt, x[1]);
00080          } else {
00081            FloatVarArgs y(2);
00082            y[0]=x[0]; y[1]=x[1];
00083            rel(home, y, frt, x[2]);
00084          }
00085        }
00087        virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x,
00088                          Gecode::Reify r) {
00089          assert(x.size() == 2);
00090          Gecode::rel(home, x[0], frt, x[1], r);
00091        }
00092      };
00093 
00095      class FloatVarXX : public Test {
00096      protected:
00098        Gecode::FloatRelType frt;
00099      public:
00101        FloatVarXX(Gecode::FloatRelType frt0, Gecode::FloatNum st)
00102          : Test("Rel::Float::Var::XX::"+str(frt0),
00103                 1,-3,3,st,CPLT_ASSIGNMENT,true),
00104            frt(frt0) {
00105          testsubsumed = false;
00106        }
00108        virtual MaybeType solution(const Assignment& x) const {
00109          return cmp(x[0],frt,x[0]);
00110        }
00112        virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
00113          Gecode::rel(home, x[0], frt, x[0]);
00114        }
00116        virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x,
00117                          Gecode::Reify r) {
00118          Gecode::rel(home, x[0], frt, x[0], r);
00119        }
00120      };
00121 
00123      class FloatFloat : public Test {
00124      protected:
00126        Gecode::FloatRelType frt;
00128        Gecode::FloatVal c;
00129      public:
00131        FloatFloat(Gecode::FloatRelType frt0, int n, Gecode::FloatNum c0,
00132                   Gecode::FloatNum st)
00133          : Test("Rel::Float::Float::"+str(frt0)+"::"+str(n)+"::"+str(c0),
00134                 n,-3,3,st,CPLT_ASSIGNMENT,n==1),
00135            frt(frt0), c(c0) {
00136          testsubsumed = false;
00137        }
00139        virtual MaybeType solution(const Assignment& x) const {
00140          if (x.size() == 1) {
00141            return cmp(x[0],frt,c);
00142          } else {
00143            return cmp(x[0],frt,c) & cmp(x[1],frt,c);
00144          }
00145        }
00147        virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
00148          using namespace Gecode;
00149          if (x.size() == 1)
00150            rel(home, x[0], frt, c);
00151          else
00152            rel(home, x, frt, c);
00153        }
00155        virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x,
00156                          Gecode::Reify r) {
00157          assert(x.size() == 1);
00158          Gecode::rel(home, x[0], frt, c, r);
00159        }
00160      };
00161 
00163      class Create {
00164      public:
00166        Create(void) {
00167          using namespace Gecode;
00168          Gecode::FloatNum step = 0.7;
00169          for (FloatRelTypes frts; frts(); ++frts) {
00170           (void) new FloatVarXY(frts.frt(),1,step);
00171           (void) new FloatVarXY(frts.frt(),2,step);
00172           (void) new FloatVarXX(frts.frt(),step);
00173            for (int c=-4; c<=4; c++) {
00174              (void) new FloatFloat(frts.frt(),1,c,step);
00175              (void) new FloatFloat(frts.frt(),2,c,step);
00176            }
00177          }
00178        }
00179      };
00180 
00181      Create c;
00183 
00184    }
00185 
00186 }}
00187 
00188 // STATISTICS: test-float