int.hh
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.
*
*/
#ifndef __GECODE_TEST_INT_HH__
#define __GECODE_TEST_INT_HH__
#include "test/test.hh"
#include <gecode/int.hh>
namespace Test {
namespace Int {
class Assignment {
protected:
int n;
Gecode::IntSet d;
public:
Assignment(int n0, const Gecode::IntSet& d0);
virtual bool operator()(void) const = 0;
virtual void operator++(void) = 0;
virtual int operator[](int i) const = 0;
int size(void) const;
virtual ~Assignment(void);
};
class CpltAssignment : public Assignment {
protected:
Gecode::IntSetValues* dsv;
public:
CpltAssignment(int n, const Gecode::IntSet& d);
virtual bool operator()(void) const;
virtual void operator++(void);
virtual int operator[](int i) const;
virtual ~CpltAssignment(void);
};
class RandomAssignment : public Assignment {
protected:
int* vals;
int a;
int randval(void);
public:
RandomAssignment(int n, const Gecode::IntSet& d, int a);
virtual bool operator()(void) const;
virtual void operator++(void);
virtual int operator[](int i) const;
virtual ~RandomAssignment(void);
};
class RandomMixAssignment : public Assignment {
protected:
int* vals;
int a;
int _n1;
Gecode::IntSet _d1;
int randval(const Gecode::IntSet& d);
public:
RandomMixAssignment(int n0, const Gecode::IntSet& d0,
int n1, const Gecode::IntSet& d1, int a0);
virtual bool operator()(void) const;
virtual void operator++(void);
virtual int operator[](int i) const;
virtual ~RandomMixAssignment(void);
};
enum ConTestLevel {
CTL_NONE,
CTL_DOMAIN,
CTL_BOUNDS_D,
CTL_BOUNDS_Z,
};
class Test;
class TestSpace : public Gecode::Space {
public:
Gecode::IntSet d;
Gecode::IntVarArray x;
Gecode::Reify r;
Test* test;
bool reified;
TestSpace(int n, Gecode::IntSet& d, Test* t);
TestSpace(int n, Gecode::IntSet& d, Test* t, Gecode::ReifyMode rm);
TestSpace(TestSpace& s);
virtual Gecode::Space* copy(void);
bool assigned(void) const;
void post(void);
bool failed(void);
int rndvar(void);
void rndrel(const Assignment& a, int i, Gecode::IntRelType& irt, int& v);
void rel(int i, Gecode::IntRelType irt, int n);
void rel(bool sol);
void assign(const Assignment& a, bool skip=false);
void bound(void);
void prune(int i, bool bounds_only);
void prune(void);
bool prune(const Assignment& a, bool testfix);
void disable(void);
void enable(void);
bool disabled(const Assignment& a, TestSpace& c, bool testfix);
unsigned int propagators(void);
};
class Test : public Base {
protected:
int arity;
Gecode::IntSet dom;
bool reified;
int rms;
Gecode::IntPropLevel ipl;
ConTestLevel contest;
bool testsearch;
bool testfix;
bool eqv(void) const;
bool imp(void) const;
bool pmi(void) const;
public:
Test(const std::string& p, const std::string& s,
int a, const Gecode::IntSet& d, bool r=false,
Gecode::IntPropLevel i=Gecode::IPL_DEF);
Test(const std::string& s,
int a, const Gecode::IntSet& d, bool r=false,
Gecode::IntPropLevel i=Gecode::IPL_DEF);
Test(const std::string& p, const std::string& s,
int a, int min, int max, bool r=false,
Gecode::IntPropLevel i=Gecode::IPL_DEF);
Test(const std::string& s,
int a, int min, int max, bool r=false,
Gecode::IntPropLevel i=Gecode::IPL_DEF);
virtual Assignment* assignment(void) const;
virtual bool solution(const Assignment&) const = 0;
virtual bool ignore(const Assignment&) const;
virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) = 0;
virtual void post(Gecode::Space& home, Gecode::IntVarArray& x,
Gecode::Reify r);
virtual bool run(void);
static std::string str(Gecode::IntPropLevel ipl);
static std::string str(Gecode::IntRelType irl);
static std::string str(Gecode::BoolOpType bot);
static std::string str(bool b);
static std::string str(int i);
static std::string str(const Gecode::IntArgs& i);
template<class T> static bool cmp(T x, Gecode::IntRelType r, T y);
};
class IntPropLevels {
private:
static const Gecode::IntPropLevel ipls[3];
int i;
public:
IntPropLevels(void);
bool operator()(void) const;
void operator++(void);
Gecode::IntPropLevel ipl(void) const;
};
class IntPropBasicAdvanced {
private:
static const Gecode::IntPropLevel ipls[3];
int i;
public:
IntPropBasicAdvanced(void);
bool operator()(void) const;
void operator++(void);
Gecode::IntPropLevel ipl(void) const;
};
class IntRelTypes {
private:
static const Gecode::IntRelType irts[6];
int i;
public:
IntRelTypes(void);
void reset(void);
bool operator()(void) const;
void operator++(void);
Gecode::IntRelType irt(void) const;
};
class BoolOpTypes {
private:
static const Gecode::BoolOpType bots[5];
int i;
public:
BoolOpTypes(void);
bool operator()(void) const;
void operator++(void);
Gecode::BoolOpType bot(void) const;
};
}
}
std::ostream& operator<<(std::ostream& os, const Test::Int::Assignment& a);
#include "test/int.hpp"
#endif
// STATISTICS: test-int
Gecode::IntArgs
Passing integer arguments.
Definition int.hh:628
Gecode::IntSetValues
Value iterator for integer sets.
Definition int.hh:333
Gecode::IntSet
Integer sets.
Definition int.hh:174
Gecode::IntVarArray
Integer variable array.
Definition int.hh:763
Gecode::Reify
Reification specification.
Definition int.hh:876
Gecode::Space
Computation spaces.
Definition core.hpp:1742
Gecode::Space::c
struct Gecode::Space::@055132133326276162005044145100211202071356247106::@155123175027073262103111264343315000271204104107 c
Data available only during copying.
Test::Base::Base
Base(const std::string &s)
Create and register test with name s.
Definition test.cpp:59
Test::Int::Assignment
Base class for assignments
Definition int.hh: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::operator++
virtual void operator++(void)=0
Move to next assignment.
Test::Int::Assignment::size
int size(void) const
Return number of variables.
Definition int.hpp:46
Test::Int::Assignment::operator()
virtual bool operator()(void) const =0
Test whether all assignments have been iterated.
Test::Int::Assignment::operator[]
virtual int operator[](int i) const =0
Return value for variable i.
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::CpltAssignment::operator++
virtual void operator++(void)
Move to next assignment.
Definition int.cpp:48
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::RandomAssignment::operator++
virtual void operator++(void)
Move to next assignment.
Definition int.cpp:63
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::operator++
virtual void operator++(void)
Move to next assignment.
Definition int.cpp:70
Test::Int::RandomMixAssignment::randval
int randval(const Gecode::IntSet &d)
Definition int.hpp:109
Test::Int::TestSpace::r
Gecode::Reify r
Reification information.
Definition int.hh:156
Test::Int::TestSpace::TestSpace
TestSpace(int n, Gecode::IntSet &d, Test *t)
Create test space without reification.
Definition int.cpp:91
Test::Int::TestSpace::d
Gecode::IntSet d
Initial domain.
Definition int.hh:152
Test::Int::TestSpace::rndrel
void rndrel(const Assignment &a, int i, Gecode::IntRelType &irt, int &v)
Randomly select a pruning rel for variable i.
Definition int.cpp:181
Test::Int::TestSpace::test
Test * test
The test currently run.
Definition int.hh:158
Test::Int::TestSpace::copy
virtual Gecode::Space * copy(void)
Copy space during cloning.
Definition int.cpp:132
Test::Int::TestSpace::post
void post(void)
Post propagator.
Definition int.cpp:145
Test::Int::TestSpace::assigned
bool assigned(void) const
Test whether all variables are assigned.
Definition int.cpp:137
Test::Int::TestSpace::prune
void prune(void)
Prune some random values for some random variable.
Definition int.cpp:316
Test::Int::TestSpace::bound
void bound(void)
Assing a random variable to a random bound.
Definition int.cpp:272
Test::Int::TestSpace::assign
void assign(const Assignment &a, bool skip=false)
Assign all (or all but one, if skip is true) variables to values in a.
Definition int.cpp:259
Test::Int::TestSpace::failed
bool failed(void)
Compute a fixpoint and check for failure.
Definition int.cpp:158
Test::Int::TestSpace::reified
bool reified
Whether the test is for a reified propagator.
Definition int.hh:160
Test::Int::TestSpace::rndvar
int rndvar(void)
Randomly select an unassigned variable.
Definition int.cpp:170
Test::Int::TestSpace::disabled
bool disabled(const Assignment &a, TestSpace &c, bool testfix)
Prune values also in a space c with disabled propagators, but not those in assignment a.
Definition int.cpp:373
Test::Int::TestSpace::disable
void disable(void)
Disable propagators in space and compute fixpoint (make all idle).
Definition int.cpp:367
Test::Int::TestSpace::x
Gecode::IntVarArray x
Variables to be tested.
Definition int.hh:154
Test::Int::TestSpace::enable
void enable(void)
Enable propagators in space.
Definition int.cpp:362
Test::Int::TestSpace::rel
void rel(int i, Gecode::IntRelType irt, int n)
Perform integer tell operation on x[i].
Definition int.cpp:233
Test::Int::TestSpace::propagators
unsigned int propagators(void)
Return the number of propagators.
Definition int.cpp:421
Test::Int::Test::pmi
bool pmi(void) const
Test whether reverse implication as reification mode is supported.
Definition int.hpp:161
Test::Int::Test::run
virtual bool run(void)
Perform test.
Definition int.cpp:471
Test::Int::Test::reified
bool reified
Does the constraint also exist as reified constraint.
Definition int.hh:230
Test::Int::Test::ignore
virtual bool ignore(const Assignment &) const
Whether to ignore assignment for reification.
Definition int.cpp:462
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::post
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)=0
Post constraint.
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::solution
virtual bool solution(const Assignment &) const =0
Check for solution.
Test::Int::Test::assignment
virtual Assignment * assignment(void) const
Create assignment.
Definition int.cpp:440
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
int.hh
Gecode::IntRelType
IntRelType
Relation types for integers.
Definition int.hh:925
Gecode::ReifyMode
ReifyMode
Mode for reification.
Definition int.hh:848
Gecode::BoolOpType
BoolOpType
Operation types for Booleans.
Definition int.hh:950
Gecode::IntPropLevel
IntPropLevel
Propagation levels for integer propagators.
Definition int.hh:974
Gecode::IPL_DEF
@ IPL_DEF
Simple propagation levels.
Definition int.hh:976
Test::Int
Testing finite domain integers.
Definition int.cpp:40
Test::Int::ConTestLevel
ConTestLevel
Level of consistency to test for.
Definition int.hh:139
Test::Int::CTL_BOUNDS_Z
@ CTL_BOUNDS_Z
Test for bounds(z)-consistency.
Definition int.hh:143
Test::Int::CTL_BOUNDS_D
@ CTL_BOUNDS_D
Test for bounds(d)-consistency.
Definition int.hh:142
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
operator<<
std::basic_ostream< Char, Traits > & operator<<(std::basic_ostream< Char, Traits > &os, const Dictionary &d)
Print statistics summary.
Definition scowl.hpp:13625
int.hpp
test.hh