float.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>
* Vincent Barichard <Vincent.Barichard@univ-angers.fr>
*
* Copyright:
* Christian Schulte, 2005
* Mikael Lagerkvist, 2006
* Vincent Barichard, 2012
*
* 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_FLOAT_HH__
#define __GECODE_TEST_FLOAT_HH__
#include "test/test.hh"
#include <gecode/float.hh>
namespace Test {
namespace Float {
enum MaybeType {
MT_FALSE = 0, //< Does hold
MT_TRUE, //< Does not hold
MT_MAYBE //< Might or might not hold
};
MaybeType operator &(MaybeType a, MaybeType b);
enum AssignmentType {
CPLT_ASSIGNMENT = 0,
RANDOM_ASSIGNMENT,
EXTEND_ASSIGNMENT
};
class Test;
class Assignment {
protected:
int n;
Gecode::FloatVal d;
public:
Assignment(int n0, const Gecode::FloatVal& d0);
virtual bool operator()(void) const = 0;
virtual void operator++(void) = 0;
virtual Gecode::FloatVal operator[](int i) const = 0;
virtual void set(int i, const Gecode::FloatVal& val) = 0;
int size(void) const;
virtual ~Assignment(void);
};
class CpltAssignment : public Assignment {
protected:
Gecode::FloatVal* dsv;
Gecode::FloatNum step;
public:
CpltAssignment(int n, const Gecode::FloatVal& d, Gecode::FloatNum s);
virtual bool operator()(void) const;
virtual void operator++(void);
virtual Gecode::FloatVal operator[](int i) const;
virtual void set(int i, const Gecode::FloatVal& val);
virtual ~CpltAssignment(void);
};
class ExtAssignment : public Assignment {
protected:
const Test* curPb;
Gecode::FloatVal* dsv;
Gecode::FloatNum step;
public:
ExtAssignment(int n, const Gecode::FloatVal& d, Gecode::FloatNum s, const Test * pb);
virtual bool operator()(void) const;
virtual void operator++(void);
virtual Gecode::FloatVal operator[](int i) const;
virtual void set(int i, const Gecode::FloatVal& val);
virtual ~ExtAssignment(void);
};
class RandomAssignment : public Assignment {
protected:
Gecode::FloatVal* vals;
int a;
Gecode::FloatNum randval(void);
public:
RandomAssignment(int n, const Gecode::FloatVal& d, int a);
virtual bool operator()(void) const;
virtual void operator++(void);
virtual Gecode::FloatVal operator[](int i) const;
virtual void set(int i, const Gecode::FloatVal& val);
virtual ~RandomAssignment(void);
};
class TestSpace : public Gecode::Space {
public:
Gecode::FloatVal d;
Gecode::FloatNum step;
Gecode::FloatVarArray x;
Gecode::Reify r;
Test* test;
bool reified;
TestSpace(int n, Gecode::FloatVal& d, Gecode::FloatNum s, Test* t);
TestSpace(int n, Gecode::FloatVal& d, Gecode::FloatNum s, Test* t,
Gecode::ReifyMode rm);
TestSpace(TestSpace& s);
virtual Gecode::Space* copy(void);
virtual void dropUntil(const Assignment& a);
bool assigned(void) const;
bool matchAssignment(const Assignment& a) const;
void post(void);
bool failed(void);
void rel(int i, Gecode::FloatRelType frt, Gecode::FloatVal n);
void rel(bool sol);
void assign(const Assignment& a, MaybeType& sol, bool skip=false);
void bound(void);
Gecode::FloatNum cut(int* cutDirections);
void prune(int i);
void prune(void);
bool prune(const Assignment& a, bool testfix);
void disable(void);
void enable(void);
unsigned int propagators(void);
};
class Test : public Base {
protected:
int arity;
Gecode::FloatVal dom;
Gecode::FloatNum step;
AssignmentType assigmentType;
bool reified;
int rms;
bool testsearch;
bool testfix;
bool testsubsumed;
bool eqv(void) const;
bool imp(void) const;
bool pmi(void) const;
public:
Test(const std::string& s, int a, const Gecode::FloatVal& d,
Gecode::FloatNum st, AssignmentType at,
bool r);
Test(const std::string& s, int a,
Gecode::FloatNum min, Gecode::FloatNum max,
Gecode::FloatNum st, AssignmentType at,
bool r);
virtual Assignment* assignment(void) const;
virtual bool extendAssignement(Assignment& a) const;
virtual MaybeType solution(const Assignment&) const = 0;
bool subsumed(const TestSpace& ts) const;
virtual bool ignore(const Assignment& a) const;
virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) = 0;
virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x,
Gecode::Reify r);
virtual bool run(void);
static std::string str(Gecode::FloatRelType frt);
static std::string str(Gecode::FloatNum f);
static std::string str(Gecode::FloatVal f);
static std::string str(const Gecode::FloatValArgs& f);
static MaybeType cmp(Gecode::FloatVal x, Gecode::FloatRelType r,
Gecode::FloatVal y);
static MaybeType eq(Gecode::FloatVal x, Gecode::FloatVal y);
bool flip(void);
};
class FloatRelTypes {
private:
static const Gecode::FloatRelType frts[6];
int i;
public:
FloatRelTypes(void);
void reset(void);
bool operator()(void) const;
void operator++(void);
Gecode::FloatRelType frt(void) const;
};
}
}
std::ostream& operator<<(std::ostream& os, const Test::Float::Assignment& a);
#include "test/float.hpp"
#endif
// STATISTICS: test-float
Gecode::FloatValArgs
Passing float arguments.
Definition float.hh:950
Gecode::FloatVal
Float value type.
Definition float.hh:334
Gecode::FloatVarArray
Float variable array.
Definition float.hh:1030
Gecode::Reify
Reification specification.
Definition int.hh:876
Gecode::Space
Computation spaces.
Definition core.hpp:1742
Test::Base::Base
Base(const std::string &s)
Create and register test with name s.
Definition test.cpp:59
Test::Float::Assignment
Base class for assignments
Definition float.hh:80
Test::Float::Assignment::n
int n
Number of variables.
Definition float.hh:82
Test::Float::Assignment::operator()
virtual bool operator()(void) const =0
Test whether all assignments have been iterated.
Test::Float::Assignment::Assignment
Assignment(int n0, const Gecode::FloatVal &d0)
Initialize assignments for n0 variables and values d0.
Definition float.hpp:45
Test::Float::Assignment::d
Gecode::FloatVal d
Domain for each variable.
Definition float.hh:83
Test::Float::Assignment::operator[]
virtual Gecode::FloatVal operator[](int i) const =0
Return value for variable i.
Test::Float::Assignment::set
virtual void set(int i, const Gecode::FloatVal &val)=0
Set assignment to value val for variable i.
Test::Float::Assignment::size
int size(void) const
Return number of variables.
Definition float.hpp:48
Test::Float::Assignment::operator++
virtual void operator++(void)=0
Move to next assignment.
Test::Float::Assignment::~Assignment
virtual ~Assignment(void)
Destructor.
Definition float.hpp:52
Test::Float::CpltAssignment::operator++
virtual void operator++(void)
Move to next assignment.
Definition float.cpp:50
Test::Float::CpltAssignment::~CpltAssignment
virtual ~CpltAssignment(void)
Destructor.
Definition float.hpp:78
Test::Float::CpltAssignment::operator[]
virtual Gecode::FloatVal operator[](int i) const
Return value for variable i.
Definition float.hpp:68
Test::Float::CpltAssignment::step
Gecode::FloatNum step
Step for next assignment.
Definition float.hh:105
Test::Float::CpltAssignment::dsv
Gecode::FloatVal * dsv
Iterator for each variable.
Definition float.hh:104
Test::Float::CpltAssignment::set
virtual void set(int i, const Gecode::FloatVal &val)
Set assignment to value val for variable i.
Definition float.hpp:73
Test::Float::CpltAssignment::operator()
virtual bool operator()(void) const
Test whether all assignments have been iterated.
Definition float.hpp:64
Test::Float::CpltAssignment::CpltAssignment
CpltAssignment(int n, const Gecode::FloatVal &d, Gecode::FloatNum s)
Initialize assignments for n variables and values d with step s.
Definition float.hpp:55
Test::Float::ExtAssignment::ExtAssignment
ExtAssignment(int n, const Gecode::FloatVal &d, Gecode::FloatNum s, const Test *pb)
Initialize assignments for n variables and values d with step s.
Definition float.hpp:83
Test::Float::ExtAssignment::~ExtAssignment
virtual ~ExtAssignment(void)
Destructor.
Definition float.hpp:107
Test::Float::ExtAssignment::set
virtual void set(int i, const Gecode::FloatVal &val)
Set assignment to value val for variable i.
Definition float.hpp:102
Test::Float::ExtAssignment::dsv
Gecode::FloatVal * dsv
Iterator for each variable.
Definition float.hh:125
Test::Float::ExtAssignment::operator[]
virtual Gecode::FloatVal operator[](int i) const
Return value for variable i.
Definition float.hpp:97
Test::Float::ExtAssignment::operator++
virtual void operator++(void)
Move to next assignment.
Definition float.cpp:67
Test::Float::ExtAssignment::step
Gecode::FloatNum step
Step for next assignment.
Definition float.hh:126
Test::Float::ExtAssignment::curPb
const Test * curPb
Current problem used to complete assignment.
Definition float.hh:124
Test::Float::ExtAssignment::operator()
virtual bool operator()(void) const
Test whether all assignments have been iterated.
Definition float.hpp:93
Test::Float::FloatRelTypes::operator++
void operator++(void)
Increment to next relation type.
Definition float.hpp:300
Test::Float::FloatRelTypes::frt
Gecode::FloatRelType frt(void) const
Return current relation type.
Definition float.hpp:304
Test::Float::FloatRelTypes::FloatRelTypes
FloatRelTypes(void)
Initialize iterator.
Definition float.hpp:289
Test::Float::FloatRelTypes::operator()
bool operator()(void) const
Test whether iterator is done.
Definition float.hpp:296
Test::Float::FloatRelTypes::reset
void reset(void)
Reset iterator.
Definition float.hpp:292
Test::Float::RandomAssignment::RandomAssignment
RandomAssignment(int n, const Gecode::FloatVal &d, int a)
Initialize for a assignments for n variables and values d.
Definition float.hpp:130
Test::Float::RandomAssignment::operator[]
virtual Gecode::FloatVal operator[](int i) const
Return value for variable i.
Definition float.hpp:141
Test::Float::RandomAssignment::set
virtual void set(int i, const Gecode::FloatVal &val)
Set assignment to value val for variable i.
Definition float.hpp:146
Test::Float::RandomAssignment::randval
Gecode::FloatNum randval(void)
Definition float.hpp:112
Test::Float::RandomAssignment::vals
Gecode::FloatVal * vals
The current values for the variables.
Definition float.hh:146
Test::Float::RandomAssignment::operator()
virtual bool operator()(void) const
Test whether all assignments have been iterated.
Definition float.hpp:137
Test::Float::RandomAssignment::operator++
virtual void operator++(void)
Move to next assignment.
Definition float.cpp:89
Test::Float::RandomAssignment::a
int a
How many assigments still to be generated Generate new value according to domain.
Definition float.hh:147
Test::Float::RandomAssignment::~RandomAssignment
virtual ~RandomAssignment(void)
Destructor.
Definition float.hpp:151
Test::Float::TestSpace
Space for executing tests.
Definition float.hh:166
Test::Float::TestSpace::x
Gecode::FloatVarArray x
Variables to be tested.
Definition float.hh:173
Test::Float::TestSpace::prune
void prune(void)
Prune some random values for some random variable.
Definition float.cpp:348
Test::Float::TestSpace::cut
Gecode::FloatNum cut(int *cutDirections)
Cut the bigger variable to an half sized interval. It returns the new size of the cut interval....
Definition float.cpp:303
Test::Float::TestSpace::matchAssignment
bool matchAssignment(const Assignment &a) const
Test whether all variables match assignment a.
Definition float.cpp:211
Test::Float::TestSpace::r
Gecode::Reify r
Reification information.
Definition float.hh:175
Test::Float::TestSpace::bound
void bound(void)
Assing a random variable to a random bound.
Definition float.cpp:288
Test::Float::TestSpace::propagators
unsigned int propagators(void)
Return the number of propagators.
Definition float.cpp:410
Test::Float::TestSpace::disable
void disable(void)
Disable propagators in space and compute fixpoint (make all idle).
Definition float.cpp:191
Test::Float::TestSpace::d
Gecode::FloatVal d
Initial domain.
Definition float.hh:169
Test::Float::TestSpace::post
void post(void)
Post propagator.
Definition float.cpp:219
Test::Float::TestSpace::TestSpace
TestSpace(int n, Gecode::FloatVal &d, Gecode::FloatNum s, Test *t)
Create test space.
Definition float.cpp:143
Test::Float::TestSpace::test
Test * test
The test currently run.
Definition float.hh:177
Test::Float::TestSpace::reified
bool reified
Whether the test is for a reified propagator.
Definition float.hh:179
Test::Float::TestSpace::enable
void enable(void)
Enable propagators in space.
Definition float.cpp:186
Test::Float::TestSpace::failed
bool failed(void)
Compute a fixpoint and check for failure.
Definition float.cpp:232
Test::Float::TestSpace::assigned
bool assigned(void) const
Test whether all variables are assigned.
Definition float.cpp:203
Test::Float::TestSpace::dropUntil
virtual void dropUntil(const Assignment &a)
Add constraints to skip solutions to the a assignment.
Definition float.cpp:197
Test::Float::TestSpace::step
Gecode::FloatNum step
Step for going to next solution.
Definition float.hh:171
Test::Float::TestSpace::rel
void rel(int i, Gecode::FloatRelType frt, Gecode::FloatVal n)
Perform integer tell operation on x[i].
Definition float.cpp:244
Test::Float::TestSpace::assign
void assign(const Assignment &a, MaybeType &sol, bool skip=false)
Assign all (or all but one, if skip is true) variables to values in a If assignment of a variable is ...
Definition float.cpp:270
Test::Float::TestSpace::copy
virtual Gecode::Space * copy(void)
Copy space during cloning.
Definition float.cpp:181
Test::Float::Test::rms
int rms
Which reification modes are supported.
Definition float.hh:257
Test::Float::Test::eq
static MaybeType eq(Gecode::FloatVal x, Gecode::FloatVal y)
Whether x and y are equal.
Definition float.hpp:268
Test::Float::Test::cmp
static MaybeType cmp(Gecode::FloatVal x, Gecode::FloatRelType r, Gecode::FloatVal y)
Compare x and y with respect to r.
Definition float.hpp:235
Test::Float::Test::testsubsumed
bool testsubsumed
Whether to test for subsumption.
Definition float.hh:263
Test::Float::Test::extendAssignement
virtual bool extendAssignement(Assignment &a) const
Complete the current assignment to get a feasible one (which satisfies all constraint)....
Definition float.cpp:435
Test::Float::Test::testfix
bool testfix
Whether to perform fixpoint test.
Definition float.hh:261
Test::Float::Test::eqv
bool eqv(void) const
Test whether equivalence as reification mode is supported.
Definition float.hpp:160
Test::Float::Test::arity
int arity
Number of variables.
Definition float.hh:247
Test::Float::Test::post
virtual void post(Gecode::Space &home, Gecode::FloatVarArray &x)=0
Post constraint.
Test::Float::Test::run
virtual bool run(void)
Perform test.
Definition float.cpp:474
Test::Float::Test::str
static std::string str(Gecode::FloatRelType frt)
Map float relation to string.
Definition float.hpp:194
Test::Float::Test::flip
bool flip(void)
Flip a coin and return true or false randomly.
Definition float.hpp:273
Test::Float::Test::step
Gecode::FloatNum step
Step for going to next solution.
Definition float.hh:251
Test::Float::Test::assignment
virtual Assignment * assignment(void) const
Create assignment.
Definition float.cpp:420
Test::Float::Test::pmi
bool pmi(void) const
Test whether reverse implication as reification mode is supported.
Definition float.hpp:168
Test::Float::Test::subsumed
bool subsumed(const TestSpace &ts) const
Test if ts is subsumed or not (i.e. if there is no more propagator unless the assignment is an extend...
Definition float.cpp:441
Test::Float::Test::reified
bool reified
Does the constraint also exist as reified constraint.
Definition float.hh:255
Test::Float::Test::testsearch
bool testsearch
Whether to perform search test.
Definition float.hh:259
Test::Float::Test::ignore
virtual bool ignore(const Assignment &a) const
Whether to ignore assignment for reification.
Definition float.cpp:465
Test::Float::Test::solution
virtual MaybeType solution(const Assignment &) const =0
Check for solution.
Test::Float::Test::assigmentType
AssignmentType assigmentType
Gives the type of assignment to use.
Definition float.hh:253
Test::Float::Test::dom
Gecode::FloatVal dom
Domain of variables.
Definition float.hh:249
Test::Float::Test::imp
bool imp(void) const
Test whether implication as reification mode is supported.
Definition float.hpp:164
float.hh
Gecode::FloatNum
double FloatNum
Floating point number base type.
Definition float.hh:106
Gecode::FloatRelType
FloatRelType
Relation types for floats.
Definition float.hh:1068
Gecode::ReifyMode
ReifyMode
Mode for reification.
Definition int.hh:848
Test::Float
Testing domain floats.
Definition float.cpp:43
Test::Float::AssignmentType
AssignmentType
Assignment possible types.
Definition float.hh:61
Test::Float::RANDOM_ASSIGNMENT
@ RANDOM_ASSIGNMENT
Definition float.hh:63
Test::Float::EXTEND_ASSIGNMENT
@ EXTEND_ASSIGNMENT
Definition float.hh:64
Test::Float::CPLT_ASSIGNMENT
@ CPLT_ASSIGNMENT
Definition float.hh:62
Test::Float::operator&
MaybeType operator&(MaybeType a, MaybeType b)
Three-valued conjunction of MaybeType.
Definition float.hpp:278
Test::Float::MaybeType
MaybeType
Type for comparisons and solutions.
Definition float.hh:51
Test::Float::MT_MAYBE
@ MT_MAYBE
Definition float.hh:54
Test::Float::MT_FALSE
@ MT_FALSE
Definition float.hh:52
Test::Float::MT_TRUE
@ MT_TRUE
Definition float.hh:53
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
float.hpp
test.hh