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

dom.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 Dom {
00044 
00050 
00051      class Val : public Test {
00052      protected:
00054        Gecode::FloatVal c;
00055      public:
00057        Val(int n, Gecode::FloatVal c0, Gecode::FloatNum st)
00058          : Test("Dom::Val::"+str(n)+"::"+str(c0),
00059                 n,-3,3,st,CPLT_ASSIGNMENT,n==1), c(c0) {
00060          testsubsumed = false;
00061        }
00063        virtual MaybeType solution(const Assignment& x) const {
00064          for (int i=x.size(); i--; )
00065            if ((x[i].max() > c.max()) || (x[i].min() < c.min()))
00066              return MT_FALSE;
00067          return MT_TRUE;
00068        }
00070        virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
00071          if (x.size() == 1)
00072            Gecode::dom(home, x[0], c);
00073          else
00074            Gecode::dom(home, x, c);
00075        }
00077        virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x,
00078                          Gecode::Reify r) {
00079          assert(x.size() == 1);
00080          Gecode::dom(home, x[0], c, r);
00081        }
00082      };
00083 
00085      class Num : public Test {
00086      protected:
00088        Gecode::FloatNum min;
00090        Gecode::FloatNum max;
00091      public:
00093        Num(int n, Gecode::FloatNum min0, Gecode::FloatNum max0,
00094            Gecode::FloatNum st)
00095          : Test("Dom::Num::"+str(n)+"::"+str(min0)+"::"+str(max0),
00096                 n,-3,3,st,CPLT_ASSIGNMENT,n==1), min(min0), max(max0) {
00097          testsubsumed = false;
00098        }
00100        virtual MaybeType solution(const Assignment& x) const {
00101          if (max < min)
00102            return MT_FALSE;
00103          for (int i=x.size(); i--; )
00104            if ((x[i].max() > max) || (x[i].min() < min))
00105              return MT_FALSE;
00106          return MT_TRUE;
00107        }
00109        virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
00110          if (x.size() == 1)
00111            Gecode::dom(home, x[0], min, max);
00112          else
00113            Gecode::dom(home, x, min, max);
00114        }
00116        virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x,
00117                          Gecode::Reify r) {
00118          assert(x.size() == 1);
00119          Gecode::dom(home, x[0], min, max, r);
00120        }
00121      };
00122 
00124      class Create {
00125      public:
00127        Create(void) {
00128          using namespace Gecode;
00129          FloatNum step = 0.7;
00130          for (int c=-4; c<=4; c++) {
00131            (void) new Val(1,c,step);
00132            (void) new Val(2,c,step);
00133            for (int d=-3; d<=3; d++) {
00134              (void) new Num(1,c,d,step);
00135              (void) new Num(2,c,d,step);
00136            }
00137          }
00138        }
00139      };
00140 
00141      Create c;
00143 
00144    }
00145 
00146 }}
00147 
00148 // STATISTICS: test-float