Generated on Tue Apr 18 10:21:38 2017 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  *  Last modified:
00012  *     $Date: 2015-01-20 20:48:23 +0100 (Tue, 20 Jan 2015) $ by $Author: schulte $
00013  *     $Revision: 14369 $
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 Dom {
00048 
00054 
00055      class Val : public Test {
00056      protected:
00058        Gecode::FloatVal c;
00059      public:
00061        Val(int n, Gecode::FloatVal c0, Gecode::FloatNum st)
00062          : Test("Dom::Val::"+str(n)+"::"+str(c0),
00063                 n,-3,3,st,CPLT_ASSIGNMENT,n==1), c(c0) {
00064          testsubsumed = false;
00065        }
00067        virtual MaybeType solution(const Assignment& x) const {
00068          for (int i=x.size(); i--; )
00069            if ((x[i].max() > c.max()) || (x[i].min() < c.min()))
00070              return MT_FALSE;
00071          return MT_TRUE;
00072        }
00074        virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
00075          if (x.size() == 1)
00076            Gecode::dom(home, x[0], c);
00077          else
00078            Gecode::dom(home, x, c);
00079        }
00081        virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x,
00082                          Gecode::Reify r) {
00083          assert(x.size() == 1);
00084          Gecode::dom(home, x[0], c, r);
00085        }
00086      };
00087 
00089      class Num : public Test {
00090      protected:
00092        Gecode::FloatNum min;
00094        Gecode::FloatNum max;
00095      public:
00097        Num(int n, Gecode::FloatNum min0, Gecode::FloatNum max0,
00098            Gecode::FloatNum st)
00099          : Test("Dom::Num::"+str(n)+"::"+str(min0)+"::"+str(max0),
00100                 n,-3,3,st,CPLT_ASSIGNMENT,n==1), min(min0), max(max0) {
00101          testsubsumed = false;
00102        }
00104        virtual MaybeType solution(const Assignment& x) const {
00105          if (max < min)
00106            return MT_FALSE;
00107          for (int i=x.size(); i--; )
00108            if ((x[i].max() > max) || (x[i].min() < min))
00109              return MT_FALSE;
00110          return MT_TRUE;
00111        }
00113        virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
00114          if (x.size() == 1)
00115            Gecode::dom(home, x[0], min, max);
00116          else
00117            Gecode::dom(home, x, min, max);
00118        }
00120        virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x,
00121                          Gecode::Reify r) {
00122          assert(x.size() == 1);
00123          Gecode::dom(home, x[0], min, max, r);
00124        }
00125      };
00126 
00128      class Create {
00129      public:
00131        Create(void) {
00132          using namespace Gecode;
00133          FloatNum step = 0.7;
00134          for (int c=-4; c<=4; c++) {
00135            (void) new Val(1,c,step);
00136            (void) new Val(2,c,step);
00137            for (int d=-3; d<=3; d++) {
00138              (void) new Num(1,c,d,step);
00139              (void) new Num(2,c,d,step);
00140            }
00141          }
00142        }
00143      };
00144 
00145      Create c;
00147 
00148    }
00149 
00150 }}
00151 
00152 // STATISTICS: test-float