precede.cpp
Go to the documentation of this file.
/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
/*
* Main authors:
* Christopher Mears <Chris.Mears@monash.edu>
*
* Contributing authors:
* Christian Schulte <schulte@gecode.org>
* Guido Tack <tack@gecode.org>
*
* Copyright:
* Christopher Mears, 2011
* Christian Schulte, 2011
* Guido Tack, 2011
*
* This file is part of Gecode, the generic constraint
* development environment:
* http://www.gecode.org
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
#include "test/set.hh"
using namespace Gecode;
namespace Test { namespace Set {
namespace Precede {
static IntSet ds(-1,3);
class Single : public SetTest {
private:
int s, t;
bool in(int i, int x) const {
CountableSetRanges xr(ds,x);
Iter::Ranges::Singleton ir(i,i);
return Iter::Ranges::subset(ir,xr);
}
public:
Single(int s0, int t0)
: SetTest("Precede::Single::"+str(s0)+"<"+str(t0),4,ds,false),
s(s0), t(t0) {}
virtual bool solution(const SetAssignment& x) const {
int n = x.size();
for (int i = 0 ; i < n ; i++) {
if (!in(s,x[i]) && in(t,x[i]))
return false;
if (in(s,x[i]) && !in(t,x[i]))
return true;
}
return true;
}
virtual void post(Gecode::Space& home, Gecode::SetVarArray& x,
Gecode::IntVarArray&) {
Gecode::precede(home, x, s, t);
}
};
class Multi : public SetTest {
private:
Gecode::IntArgs c;
bool in(int i, int x) const {
CountableSetRanges xr(ds,x);
Iter::Ranges::Singleton ir(i,i);
return Iter::Ranges::subset(ir,xr);
}
public:
Multi(const Gecode::IntArgs& c0)
: SetTest("Precede::Multi::"+str(c0),4,ds,false), c(c0) {}
virtual bool solution(const SetAssignment& x) const {
for (int j=0; j<c.size()-1; j++)
for (int i=0; i<x.size(); i++) {
if (!in(c[j],x[i]) && in(c[j+1],x[i]))
return false;
if (in(c[j],x[i]) && !in(c[j+1],x[i]))
break;
}
return true;
}
virtual void post(Gecode::Space& home, Gecode::SetVarArray& x,
Gecode::IntVarArray&) {
Gecode::precede(home, x, c);
}
};
Single _a(2, 3);
Single _b(0, 3);
Multi _c(Gecode::IntArgs({1,2,3}));
Multi _d(Gecode::IntArgs({3,2,1}));
Multi _e(Gecode::IntArgs({4,2,3,1}));
}
}}
// STATISTICS: test-set
Gecode::IntArgs
Passing integer arguments.
Definition int.hh:628
Gecode::IntSet
Integer sets.
Definition int.hh:174
Gecode::IntVarArray
Integer variable array.
Definition int.hh:763
Gecode::Iter::Ranges::Singleton
Range iterator for singleton range.
Definition ranges-singleton.hpp:42
Gecode::SetVarArray
Set variable array
Definition set.hh:570
Gecode::Space
Computation spaces.
Definition core.hpp:1742
Test::Set::CountableSetRanges
Range iterator producing subsets of an IntSet.
Definition set.hh:99
Test::Set::Precede::Multi
Test for multiple value precedence constraint
Definition precede.cpp:88
Test::Set::Precede::Multi::Multi
Multi(const Gecode::IntArgs &c0)
Create and register test.
Definition precede.cpp:101
Test::Set::Precede::Multi::post
virtual void post(Gecode::Space &home, Gecode::SetVarArray &x, Gecode::IntVarArray &)
Post constraint on x.
Definition precede.cpp:115
Test::Set::Precede::Multi::solution
virtual bool solution(const SetAssignment &x) const
Test whether x is solution
Definition precede.cpp:104
Test::Set::Precede::Single
Test for single value precedence constraint
Definition precede.cpp:52
Test::Set::Precede::Single::Single
Single(int s0, int t0)
Create and register test.
Definition precede.cpp:66
Test::Set::Precede::Single::post
virtual void post(Gecode::Space &home, Gecode::SetVarArray &x, Gecode::IntVarArray &)
Post constraint on x.
Definition precede.cpp:81
Test::Set::Precede::Single::solution
virtual bool solution(const SetAssignment &x) const
Test whether x is solution
Definition precede.cpp:70
Test::Set::SetAssignment
Generate all set assignments.
Definition set.hh:142
Test::Set::SetAssignment::size
int size(void) const
Return arity.
Definition set.hh:173
Test::Set::SetTest::str
static std::string str(Gecode::SetRelType srt)
Map set relation to string.
Definition set.hpp:46
Test::Set::SetTest::SetTest
SetTest(const std::string &s, int a, const Gecode::IntSet &d, bool r=false, int w=0)
Constructor.
Definition set.hh:304
Gecode::precede
void precede(Home home, const IntVarArgs &x, int s, int t, IntPropLevel=IPL_DEF)
Post propagator that s precedes t in x.
Definition precede.cpp:43
Gecode::Iter::Ranges::subset
bool subset(I &i, J &j)
Check whether range iterator i is subset of range iterator j.
Definition ranges-operations.hpp:97
Gecode
Gecode toplevel namespace
Test::Set::Precede
Tests for value precedence constraints
Definition precede.cpp:47
Test::Set::Precede::_c
Multi _c(Gecode::IntArgs({1, 2, 3}))
Test::Set::Precede::_a
Single _a(2, 3)
Test::Set::Precede::_e
Multi _e(Gecode::IntArgs({4, 2, 3, 1}))
Test::Set::Precede::_b
Single _b(0, 3)
Test::Set::Precede::_d
Multi _d(Gecode::IntArgs({3, 2, 1}))
Test::Set
Testing finite sets.
Definition set.cpp:42
Test
General test support.
Definition afc.cpp:39
set.hh