int.hpp
Go to the documentation of this file.
/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
/*
* Main authors:
* Christian Schulte <schulte@gecode.org>
* Mikael Lagerkvist <lagerkvist@gecode.org>
*
* Copyright:
* Christian Schulte, 2005
* Mikael Lagerkvist, 2006
*
* 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.
*
*/
namespace Test { namespace Int {
/*
* Assignments
*
*/
inline
Assignment::Assignment(int n0, const Gecode::IntSet& d0)
: n(n0), d(d0) {}
inline int
Assignment::size(void) const {
return n;
}
inline
Assignment::~Assignment(void) {}
inline
CpltAssignment::CpltAssignment(int n, const Gecode::IntSet& d)
: Assignment(n,d),
dsv(new Gecode::IntSetValues[static_cast<unsigned int>(n)]) {
for (int i=n; i--; )
dsv[i].init(d);
}
inline bool
CpltAssignment::operator()(void) const {
return dsv[0]();
}
inline int
CpltAssignment::operator[](int i) const {
assert((i>=0) && (i<n));
return dsv[i].val();
}
inline
CpltAssignment::~CpltAssignment(void) {
delete [] dsv;
}
forceinline int
RandomAssignment::randval(void) {
unsigned int skip = Base::rand(d.size());
for (Gecode::IntSetRanges it(d); true; ++it) {
if (it.width() > skip)
return it.min() + static_cast<int>(skip);
skip -= it.width();
}
GECODE_NEVER;
return 0;
}
inline
RandomAssignment::RandomAssignment(int n, const Gecode::IntSet& d, int a0)
: Assignment(n,d), vals(new int[static_cast<size_t>(n)]), a(a0) {
for (int i=n; i--; )
vals[i] = randval();
}
inline bool
RandomAssignment::operator()(void) const {
return a>0;
}
inline int
RandomAssignment::operator[](int i) const {
assert((i>=0) && (i<n));
return vals[i];
}
inline
RandomAssignment::~RandomAssignment(void) {
delete [] vals;
}
forceinline int
RandomMixAssignment::randval(const Gecode::IntSet& d) {
unsigned int skip = Base::rand(d.size());
for (Gecode::IntSetRanges it(d); true; ++it) {
if (it.width() > skip)
return it.min() + static_cast<int>(skip);
skip -= it.width();
}
GECODE_NEVER;
return 0;
}
inline
RandomMixAssignment::RandomMixAssignment(int n0, const Gecode::IntSet& d0,
int n1, const Gecode::IntSet& d1,
int a0)
: Assignment(n0+n1,d0),vals(new int[static_cast<size_t>(n0+n1)]),
a(a0),_n1(n1),_d1(d1) {
for (int i=n0; i--; )
vals[i] = randval(d);
for (int i=n1; i--; )
vals[n0+i] = randval(_d1);
}
inline bool
RandomMixAssignment::operator()(void) const {
return a>0;
}
inline int
RandomMixAssignment::operator[](int i) const {
assert((i>=0) && (i<n));
return vals[i];
}
inline
RandomMixAssignment::~RandomMixAssignment(void) {
delete [] vals;
}
/*
* Tests with integer constraints
*
*/
forceinline bool
Test::eqv(void) const {
return reified && ((rms & (1 << Gecode::RM_EQV)) != 0);
}
forceinline bool
Test::imp(void) const {
return reified && ((rms & (1 << Gecode::RM_IMP)) != 0);
}
forceinline bool
Test::pmi(void) const {
return reified && ((rms & (1 << Gecode::RM_PMI)) != 0);
}
inline
Test::Test(const std::string& p, const std::string& s,
int a, const Gecode::IntSet& d, bool r,
Gecode::IntPropLevel i)
: Base(p+s), arity(a), dom(d),
reified(r), rms((1 << Gecode::RM_EQV) |
(1 << Gecode::RM_IMP) |
(1 << Gecode::RM_PMI)),
ipl(i), contest(ipl == Gecode::IPL_DOM ? CTL_DOMAIN : CTL_NONE),
testsearch(true), testfix(true) {}
inline
Test::Test(const std::string& s,
int a, const Gecode::IntSet& d, bool r,
Gecode::IntPropLevel i)
: Base("Int::"+s), arity(a), dom(d),
reified(r), rms((1 << Gecode::RM_EQV) |
(1 << Gecode::RM_IMP) |
(1 << Gecode::RM_PMI)),
ipl(i), contest(ipl == Gecode::IPL_DOM ? CTL_DOMAIN : CTL_NONE),
testsearch(true), testfix(true) {}
inline
Test::Test(const std::string& p, const std::string& s,
int a, int min, int max, bool r,
Gecode::IntPropLevel i)
: Base(p+s), arity(a), dom(min,max),
reified(r), rms((1 << Gecode::RM_EQV) |
(1 << Gecode::RM_IMP) |
(1 << Gecode::RM_PMI)),
ipl(i), contest(ipl == Gecode::IPL_DOM ? CTL_DOMAIN : CTL_NONE),
testsearch(true), testfix(true) {}
inline
Test::Test(const std::string& s,
int a, int min, int max, bool r, Gecode::IntPropLevel i)
: Base("Int::"+s), arity(a), dom(min,max),
reified(r), rms((1 << Gecode::RM_EQV) |
(1 << Gecode::RM_IMP) |
(1 << Gecode::RM_PMI)),
ipl(i), contest(ipl == Gecode::IPL_DOM ? CTL_DOMAIN : CTL_NONE),
testsearch(true), testfix(true) {}
inline
std::string
Test::str(Gecode::IntPropLevel ipl) {
using namespace Gecode;
std::stringstream s;
switch (vbd(ipl)) {
case IPL_VAL: s << "Val"; break;
case IPL_BND: s << "Bnd"; break;
case IPL_DOM: s << "Dom"; break;
default: s << "Def"; break;
}
if (ipl & IPL_BASIC) s << "+B";
if (ipl & IPL_ADVANCED) s << "+A";
return s.str();
}
inline
std::string
Test::str(Gecode::IntRelType irt) {
using namespace Gecode;
switch (irt) {
case IRT_LQ: return "Lq";
case IRT_LE: return "Le";
case IRT_GQ: return "Gq";
case IRT_GR: return "Gr";
case IRT_EQ: return "Eq";
case IRT_NQ: return "Nq";
default: ;
}
GECODE_NEVER;
return "NONE";
}
inline std::string
Test::str(Gecode::BoolOpType bot) {
using namespace Gecode;
switch (bot) {
case BOT_AND: return "And";
case BOT_OR: return "Or";
case BOT_IMP: return "Imp";
case BOT_EQV: return "Eqv";
case BOT_XOR: return "Xor";
default: GECODE_NEVER;
}
GECODE_NEVER;
return "NONE";
}
inline
std::string
Test::str(bool b) {
std::stringstream s;
if (b)
s << "+";
else
s << "-";
return s.str();
}
inline
std::string
Test::str(int i) {
std::stringstream s;
s << i;
return s.str();
}
inline
std::string
Test::str(const Gecode::IntArgs& x) {
std::string s = "";
for (int i=0; i<x.size()-1; i++)
s += str(x[i]) + ",";
return "[" + s + str(x[x.size()-1]) + "]";
}
template<class T>
inline bool
Test::cmp(T x, Gecode::IntRelType r, T y) {
using namespace Gecode;
switch (r) {
case IRT_EQ: return x == y;
case IRT_NQ: return x != y;
case IRT_LQ: return x <= y;
case IRT_LE: return x < y;
case IRT_GR: return x > y;
case IRT_GQ: return x >= y;
default: ;
}
return false;
}
inline
IntPropLevels::IntPropLevels(void)
: i(sizeof(ipls)/sizeof(Gecode::IntPropLevel)-1) {}
inline bool
IntPropLevels::operator()(void) const {
return i>=0;
}
inline void
IntPropLevels::operator++(void) {
i--;
}
inline Gecode::IntPropLevel
IntPropLevels::ipl(void) const {
return ipls[i];
}
inline
IntPropBasicAdvanced::IntPropBasicAdvanced(void)
: i(sizeof(ipls)/sizeof(Gecode::IntPropLevel)-1) {}
inline bool
IntPropBasicAdvanced::operator()(void) const {
return i>=0;
}
inline void
IntPropBasicAdvanced::operator++(void) {
i--;
}
inline Gecode::IntPropLevel
IntPropBasicAdvanced::ipl(void) const {
return ipls[i];
}
inline
IntRelTypes::IntRelTypes(void)
: i(sizeof(irts)/sizeof(Gecode::IntRelType)-1) {}
inline void
IntRelTypes::reset(void) {
i = sizeof(irts)/sizeof(Gecode::IntRelType)-1;
}
inline bool
IntRelTypes::operator()(void) const {
return i>=0;
}
inline void
IntRelTypes::operator++(void) {
i--;
}
inline Gecode::IntRelType
IntRelTypes::irt(void) const {
return irts[i];
}
inline
BoolOpTypes::BoolOpTypes(void)
: i(sizeof(bots)/sizeof(Gecode::BoolOpType)-1) {}
inline bool
BoolOpTypes::operator()(void) const {
return i>=0;
}
inline void
BoolOpTypes::operator++(void) {
i--;
}
inline Gecode::BoolOpType
BoolOpTypes::bot(void) const {
return bots[i];
}
}}
// STATISTICS: test-int
Gecode::ArgArrayBase::size
int size(void) const
Return size of array (number of elements).
Definition array.hpp:1607
Gecode::IntArgs
Passing integer arguments.
Definition int.hh:628
Gecode::IntSetRanges
Range iterator for integer sets.
Definition int.hh:292
Gecode::IntSet
Integer sets.
Definition int.hh:174
Test::Base::rand
static Gecode::Support::RandomGenerator rand
Random number generator.
Definition test.hh:134
Test::Base::Base
Base(const std::string &s)
Create and register test with name s.
Definition test.cpp:59
Test::Int::Assignment::d
Gecode::IntSet d
Domain for each variable.
Definition int.hh:62
Test::Int::Assignment::n
int n
Number of variables.
Definition int.hh:61
Test::Int::Assignment::~Assignment
virtual ~Assignment(void)
Destructor.
Definition int.hpp:50
Test::Int::Assignment::Assignment
Assignment(int n0, const Gecode::IntSet &d0)
Initialize assignments for n0 variables and values d0.
Definition int.hpp:43
Test::Int::Assignment::size
int size(void) const
Return number of variables.
Definition int.hpp:46
Test::Int::BoolOpTypes::BoolOpTypes
BoolOpTypes(void)
Initialize iterator.
Definition int.hpp:356
Test::Int::BoolOpTypes::operator()
bool operator()(void) const
Test whether iterator is done.
Definition int.hpp:359
Test::Int::BoolOpTypes::bot
Gecode::BoolOpType bot(void) const
Return current operation type.
Definition int.hpp:367
Test::Int::BoolOpTypes::operator++
void operator++(void)
Increment to next operation type.
Definition int.hpp:363
Test::Int::CpltAssignment::CpltAssignment
CpltAssignment(int n, const Gecode::IntSet &d)
Initialize assignments for n0 variables and values d0.
Definition int.hpp:54
Test::Int::CpltAssignment::operator[]
virtual int operator[](int i) const
Return value for variable i.
Definition int.hpp:65
Test::Int::CpltAssignment::~CpltAssignment
virtual ~CpltAssignment(void)
Destructor.
Definition int.hpp:70
Test::Int::CpltAssignment::operator()
virtual bool operator()(void) const
Test whether all assignments have been iterated.
Definition int.hpp:61
Test::Int::CpltAssignment::dsv
Gecode::IntSetValues * dsv
Iterator for each variable.
Definition int.hh:81
Test::Int::IntPropBasicAdvanced::ipl
Gecode::IntPropLevel ipl(void) const
Return current level.
Definition int.hpp:330
Test::Int::IntPropBasicAdvanced::operator()
bool operator()(void) const
Test whether iterator is done.
Definition int.hpp:322
Test::Int::IntPropBasicAdvanced::IntPropBasicAdvanced
IntPropBasicAdvanced(void)
Initialize iterator.
Definition int.hpp:319
Test::Int::IntPropBasicAdvanced::operator++
void operator++(void)
Increment to next level.
Definition int.hpp:326
Test::Int::IntPropLevels::IntPropLevels
IntPropLevels(void)
Initialize iterator.
Definition int.hpp:302
Test::Int::IntPropLevels::ipl
Gecode::IntPropLevel ipl(void) const
Return current level.
Definition int.hpp:313
Test::Int::IntPropLevels::operator()
bool operator()(void) const
Test whether iterator is done.
Definition int.hpp:305
Test::Int::IntPropLevels::operator++
void operator++(void)
Increment to next level.
Definition int.hpp:309
Test::Int::IntRelTypes::operator++
void operator++(void)
Increment to next relation type.
Definition int.hpp:347
Test::Int::IntRelTypes::operator()
bool operator()(void) const
Test whether iterator is done.
Definition int.hpp:343
Test::Int::IntRelTypes::reset
void reset(void)
Reset iterator.
Definition int.hpp:339
Test::Int::IntRelTypes::IntRelTypes
IntRelTypes(void)
Initialize iterator.
Definition int.hpp:336
Test::Int::IntRelTypes::irt
Gecode::IntRelType irt(void) const
Return current relation type.
Definition int.hpp:351
Test::Int::RandomAssignment::operator[]
virtual int operator[](int i) const
Return value for variable i.
Definition int.hpp:99
Test::Int::RandomAssignment::~RandomAssignment
virtual ~RandomAssignment(void)
Destructor.
Definition int.hpp:104
Test::Int::RandomAssignment::RandomAssignment
RandomAssignment(int n, const Gecode::IntSet &d, int a)
Initialize for a assignments for n0 variables and values d0.
Definition int.hpp:88
Test::Int::RandomAssignment::a
int a
How many assigments still to be generated Generate new value according to domain.
Definition int.hh:99
Test::Int::RandomAssignment::vals
int * vals
The current values for the variables.
Definition int.hh:98
Test::Int::RandomAssignment::randval
int randval(void)
Definition int.hpp:76
Test::Int::RandomAssignment::operator()
virtual bool operator()(void) const
Test whether all assignments have been iterated.
Definition int.hpp:95
Test::Int::RandomMixAssignment::_n1
int _n1
How many variables in the second set.
Definition int.hh:120
Test::Int::RandomMixAssignment::RandomMixAssignment
RandomMixAssignment(int n0, const Gecode::IntSet &d0, int n1, const Gecode::IntSet &d1, int a0)
Initialize for a assignments for n0 variables and values d0.
Definition int.hpp:121
Test::Int::RandomMixAssignment::_d1
Gecode::IntSet _d1
Domain for second set of variables Generate new value according to domain d.
Definition int.hh:121
Test::Int::RandomMixAssignment::operator[]
virtual int operator[](int i) const
Return value for variable i.
Definition int.hpp:138
Test::Int::RandomMixAssignment::operator()
virtual bool operator()(void) const
Test whether all assignments have been iterated.
Definition int.hpp:133
Test::Int::RandomMixAssignment::~RandomMixAssignment
virtual ~RandomMixAssignment(void)
Destructor.
Definition int.hpp:144
Test::Int::RandomMixAssignment::a
int a
How many assigments still to be generated.
Definition int.hh:119
Test::Int::RandomMixAssignment::vals
int * vals
The current values for the variables.
Definition int.hh:118
Test::Int::RandomMixAssignment::randval
int randval(const Gecode::IntSet &d)
Definition int.hpp:109
Test::Int::Test::pmi
bool pmi(void) const
Test whether reverse implication as reification mode is supported.
Definition int.hpp:161
Test::Int::Test::reified
bool reified
Does the constraint also exist as reified constraint.
Definition int.hh:230
Test::Int::Test::testsearch
bool testsearch
Whether to perform search test.
Definition int.hh:238
Test::Int::Test::testfix
bool testfix
Whether to perform fixpoint test.
Definition int.hh:240
Test::Int::Test::rms
int rms
Which reification modes are supported.
Definition int.hh:232
Test::Int::Test::Test
Test(const std::string &p, const std::string &s, int a, const Gecode::IntSet &d, bool r=false, Gecode::IntPropLevel i=Gecode::IPL_DEF)
Constructor.
Definition int.hpp:165
Test::Int::Test::ipl
Gecode::IntPropLevel ipl
Propagation level.
Definition int.hh:234
Test::Int::Test::eqv
bool eqv(void) const
Test whether equivalence as reification mode is supported.
Definition int.hpp:153
Test::Int::Test::arity
int arity
Number of variables.
Definition int.hh:226
Test::Int::Test::str
static std::string str(Gecode::IntPropLevel ipl)
Map integer propagation level to string.
Definition int.hpp:209
Test::Int::Test::cmp
static bool cmp(T x, Gecode::IntRelType r, T y)
Compare x and y with respect to r.
Definition int.hpp:285
Test::Int::Test::dom
Gecode::IntSet dom
Domain of variables.
Definition int.hh:228
Test::Int::Test::imp
bool imp(void) const
Test whether implication as reification mode is supported.
Definition int.hpp:157
Test::Int::Test::contest
ConTestLevel contest
Whether to test for certain consistency.
Definition int.hh:236
Gecode::IntRelType
IntRelType
Relation types for integers.
Definition int.hh:925
Gecode::BoolOpType
BoolOpType
Operation types for Booleans.
Definition int.hh:950
Gecode::IntPropLevel
IntPropLevel
Propagation levels for integer propagators.
Definition int.hh:974
Gecode::IRT_EQ
@ IRT_EQ
Equality ( ).
Definition int.hh:926
Gecode::IRT_NQ
@ IRT_NQ
Disequality ( ).
Definition int.hh:927
Gecode::IRT_GQ
@ IRT_GQ
Greater or equal ( ).
Definition int.hh:930
Gecode::IRT_LE
@ IRT_LE
Less ( ).
Definition int.hh:929
Gecode::IRT_GR
@ IRT_GR
Greater ( ).
Definition int.hh:931
Gecode::IRT_LQ
@ IRT_LQ
Less or equal ( ).
Definition int.hh:928
Gecode::RM_IMP
@ RM_IMP
Implication for reification.
Definition int.hh:862
Gecode::RM_PMI
@ RM_PMI
Inverse implication for reification.
Definition int.hh:869
Gecode::RM_EQV
@ RM_EQV
Equivalence for reification (default).
Definition int.hh:855
Gecode::BOT_OR
@ BOT_OR
Disjunction.
Definition int.hh:952
Gecode::BOT_EQV
@ BOT_EQV
Equivalence.
Definition int.hh:954
Gecode::BOT_IMP
@ BOT_IMP
Implication.
Definition int.hh:953
Gecode::BOT_XOR
@ BOT_XOR
Exclusive or.
Definition int.hh:955
Gecode::BOT_AND
@ BOT_AND
Conjunction.
Definition int.hh:951
Gecode::IPL_BASIC
@ IPL_BASIC
Use basic propagation algorithm.
Definition int.hh:981
Gecode::IPL_DOM
@ IPL_DOM
Domain propagation Options: basic versus advanced propagation.
Definition int.hh:979
Gecode::IPL_VAL
@ IPL_VAL
Value propagation.
Definition int.hh:977
Gecode::IPL_ADVANCED
@ IPL_ADVANCED
Use advanced propagation algorithm.
Definition int.hh:982
Gecode::IPL_BND
@ IPL_BND
Bounds propagation.
Definition int.hh:978
Gecode
Gecode toplevel namespace
Gecode::vbd
IntPropLevel vbd(IntPropLevel ipl)
Extract value, bounds, or domain propagation from propagation level.
Definition ipl.hpp:37
Test::Int
Testing finite domain integers.
Definition int.cpp:40
Test::Int::CTL_NONE
@ CTL_NONE
No consistency-test.
Definition int.hh:140
Test::Int::CTL_DOMAIN
@ CTL_DOMAIN
Test for domain-consistency.
Definition int.hh:141
Test
General test support.
Definition afc.cpp:39
Test::r
Region r
Definition region.cpp:65
forceinline
#define forceinline
Definition config.hpp:187
GECODE_NEVER
#define GECODE_NEVER
Assert that this command is never executed.
Definition macros.hpp:56