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>
*
* Copyright:
* Christopher Mears, 2011
* Christian Schulte, 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/int.hh"
namespace Test { namespace Int {
namespace Precede {
class Single : public Test {
private:
int s, t;
public:
Single(int s0, int t0)
: Test("Precede::Single::"+str(s0)+"<"+str(t0),8,1,4),
s(s0), t(t0) {}
virtual bool solution(const Assignment& x) const {
int n = x.size();
for (int i = 0 ; i < n ; i++) {
if (x[i] == t)
return false;
if (x[i] == s)
return true;
}
return true;
}
virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
Gecode::precede(home, x, s, t);
}
};
class Multi : public Test {
private:
Gecode::IntArgs c;
public:
Multi(const Gecode::IntArgs& c0)
: Test("Precede::Multi::"+str(c0),6,1,5), c(c0) {
contest = CTL_NONE;
}
virtual bool solution(const Assignment& x) const {
for (int j=0; j<c.size()-1; j++)
for (int i=0; i<x.size(); i++) {
if (x[i] == c[j+1])
return false;
if (x[i] == c[j])
break;
}
return true;
}
virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
Gecode::precede(home, x, c);
}
};
Single _a(2, 3);
Single _b(1, 4);
Multi _c(Gecode::IntArgs({1,2,3}));
Multi _d(Gecode::IntArgs({3,2,1}));
Multi _e(Gecode::IntArgs({4,2,3,1}));
}
}}
// STATISTICS: test-int
Gecode::IntArgs
Passing integer arguments.
Definition int.hh:628
Gecode::IntVarArray
Integer variable array.
Definition int.hh:763
Gecode::Space
Computation spaces.
Definition core.hpp:1742
Test::Int::Assignment
Base class for assignments
Definition int.hh:59
Test::Int::Assignment::size
int size(void) const
Return number of variables.
Definition int.hpp:46
Test::Int::Precede::Multi
Test for multiple value precedence constraint
Definition precede.cpp:73
Test::Int::Precede::Multi::post
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
Definition precede.cpp:95
Test::Int::Precede::Multi::Multi
Multi(const Gecode::IntArgs &c0)
Create and register test.
Definition precede.cpp:79
Test::Int::Precede::Multi::solution
virtual bool solution(const Assignment &x) const
Test whether x is solution
Definition precede.cpp:84
Test::Int::Precede::Single
Test for single value precedence constraint
Definition precede.cpp:46
Test::Int::Precede::Single::post
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
Definition precede.cpp:67
Test::Int::Precede::Single::Single
Single(int s0, int t0)
Create and register test.
Definition precede.cpp:52
Test::Int::Precede::Single::solution
virtual bool solution(const Assignment &x) const
Test whether x is solution
Definition precede.cpp:56
Test::Int::Test::str
static std::string str(Gecode::IntPropLevel ipl)
Map integer propagation level to string.
Definition int.hpp:209
Test::Int::Test::contest
ConTestLevel contest
Whether to test for certain consistency.
Definition int.hh:236
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
Test::Int::Precede
Tests for value precedence constraints
Definition precede.cpp:43
Test::Int::Precede::_b
Single _b(1, 4)
Test::Int::Precede::_e
Multi _e(Gecode::IntArgs({4, 2, 3, 1}))
Test::Int::Precede::_a
Single _a(2, 3)
Test::Int::Precede::_c
Multi _c(Gecode::IntArgs({1, 2, 3}))
Test::Int::Precede::_d
Multi _d(Gecode::IntArgs({3, 2, 1}))
Test::Int
Testing finite domain integers.
Definition int.cpp:40
Test::Int::CTL_NONE
@ CTL_NONE
No consistency-test.
Definition int.hh:140
Test
General test support.
Definition afc.cpp:39
int.hh