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  *
00006  *  Copyright:
00007  *     Christian Schulte, 2005
00008  *
00009  *  Last modified:
00010  *     $Date: 2016-10-25 12:52:26 +0200 (Tue, 25 Oct 2016) $ by $Author: schulte $
00011  *     $Revision: 15233 $
00012  *
00013  *  This file is part of Gecode, the generic constraint
00014  *  development environment:
00015  *     http://www.gecode.org
00016  *
00017  *  Permission is hereby granted, free of charge, to any person obtaining
00018  *  a copy of this software and associated documentation files (the
00019  *  "Software"), to deal in the Software without restriction, including
00020  *  without limitation the rights to use, copy, modify, merge, publish,
00021  *  distribute, sublicense, and/or sell copies of the Software, and to
00022  *  permit persons to whom the Software is furnished to do so, subject to
00023  *  the following conditions:
00024  *
00025  *  The above copyright notice and this permission notice shall be
00026  *  included in all copies or substantial portions of the Software.
00027  *
00028  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00029  *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00030  *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00031  *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
00032  *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
00033  *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00034  *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00035  *
00036  */
00037 
00038 #include "test/int.hh"
00039 
00040 namespace Test { namespace Int {
00041 
00043    namespace Dom {
00044 
00050 
00051      class DomInt : public Test {
00052      public:
00054        DomInt(int n)
00055          : Test("Dom::Int::"+str(n),n,-4,4,n == 1,
00056                 Gecode::IPL_DOM) {}
00058        virtual bool solution(const Assignment& x) const {
00059          for (int i=x.size(); i--; )
00060            if (x[i] != -2)
00061              return false;
00062          return true;
00063        }
00065        virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
00066          if (x.size() == 1)
00067            Gecode::dom(home, x[0], -2);
00068          else
00069            Gecode::dom(home, x, -2);
00070        }
00072        virtual void post(Gecode::Space& home, Gecode::IntVarArray& x,
00073                          Gecode::Reify r) {
00074          assert(x.size() == 1);
00075          Gecode::dom(home, x[0], -2, r);
00076        }
00077      };
00078 
00079 
00081      class DomRange : public Test {
00082      public:
00084        DomRange(int n)
00085          : Test("Dom::Range::"+str(n),n,-4,4,n == 1,
00086                 Gecode::IPL_DOM) {}
00088        virtual bool solution(const Assignment& x) const {
00089          for (int i=x.size(); i--; )
00090            if ((x[i] < -2) || (x[i] > 2))
00091              return false;
00092          return true;
00093        }
00095        virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
00096          if (x.size() == 1)
00097            Gecode::dom(home, x[0], -2, 2);
00098          else
00099            Gecode::dom(home, x, -2, 2);
00100        }
00102        virtual void post(Gecode::Space& home, Gecode::IntVarArray& x,
00103                          Gecode::Reify r) {
00104          assert(x.size() == 1);
00105          Gecode::dom(home, x[0], -2, 2, r);
00106        }
00107      };
00108 
00110      class DomRangeEmpty : public Test {
00111      public:
00113        DomRangeEmpty(void) : Test("Dom::Range::Empty",1,-4,4,true) {}
00115        virtual bool solution(const Assignment&) const {
00116          return false;
00117        }
00119        virtual void post(Gecode::Space& home, Gecode::IntVarArray&) {
00120          home.fail();
00121        }
00123        virtual void post(Gecode::Space& home, Gecode::IntVarArray& x,
00124                          Gecode::Reify r) {
00125          Gecode::dom(home, x[0], 3, 2, r);
00126        }
00127      };
00128 
00129 
00130      const int r[4][2] = {
00131        {-4,-3},{-1,-1},{1,1},{3,5}
00132      };
00133      Gecode::IntSet d(r,4);
00134 
00136      class DomDom : public Test {
00137      public:
00139        DomDom(int n)
00140          : Test("Dom::Dom::"+str(n),n,-6,6,n == 1,
00141                 Gecode::IPL_DOM) {}
00143        virtual bool solution(const Assignment& x) const {
00144          for (int i=x.size(); i--; )
00145            if (!(((x[i] >= -4) && (x[i] <= -3)) ||
00146                  ((x[i] >= -1) && (x[i] <= -1)) ||
00147                  ((x[i] >=  1) && (x[i] <=  1)) ||
00148                  ((x[i] >=  3) && (x[i] <=  5))))
00149              return false;
00150          return true;
00151        }
00153        virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
00154          if (x.size() == 1)
00155            Gecode::dom(home, x[0], d);
00156          else
00157            Gecode::dom(home, x, d);
00158        }
00160        virtual void post(Gecode::Space& home, Gecode::IntVarArray& x,
00161                          Gecode::Reify r) {
00162          assert(x.size() == 1);
00163          Gecode::dom(home, x[0], d, r);
00164        }
00165      };
00166 
00167      DomInt di1(1);
00168      DomInt di3(3);
00169      DomRange dr1(1);
00170      DomRange dr3(3);
00171      DomDom dd1(1);
00172      DomDom dd3(3);
00173      DomRangeEmpty dre;
00175 
00176    }
00177 }}
00178 
00179 // STATISTICS: test-int
00180