Generated on Thu Apr 11 13:59:11 2019 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  *  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/set.hh"
00041 
00042 using namespace Gecode;
00043 
00044 namespace Test { namespace Set {
00045 
00047    namespace Precede {
00048 
00049      static IntSet ds(-1,3);
00050 
00052      class Single : public SetTest {
00053      private:
00055        int s, t;
00056 
00058        bool in(int i, int x) const {
00059          CountableSetRanges xr(ds,x);
00060          Iter::Ranges::Singleton ir(i,i);
00061          return Iter::Ranges::subset(ir,xr);
00062        }
00063 
00064      public:
00066        Single(int s0, int t0)
00067          : SetTest("Precede::Single::"+str(s0)+"<"+str(t0),4,ds,false),
00068            s(s0), t(t0) {}
00070        virtual bool solution(const SetAssignment& x) const {
00071          int n = x.size();
00072          for (int i = 0 ; i < n ; i++) {
00073            if (!in(s,x[i]) && in(t,x[i]))
00074              return false;
00075            if (in(s,x[i]) && !in(t,x[i]))
00076              return true;
00077          }
00078          return true;
00079        }
00081        virtual void post(Gecode::Space& home, Gecode::SetVarArray& x,
00082                          Gecode::IntVarArray&) {
00083          Gecode::precede(home, x, s, t);
00084        }
00085      };
00086 
00088      class Multi : public SetTest {
00089      private:
00091        Gecode::IntArgs c;
00092 
00094        bool in(int i, int x) const {
00095          CountableSetRanges xr(ds,x);
00096          Iter::Ranges::Singleton ir(i,i);
00097          return Iter::Ranges::subset(ir,xr);
00098        }
00099      public:
00101        Multi(const Gecode::IntArgs& c0)
00102          : SetTest("Precede::Multi::"+str(c0),4,ds,false), c(c0) {}
00104        virtual bool solution(const SetAssignment& x) const {
00105          for (int j=0; j<c.size()-1; j++)
00106            for (int i=0; i<x.size(); i++) {
00107              if (!in(c[j],x[i]) && in(c[j+1],x[i]))
00108                return false;
00109              if (in(c[j],x[i]) && !in(c[j+1],x[i]))
00110                break;
00111            }
00112          return true;
00113        }
00115        virtual void post(Gecode::Space& home, Gecode::SetVarArray& x,
00116                          Gecode::IntVarArray&) {
00117          Gecode::precede(home, x, c);
00118        }
00119      };
00120 
00121      Single _a(2, 3);
00122      Single _b(0, 3);
00123 
00124      Multi _c(Gecode::IntArgs({1,2,3}));
00125      Multi _d(Gecode::IntArgs({3,2,1}));
00126      Multi _e(Gecode::IntArgs({4,2,3,1}));
00127 
00128    }
00129 
00130 }}
00131 
00132 // STATISTICS: test-set