Generated on Thu Mar 22 10:39:40 2012 for Gecode by doxygen 1.6.3

precede.cpp

Go to the documentation of this file.
00001 /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
00002 /*
00003  *  Main authors:
00004  *     Christopher Mears <Chris.Mears@monash.edu>
00005  *
00006  *  Contributing authors:
00007  *     Christian Schulte <schulte@gecode.org>
00008  *     Guido Tack <tack@gecode.org>
00009  *
00010  *  Copyright:
00011  *     Christopher Mears, 2011
00012  *     Christian Schulte, 2011
00013  *     Guido Tack, 2011
00014  *
00015  *  Last modified:
00016  *     $Date: 2011-07-12 12:49:06 +0200 (Tue, 12 Jul 2011) $ by $Author: tack $
00017  *     $Revision: 12172 $
00018  *
00019  *  This file is part of Gecode, the generic constraint
00020  *  development environment:
00021  *     http://www.gecode.org
00022  *
00023  *  Permission is hereby granted, free of charge, to any person obtaining
00024  *  a copy of this software and associated documentation files (the
00025  *  "Software"), to deal in the Software without restriction, including
00026  *  without limitation the rights to use, copy, modify, merge, publish,
00027  *  distribute, sublicense, and/or sell copies of the Software, and to
00028  *  permit persons to whom the Software is furnished to do so, subject to
00029  *  the following conditions:
00030  *
00031  *  The above copyright notice and this permission notice shall be
00032  *  included in all copies or substantial portions of the Software.
00033  *
00034  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00035  *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00036  *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00037  *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
00038  *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
00039  *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00040  *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00041  *
00042  */
00043 
00044 #include "test/set.hh"
00045 
00046 using namespace Gecode;
00047 
00048 namespace Test { namespace Set {
00049 
00051    namespace Precede {
00052             
00053      static IntSet ds(-1,3);
00054     
00056      class Single : public SetTest {
00057      private:
00059        int s, t;
00060        
00062        bool in(int i, int x) const {
00063          CountableSetRanges xr(ds,x);
00064          Iter::Ranges::Singleton ir(i,i);
00065          return Iter::Ranges::subset(ir,xr);
00066        }
00067        
00068      public:
00070        Single(int s0, int t0)
00071          : SetTest("Precede::Single::"+str(s0)+"<"+str(t0),4,ds,false),
00072            s(s0), t(t0) {}
00074        virtual bool solution(const SetAssignment& x) const {
00075          int n = x.size();
00076          for (int i = 0 ; i < n ; i++) {
00077            if (!in(s,x[i]) && in(t,x[i]))
00078              return false;
00079            if (in(s,x[i]) && !in(t,x[i]))
00080              return true;
00081          }
00082          return true;
00083        }
00085        virtual void post(Gecode::Space& home, Gecode::SetVarArray& x,
00086                          Gecode::IntVarArray&) {
00087          Gecode::precede(home, x, s, t);
00088        }
00089      };
00090      
00092      class Multi : public SetTest {
00093      private:
00095        Gecode::IntArgs c;
00096 
00098        bool in(int i, int x) const {
00099          CountableSetRanges xr(ds,x);
00100          Iter::Ranges::Singleton ir(i,i);
00101          return Iter::Ranges::subset(ir,xr);
00102        }
00103      public:
00105        Multi(const Gecode::IntArgs& c0)
00106          : SetTest("Precede::Multi::"+str(c0),4,ds,false), c(c0) {}
00108        virtual bool solution(const SetAssignment& x) const {
00109          for (int j=0; j<c.size()-1; j++)
00110            for (int i=0; i<x.size(); i++) {
00111              if (!in(c[j],x[i]) && in(c[j+1],x[i]))
00112                return false;
00113              if (in(c[j],x[i]) && !in(c[j+1],x[i]))
00114                break;
00115            }
00116          return true;
00117        }
00119        virtual void post(Gecode::Space& home, Gecode::SetVarArray& x,
00120                          Gecode::IntVarArray&) {
00121          Gecode::precede(home, x, c);
00122        }
00123      };
00124      
00125      Single _a(2, 3);
00126      Single _b(0, 3);
00127 
00128      Multi _c(Gecode::IntArgs(3, 1,2,3));
00129      Multi _d(Gecode::IntArgs(3, 3,2,1));
00130      Multi _e(Gecode::IntArgs(4, 4,2,3,1));
00131 
00132    }
00133 
00134 }}
00135 
00136 // STATISTICS: test-set