Generated on Wed Nov 5 2014 05:18:19 for Gecode by doxygen 1.7.6.1
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: 2013-02-12 20:48:02 +0100 (Tue, 12 Feb 2013) $ by $Author: vbarichard $
00013  *     $Revision: 13281 $
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) {}
00066        virtual MaybeType solution(const Assignment& x) const {
00067          if (x.size() == 2) {
00068            return cmp(x[0],frt,x[1]);
00069          } else {
00070            MaybeType r1 = cmp(x[0],frt,x[2]);
00071            MaybeType r2 = cmp(x[1],frt,x[2]);
00072            if ((r1 == MT_TRUE) && (r2 == MT_TRUE)) return MT_TRUE;
00073            else if ((r1 == MT_FALSE) || (r2 == MT_FALSE)) return MT_FALSE;
00074            else return MT_MAYBE;
00075          }
00076        }
00078        virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
00079          using namespace Gecode;
00080          if (x.size() == 2) {
00081            rel(home, x[0], frt, x[1]);
00082          } else {
00083            FloatVarArgs y(2);
00084            y[0]=x[0]; y[1]=x[1];
00085            rel(home, y, frt, x[2]);
00086          }
00087        }
00089        virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x,
00090                          Gecode::Reify r) {
00091          assert(x.size() == 2);
00092          Gecode::rel(home, x[0], frt, x[1], r);
00093        }
00094      };
00095 
00097      class FloatVarXX : public Test {
00098      protected:
00100        Gecode::FloatRelType frt;
00101      public:
00103        FloatVarXX(Gecode::FloatRelType frt0, Gecode::FloatNum st)
00104          : Test("Rel::Float::Var::XX::"+str(frt0),
00105                 1,-3,3,st,CPLT_ASSIGNMENT,true),
00106            frt(frt0) { }
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) {}
00137        virtual MaybeType solution(const Assignment& x) const {
00138          if (x.size() == 1) {
00139            return cmp(x[0],frt,c);
00140          } else {
00141            return cmp(x[0],frt,c) & cmp(x[1],frt,c);
00142          }
00143        }
00145        virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
00146          using namespace Gecode;
00147          if (x.size() == 1)
00148            rel(home, x[0], frt, c);
00149          else
00150            rel(home, x, frt, c);
00151        }
00153        virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x,
00154                          Gecode::Reify r) {
00155          assert(x.size() == 1);
00156          Gecode::rel(home, x[0], frt, c, r);
00157        }
00158      };
00159 
00161      class Create {
00162      public:
00164        Create(void) {
00165          using namespace Gecode;
00166          Gecode::FloatNum step = 0.7;
00167          for (FloatRelTypes frts; frts(); ++frts) {
00168           (void) new FloatVarXY(frts.frt(),1,step);
00169           (void) new FloatVarXY(frts.frt(),2,step);
00170           (void) new FloatVarXX(frts.frt(),step);
00171            for (int c=-4; c<=4; c++) {
00172              (void) new FloatFloat(frts.frt(),1,c,step);
00173              (void) new FloatFloat(frts.frt(),2,c,step);
00174            }
00175          }
00176        }
00177      };
00178 
00179      Create c;
00181 
00182    }
00183 
00184 }}
00185 
00186 // STATISTICS: test-float