Generated on for Gecode by doxygen 1.15.0
float.hh
Go to the documentation of this file.
1/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2/*
3 * Main authors:
4 * Christian Schulte <schulte@gecode.dev>
5 * Mikael Zayenz Lagerkvist <lagerkvist@gecode.dev>
6 * Vincent Barichard <Vincent.Barichard@univ-angers.fr>
7 *
8 * Copyright:
9 * Christian Schulte, 2005
10 * Mikael Zayenz Lagerkvist, 2006
11 * Vincent Barichard, 2012
12 *
13 * This file is part of Gecode, the generic constraint
14 * development environment:
15 * http://www.gecode.dev
16 *
17 * Permission is hereby granted, free of charge, to any person obtaining
18 * a copy of this software and associated documentation files (the
19 * "Software"), to deal in the Software without restriction, including
20 * without limitation the rights to use, copy, modify, merge, publish,
21 * distribute, sublicense, and/or sell copies of the Software, and to
22 * permit persons to whom the Software is furnished to do so, subject to
23 * the following conditions:
24 *
25 * The above copyright notice and this permission notice shall be
26 * included in all copies or substantial portions of the Software.
27 *
28 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
29 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
30 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
31 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
32 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
33 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
34 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35 *
36 */
37
38#ifndef GECODE_TEST_FLOAT_HH
39#define GECODE_TEST_FLOAT_HH
40
41#include "test/test.hh"
42
43#include <gecode/float.hh>
44
45namespace Test {
46
48 namespace Float {
49
51 enum MaybeType {
52 MT_FALSE = 0, //< Does hold
53 MT_TRUE, //< Does not hold
54 MT_MAYBE //< Might or might not hold
55 };
56
59
66
67 class Test;
68
73
79
80 class Assignment {
81 protected:
82 int n;
84 public:
86 Assignment(int n0, const Gecode::FloatVal& d0);
88 virtual bool has_more(void) const = 0;
90 virtual void next(Gecode::Support::RandomGenerator& rand) = 0;
92 virtual Gecode::FloatVal operator[](int i) const = 0;
94 virtual void set(int i, const Gecode::FloatVal& val) = 0;
96 int size(void) const;
98 virtual ~Assignment(void);
99 };
100
102 class CpltAssignment : public Assignment {
103 protected:
106 public:
110 virtual bool has_more(void) const;
112 virtual void next(Gecode::Support::RandomGenerator& rand);
114 virtual Gecode::FloatVal operator[](int i) const;
116 virtual void set(int i, const Gecode::FloatVal& val);
118 virtual ~CpltAssignment(void);
119 };
120
122 class ExtAssignment : public Assignment {
123 protected:
124 const Test* curPb;
127 public:
129 ExtAssignment(int n, const Gecode::FloatVal& d, Gecode::FloatNum s, const Test* pb,
132 virtual bool has_more(void) const;
134 virtual void next(Gecode::Support::RandomGenerator& rand);
136 virtual Gecode::FloatVal operator[](int i) const;
138 virtual void set(int i, const Gecode::FloatVal& val);
140 virtual ~ExtAssignment(void);
141 };
142
143
146 protected:
148 int a;
151 public:
155 virtual bool has_more(void) const;
157 virtual void next(Gecode::Support::RandomGenerator& rand);
159 virtual Gecode::FloatVal operator[](int i) const;
161 virtual void set(int i, const Gecode::FloatVal& val);
163 virtual ~RandomAssignment(void);
164 };
165
167 class TestSpace : public Gecode::Space {
168 public:
181
202 virtual Gecode::Space* copy(void);
204 virtual void dropUntil(const Assignment& a);
206 bool assigned(void) const;
208 bool matchAssignment(const Assignment& a) const;
210 void post(void);
212 bool failed(void);
214 void rel(int i, Gecode::FloatRelType frt, Gecode::FloatVal n);
216 void rel(bool sol);
220 void assign(const Assignment& a, MaybeType& sol, bool skip, Gecode::Support::RandomGenerator& rand);
226 Gecode::FloatNum cut(int* cutDirections);
228 void prune(int i, Gecode::Support::RandomGenerator& rand);
232 bool prune(const Assignment& a, bool testfix, Gecode::Support::RandomGenerator& rand);
234 void disable(void);
236 void enable(void);
238 unsigned int propagators(void);
239 };
240
245 class Test : public Base {
246 protected:
248 int arity;
258 int rms;
266
267
268 bool eqv(void) const;
270 bool imp(void) const;
272 bool pmi(void) const;
274 public:
282 Test(const std::string& s, int a, const Gecode::FloatVal& d,
284 bool r);
292 Test(const std::string& s, int a,
295 bool r);
297 virtual Assignment* assignment(void) const;
300 virtual bool extendAssignment(Assignment& a) const;
302 virtual MaybeType solution(const Assignment&) const = 0;
305 bool subsumed(const TestSpace& ts) const;
307 virtual bool ignore(const Assignment& a) const;
309 virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) = 0;
311 virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x,
314 virtual bool run(void);
316
317
318 static std::string str(Gecode::FloatRelType frt);
320 static std::string str(Gecode::FloatNum f);
322 static std::string str(Gecode::FloatVal f);
324 static std::string str(const Gecode::FloatValArgs& f);
326
328
334 bool flip(void);
336 };
337
338
341 private:
343 static const Gecode::FloatRelType frts[6];
345 int i;
346 public:
348 FloatRelTypes(void);
350 void reset(void);
352 bool operator()(void) const;
354 void operator++(void);
356 Gecode::FloatRelType frt(void) const;
357 };
358
359 }
360}
361
366std::ostream& operator<<(std::ostream& os, const Test::Float::Assignment& a);
367
368#include "test/float.hpp"
369
370#endif
371
372// STATISTICS: test-float
373
Passing float arguments.
Definition float.hh:953
Float value type.
Definition float.hh:334
Float variable array.
Definition float.hh:1035
Reification specification.
Definition int.hh:910
Computation spaces.
Definition core.hpp:1775
Base(std::string s)
Create and register test with name s.
Definition test.cpp:60
Base class for assignments
Definition float.hh:80
int n
Number of variables.
Definition float.hh:82
Assignment(int n0, const Gecode::FloatVal &d0)
Initialize assignments for n0 variables and values d0.
Definition float.hpp:45
virtual void next(Gecode::Support::RandomGenerator &rand)=0
Move to next assignment.
Gecode::FloatVal d
Domain for each variable.
Definition float.hh:83
virtual bool has_more(void) const =0
Test whether all assignments have been iterated.
virtual Gecode::FloatVal operator[](int i) const =0
Return value for variable i.
virtual void set(int i, const Gecode::FloatVal &val)=0
Set assignment to value val for variable i.
int size(void) const
Return number of variables.
Definition float.hpp:48
virtual ~Assignment(void)
Destructor.
Definition float.hpp:52
virtual void next(Gecode::Support::RandomGenerator &rand)
Move to next assignment.
Definition float.cpp:50
virtual ~CpltAssignment(void)
Destructor.
Definition float.hpp:78
virtual Gecode::FloatVal operator[](int i) const
Return value for variable i.
Definition float.hpp:68
Gecode::FloatNum step
Step for next assignment.
Definition float.hh:105
Gecode::FloatVal * dsv
Iterator for each variable.
Definition float.hh:104
virtual bool has_more(void) const
Test whether all assignments have been iterated.
Definition float.hpp:64
virtual void set(int i, const Gecode::FloatVal &val)
Set assignment to value val for variable i.
Definition float.hpp:73
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
virtual bool has_more(void) const
Test whether all assignments have been iterated.
Definition float.hpp:94
virtual ~ExtAssignment(void)
Destructor.
Definition float.hpp:108
virtual void set(int i, const Gecode::FloatVal &val)
Set assignment to value val for variable i.
Definition float.hpp:103
Gecode::FloatVal * dsv
Iterator for each variable.
Definition float.hh:125
virtual Gecode::FloatVal operator[](int i) const
Return value for variable i.
Definition float.hpp:98
virtual void next(Gecode::Support::RandomGenerator &rand)
Move to next assignment.
Definition float.cpp:67
Gecode::FloatNum step
Step for next assignment.
Definition float.hh:126
const Test * curPb
Current problem used to complete assignment.
Definition float.hh:124
ExtAssignment(int n, const Gecode::FloatVal &d, Gecode::FloatNum s, const Test *pb, Gecode::Support::RandomGenerator &rand)
Initialize assignments for n variables and values d with step s.
Definition float.hpp:83
void operator++(void)
Increment to next relation type.
Definition float.hpp:301
Gecode::FloatRelType frt(void) const
Return current relation type.
Definition float.hpp:305
FloatRelTypes(void)
Initialize iterator.
Definition float.hpp:290
bool operator()(void) const
Test whether iterator is done.
Definition float.hpp:297
void reset(void)
Reset iterator.
Definition float.hpp:293
virtual void next(Gecode::Support::RandomGenerator &rand)
Move to next assignment.
Definition float.cpp:89
virtual Gecode::FloatVal operator[](int i) const
Return value for variable i.
Definition float.hpp:142
virtual void set(int i, const Gecode::FloatVal &val)
Set assignment to value val for variable i.
Definition float.hpp:147
RandomAssignment(int n, const Gecode::FloatVal &d, int a0, Gecode::Support::RandomGenerator &rand)
Initialize for a assignments for n variables and values d.
Definition float.hpp:131
Gecode::FloatNum randval(Gecode::Support::RandomGenerator &rand)
Definition float.hpp:113
Gecode::FloatVal * vals
The current values for the variables.
Definition float.hh:147
int a
How many assignments still to be generated Generate new value according to domain.
Definition float.hh:148
virtual bool has_more(void) const
Test whether all assignments have been iterated.
Definition float.hpp:138
virtual ~RandomAssignment(void)
Destructor.
Definition float.hpp:152
Space for executing tests.
Definition float.hh:167
void bound(Gecode::Support::RandomGenerator &rand)
Assign a random variable to a random bound.
Definition float.cpp:288
void prune(int i, Gecode::Support::RandomGenerator &rand)
Prune some random values from variable i.
Definition float.cpp:332
Gecode::FloatVarArray x
Variables to be tested.
Definition float.hh:174
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
bool matchAssignment(const Assignment &a) const
Test whether all variables match assignment a.
Definition float.cpp:211
Gecode::Reify r
Reification information.
Definition float.hh:176
unsigned int propagators(void)
Return the number of propagators.
Definition float.cpp:410
void disable(void)
Disable propagators in space and compute fixpoint (make all idle).
Definition float.cpp:191
Gecode::FloatVal d
Initial domain.
Definition float.hh:170
void post(void)
Post propagator.
Definition float.cpp:219
TestSpace(int n, Gecode::FloatVal &d, Gecode::FloatNum s, Test *t)
Create test space.
Definition float.cpp:143
Test * test
The test currently run.
Definition float.hh:178
bool reified
Whether the test is for a reified propagator.
Definition float.hh:180
void enable(void)
Enable propagators in space.
Definition float.cpp:186
bool failed(void)
Compute a fixpoint and check for failure.
Definition float.cpp:232
bool assigned(void) const
Test whether all variables are assigned.
Definition float.cpp:203
virtual void dropUntil(const Assignment &a)
Add constraints to skip solutions to the a assignment.
Definition float.cpp:197
Gecode::FloatNum step
Step for going to next solution.
Definition float.hh:172
void assign(const Assignment &a, MaybeType &sol, bool skip, Gecode::Support::RandomGenerator &rand)
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
void rel(int i, Gecode::FloatRelType frt, Gecode::FloatVal n)
Perform integer tell operation on x[i].
Definition float.cpp:244
virtual Gecode::Space * copy(void)
Copy space during cloning.
Definition float.cpp:181
int rms
Which reification modes are supported.
Definition float.hh:258
static MaybeType eq(Gecode::FloatVal x, Gecode::FloatVal y)
Whether x and y are equal.
Definition float.hpp:269
static MaybeType cmp(Gecode::FloatVal x, Gecode::FloatRelType r, Gecode::FloatVal y)
Compare x and y with respect to r.
Definition float.hpp:236
virtual bool extendAssignment(Assignment &a) const
Complete the current assignment to get a feasible one (which satisfies all constraint)....
Definition float.cpp:435
bool testsubsumed
Whether to test for subsumption.
Definition float.hh:264
bool testfix
Whether to perform fixpoint test.
Definition float.hh:262
bool eqv(void) const
Test whether equivalence as reification mode is supported.
Definition float.hpp:161
int arity
Number of variables.
Definition float.hh:248
virtual void post(Gecode::Space &home, Gecode::FloatVarArray &x)=0
Post constraint.
virtual bool run(void)
Perform test.
Definition float.cpp:478
static std::string str(Gecode::FloatRelType frt)
Map float relation to string.
Definition float.hpp:195
bool flip(void)
Flip a coin and return true or false randomly.
Definition float.hpp:274
Gecode::FloatNum step
Step for going to next solution.
Definition float.hh:252
virtual Assignment * assignment(void) const
Create assignment.
Definition float.cpp:420
AssignmentType assignmentType
Gives the type of assignment to use.
Definition float.hh:254
bool pmi(void) const
Test whether reverse implication as reification mode is supported.
Definition float.hpp:169
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
bool reified
Does the constraint also exist as reified constraint.
Definition float.hh:256
bool testsearch
Whether to perform search test.
Definition float.hh:260
virtual bool ignore(const Assignment &a) const
Whether to ignore assignment for reification.
Definition float.cpp:469
virtual MaybeType solution(const Assignment &) const =0
Check for solution.
Gecode::FloatVal dom
Domain of variables.
Definition float.hh:250
bool imp(void) const
Test whether implication as reification mode is supported.
Definition float.hpp:165
LinearCongruentialGenerator< 2147483647, 48271, 44488, 3399 > RandomGenerator
Default values for linear congruential generator.
Definition random.hpp:183
double FloatNum
Floating point number base type.
Definition float.hh:106
FloatRelType
Relation types for floats.
Definition float.hh:1075
ReifyMode
Mode for reification.
Definition int.hh:882
Testing domain floats.
Definition float.cpp:43
AssignmentType
Assignment possible types.
Definition float.hh:61
@ RANDOM_ASSIGNMENT
Definition float.hh:63
@ EXTEND_ASSIGNMENT
Definition float.hh:64
@ CPLT_ASSIGNMENT
Definition float.hh:62
MaybeType operator&(MaybeType a, MaybeType b)
Three-valued conjunction of MaybeType.
Definition float.hpp:279
MaybeType
Type for comparisons and solutions.
Definition float.hh:51
General test support.
Definition afc.cpp:39
Region r
Definition region.cpp:65
std::basic_ostream< Char, Traits > & operator<<(std::basic_ostream< Char, Traits > &os, const Dictionary &d)
Print statistics summary.
Definition scowl.hpp:13625