Generated on Thu Mar 22 10:39:36 2012 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: 2010-08-23 18:53:25 +0200 (Mon, 23 Aug 2010) $ by $Author: tack $
00011  *     $Revision: 11358 $
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) : Test("Dom::Int::"+str(n),n,-4,4,n == 1) {}
00056        virtual bool solution(const Assignment& x) const {
00057          for (int i=x.size(); i--; )
00058            if (x[i] != -2)
00059              return false;
00060          return true;
00061        }
00063        virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
00064          if (x.size() == 1)
00065            Gecode::dom(home, x[0], -2);
00066          else
00067            Gecode::dom(home, x, -2);
00068        }
00070        virtual void post(Gecode::Space& home, Gecode::IntVarArray& x,
00071                          Gecode::BoolVar b) {
00072          assert(x.size() == 1);
00073          Gecode::dom(home, x[0], -2, b);
00074        }
00075      };
00076 
00077 
00079      class DomRange : public Test {
00080      public:
00082        DomRange(int n) : Test("Dom::Range::"+str(n),n,-4,4,n == 1) {}
00084        virtual bool solution(const Assignment& x) const {
00085          for (int i=x.size(); i--; )
00086            if ((x[i] < -2) || (x[i] > 2))
00087              return false;
00088          return true;
00089        }
00091        virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
00092          if (x.size() == 1)
00093            Gecode::dom(home, x[0], -2, 2);
00094          else
00095            Gecode::dom(home, x, -2, 2);
00096        }
00098        virtual void post(Gecode::Space& home, Gecode::IntVarArray& x,
00099                          Gecode::BoolVar b) {
00100          assert(x.size() == 1);
00101          Gecode::dom(home, x[0], -2, 2, b);
00102        }
00103      };
00104 
00106      class DomRangeEmpty : public Test {
00107      public:
00109        DomRangeEmpty(void) : Test("Dom::Range::Empty",1,-4,4,true) {}
00111        virtual bool solution(const Assignment&) const {
00112          return false;
00113        }
00115        virtual void post(Gecode::Space& home, Gecode::IntVarArray&) {
00116          home.fail();
00117        }
00119        virtual void post(Gecode::Space& home, Gecode::IntVarArray& x,
00120                          Gecode::BoolVar b) {
00121          Gecode::dom(home, x[0], 3, 2, b);
00122        }
00123      };
00124 
00125 
00126      const int r[4][2] = {
00127        {-4,-3},{-1,-1},{1,1},{3,5}
00128      };
00129      Gecode::IntSet d(r,4);
00130 
00132      class DomDom : public Test {
00133      public:
00135        DomDom(int n) : Test("Dom::Dom::"+str(n),n,-6,6,n == 1) {}
00137        virtual bool solution(const Assignment& x) const {
00138          for (int i=x.size(); i--; )
00139            if (!(((x[i] >= -4) && (x[i] <= -3)) ||
00140                  ((x[i] >= -1) && (x[i] <= -1)) ||
00141                  ((x[i] >=  1) && (x[i] <=  1)) ||
00142                  ((x[i] >=  3) && (x[i] <=  5))))
00143              return false;
00144          return true;
00145        }
00147        virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
00148          if (x.size() == 1)
00149            Gecode::dom(home, x[0], d);
00150          else
00151            Gecode::dom(home, x, d);
00152        }
00154        virtual void post(Gecode::Space& home, Gecode::IntVarArray& x,
00155                          Gecode::BoolVar b) {
00156          assert(x.size() == 1);
00157          Gecode::dom(home, x[0], d, b);
00158        }
00159      };
00160 
00161      DomInt di1(1);
00162      DomInt di3(3);
00163      DomRange dr1(1);
00164      DomRange dr3(3);
00165      DomDom dd1(1);
00166      DomDom dd3(3);
00167      DomRangeEmpty dre;
00169 
00170    }
00171 }}
00172 
00173 // STATISTICS: test-int
00174