Generated on Sat Feb 7 2015 02:01:14 for Gecode by doxygen 1.8.9.1
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.org>
5  * Mikael Lagerkvist <lagerkvist@gecode.org>
6  * Vincent Barichard <Vincent.Barichard@univ-angers.fr>
7  *
8  * Copyright:
9  * Christian Schulte, 2005
10  * Mikael Lagerkvist, 2006
11  * Vincent Barichard, 2012
12  *
13  * Last modified:
14  * $Date: 2013-02-04 22:41:43 +0100 (Mon, 04 Feb 2013) $ by $Author: schulte $
15  * $Revision: 13264 $
16  *
17  * This file is part of Gecode, the generic constraint
18  * development environment:
19  * http://www.gecode.org
20  *
21  * Permission is hereby granted, free of charge, to any person obtaining
22  * a copy of this software and associated documentation files (the
23  * "Software"), to deal in the Software without restriction, including
24  * without limitation the rights to use, copy, modify, merge, publish,
25  * distribute, sublicense, and/or sell copies of the Software, and to
26  * permit persons to whom the Software is furnished to do so, subject to
27  * the following conditions:
28  *
29  * The above copyright notice and this permission notice shall be
30  * included in all copies or substantial portions of the Software.
31  *
32  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
33  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
34  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
35  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
36  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
37  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
38  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
39  *
40  */
41 
42 #ifndef __GECODE_TEST_FLOAT_HH__
43 #define __GECODE_TEST_FLOAT_HH__
44 
45 #include "test/test.hh"
46 
47 #include <gecode/float.hh>
48 
49 namespace Test {
50 
52  namespace Float {
53 
55  enum MaybeType {
56  MT_FALSE = 0, //< Does hold
57  MT_TRUE, //< Does not hold
58  MT_MAYBE //< Might or might not hold
59  };
60 
63 
69  };
70 
71  class Test;
72 
83  class Assignment {
85  protected:
86  int n;
88  public:
90  Assignment(int n0, const Gecode::FloatVal& d0);
92  virtual bool operator()(void) const = 0;
94  virtual void operator++(void) = 0;
96  virtual Gecode::FloatVal operator[](int i) const = 0;
98  virtual void set(int i, const Gecode::FloatVal& val) = 0;
100  int size(void) const;
102  virtual ~Assignment(void);
103  };
104 
106  class CpltAssignment : public Assignment {
107  protected:
110  public:
114  virtual bool operator()(void) const;
116  virtual void operator++(void);
118  virtual Gecode::FloatVal operator[](int i) const;
120  virtual void set(int i, const Gecode::FloatVal& val);
122  virtual ~CpltAssignment(void);
123  };
124 
126  class ExtAssignment : public Assignment {
127  protected:
128  const Test* curPb;
131  public:
133  ExtAssignment(int n, const Gecode::FloatVal& d, Gecode::FloatNum s, const Test * pb);
135  virtual bool operator()(void) const;
137  virtual void operator++(void);
139  virtual Gecode::FloatVal operator[](int i) const;
141  virtual void set(int i, const Gecode::FloatVal& val);
143  virtual ~ExtAssignment(void);
144  };
145 
146 
148  class RandomAssignment : public Assignment {
149  protected:
151  int a;
154  public:
156  RandomAssignment(int n, const Gecode::FloatVal& d, int a);
158  virtual bool operator()(void) const;
160  virtual void operator++(void);
162  virtual Gecode::FloatVal operator[](int i) const;
164  virtual void set(int i, const Gecode::FloatVal& val);
166  virtual ~RandomAssignment(void);
167  };
168 
170  class TestSpace : public Gecode::Space {
171  public:
183  bool reified;
184 
201  Gecode::ReifyMode rm);
203  TestSpace(bool share, TestSpace& s);
205  virtual Gecode::Space* copy(bool share);
207  virtual void dropUntil(const Assignment& a);
209  bool assigned(void) const;
211  bool matchAssignment(const Assignment& a) const;
213  void post(void);
215  bool failed(void);
217  void rel(int i, Gecode::FloatRelType frt, Gecode::FloatVal n);
219  void rel(bool sol);
223  void assign(const Assignment& a, MaybeType& sol, bool skip=false);
225  void bound(void);
229  Gecode::FloatNum cut(int* cutDirections);
231  void prune(int i);
233  void prune(void);
235  bool prune(const Assignment& a, bool testfix);
236  };
237 
242  class Test : public Base {
243  protected:
245  int arity;
253  bool reified;
255  int rms;
259  bool testfix;
263 
264  bool eqv(void) const;
267  bool imp(void) const;
269  bool pmi(void) const;
271  public:
279  Test(const std::string& s, int a, const Gecode::FloatVal& d,
281  bool r);
289  Test(const std::string& s, int a,
292  bool r);
294  virtual Assignment* assignment(void) const;
297  virtual bool extendAssignement(Assignment& a) const;
299  virtual MaybeType solution(const Assignment&) const = 0;
302  bool subsumed(const TestSpace& ts) const;
304  virtual bool ignore(const Assignment& a) const;
306  virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) = 0;
308  virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x,
309  Gecode::Reify r);
311  virtual bool run(void);
313 
314  static std::string str(Gecode::FloatRelType frt);
317  static std::string str(Gecode::FloatNum f);
319  static std::string str(Gecode::FloatVal f);
321  static std::string str(const Gecode::FloatValArgs& f);
323 
327  Gecode::FloatVal y);
331  bool flip(void);
333  };
335 
338  private:
340  static const Gecode::FloatRelType frts[6];
342  int i;
343  public:
345  FloatRelTypes(void);
347  void reset(void);
349  bool operator()(void) const;
351  void operator++(void);
353  Gecode::FloatRelType frt(void) const;
354  };
355 
356  }
357 }
358 
363 std::ostream& operator<<(std::ostream& os, const Test::Float::Assignment& a);
364 
365 #include "test/float.hpp"
366 
367 #endif
368 
369 // STATISTICS: test-float
370 
static MaybeType eq(Gecode::FloatVal x, Gecode::FloatVal y)
Whether x and y are equal.
Definition: float.hpp:272
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:429
Passing float arguments.
Definition: float.hh:937
Gecode::FloatNum step
Step for going to next solution.
Definition: float.hh:249
virtual ~RandomAssignment(void)
Destructor.
Definition: float.hpp:155
NodeType t
Type of node.
Definition: bool-expr.cpp:234
virtual Gecode::FloatVal operator[](int i) const
Return value for variable i.
Definition: float.hpp:145
AssignmentType
Assignment possible types.
Definition: float.hh:65
bool operator()(void) const
Test whether iterator is done.
Definition: float.hpp:300
void reset(void)
Reset iterator.
Definition: float.hpp:296
const FloatNum max
Largest allowed float value.
Definition: float.hh:831
virtual bool operator()(void) const
Test whether all assignments have been iterated.
Definition: float.hpp:97
Test(const std::string &s, int a, const Gecode::FloatVal &d, Gecode::FloatNum st, AssignmentType at, bool r)
Constructor.
Definition: float.hpp:176
Gecode::FloatNum step
Step for next assignment.
Definition: float.hh:109
void prune(void)
Prune some random values for some random variable.
Definition: float.cpp:341
virtual void set(int i, const Gecode::FloatVal &val)
Set assignment to value val for variable i.
Definition: float.hpp:106
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:87
bool testfix
Whether to perform fixpoint test.
Definition: float.hh:259
static MaybeType cmp(Gecode::FloatVal x, Gecode::FloatRelType r, Gecode::FloatVal y)
Compare x and y with respect to r.
Definition: float.hpp:239
virtual bool operator()(void) const
Test whether all assignments have been iterated.
Definition: float.hpp:141
bool testsubsumed
Whether to test for subsumption.
Definition: float.hh:261
int n
Number of variables.
Definition: float.hh:86
static std::string str(Gecode::FloatRelType frt)
Map float relation to string.
Definition: float.hpp:198
void post(void)
Post propagator.
Definition: float.cpp:212
void bound(void)
Assing a random variable to a random bound.
Definition: float.cpp:281
bool pmi(void) const
Test whether reverse implication as reification mode is supported.
Definition: float.hpp:172
Gecode::FloatRelType frt(void) const
Return current relation type.
Definition: float.hpp:308
Float variable array.
Definition: float.hh:1016
Computation spaces.
Definition: core.hpp:1362
virtual void operator++(void)
Move to next assignment.
Definition: float.cpp:71
FloatRelTypes(void)
Initialize iterator.
Definition: float.hpp:293
int a
How many assigments still to be generated Generate new value according to domain. ...
Definition: float.hh:151
bool imp(void) const
Test whether implication as reification mode is supported.
Definition: float.hpp:168
Gecode::IntSet d(v, 7)
Test * test
The test currently run.
Definition: float.hh:181
virtual void set(int i, const Gecode::FloatVal &val)=0
Set assignment to value val for variable i.
virtual MaybeType solution(const Assignment &) const =0
Check for solution.
const FloatNum min
Smallest allowed float value.
Definition: float.hh:833
Iterator for float relation types.
Definition: float.hh:337
Gecode::IntArgs i(4, 1, 2, 3, 4)
virtual ~Assignment(void)
Destructor.
Definition: float.hpp:56
CpltAssignment(int n, const Gecode::FloatVal &d, Gecode::FloatNum s)
Initialize assignments for n variables and values d with step s.
Definition: float.hpp:59
Gecode::FloatNum randval(void)
Definition: float.hpp:116
int n
Number of negative literals for node type.
Definition: bool-expr.cpp:238
Generate all assignments except the last variable and complete it to get a solution.
Definition: float.hh:126
NNF * r
Right subtree.
Definition: bool-expr.cpp:246
TestSpace(int n, Gecode::FloatVal &d, Gecode::FloatNum s, Test *t)
Create test space.
Definition: float.cpp:147
FloatRelType
Relation types for floats.
Definition: float.hh:1054
RandomAssignment(int n, const Gecode::FloatVal &d, int a)
Initialize for a assignments for n variables and values d.
Definition: float.hpp:134
bool assigned(void) const
Test whether all variables are assigned.
Definition: float.cpp:196
const Test * curPb
Current problem used to complete assignment.
Definition: float.hh:128
virtual void dropUntil(const Assignment &a)
Add constraints to skip solutions to the a assignment.
Definition: float.cpp:190
Reification specification.
Definition: int.hh:854
virtual bool ignore(const Assignment &a) const
Whether to ignore assignment for reification.
Definition: float.cpp:453
Base class for all tests to be run
Definition: test.hh:107
bool testsearch
Whether to perform search test.
Definition: float.hh:257
virtual void operator++(void)
Move to next assignment.
Definition: float.cpp:54
virtual void post(Gecode::Space &home, Gecode::FloatVarArray &x)=0
Post constraint.
Generate random selection of assignments.
Definition: float.hh:148
Gecode::Reify r
Reification information.
Definition: float.hh:179
virtual void operator++(void)=0
Move to next assignment.
virtual ~ExtAssignment(void)
Destructor.
Definition: float.hpp:111
Gecode::FloatVarArray x
Variables to be tested.
Definition: float.hh:177
Gecode::FloatVal d
Initial domain.
Definition: float.hh:173
General test support.
Definition: afc.cpp:43
virtual Gecode::FloatVal operator[](int i) const
Return value for variable i.
Definition: float.hpp:101
virtual bool extendAssignement(Assignment &a) const
Complete the current assignment to get a feasible one (which satisfies all constraint). If such an assignment is computed, it returns true, false otherwise.
Definition: float.cpp:423
Float value type.
Definition: float.hh:321
void operator++(void)
Increment to next relation type.
Definition: float.hpp:304
virtual Gecode::FloatVal operator[](int i) const =0
Return value for variable i.
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:263
Node * x
Pointer to corresponding Boolean expression node.
Definition: bool-expr.cpp:253
Gecode::FloatVal d
Domain for each variable.
Definition: float.hh:87
Gecode::FloatVal dom
Domain of variables.
Definition: float.hh:247
AssignmentType assigmentType
Gives the type of assignment to use.
Definition: float.hh:251
virtual Assignment * assignment(void) const
Create assignment.
Definition: float.cpp:408
MaybeType
Type for comparisons and solutions.
Definition: float.hh:55
bool matchAssignment(const Assignment &a) const
Test whether all variables match assignment a.
Definition: float.cpp:204
Space for executing tests.
Definition: float.hh:170
Gecode::FloatVal * dsv
Iterator for each variable.
Definition: float.hh:129
MaybeType operator&(MaybeType a, MaybeType b)
Three-valued conjunction of MaybeType.
Definition: float.hpp:282
int size(void) const
Return number of variables.
Definition: float.hpp:52
Gecode::FloatVal * vals
The current values for the variables.
Definition: float.hh:150
virtual void set(int i, const Gecode::FloatVal &val)
Set assignment to value val for variable i.
Definition: float.hpp:150
virtual bool run(void)
Perform test.
Definition: float.cpp:462
virtual Gecode::FloatVal operator[](int i) const
Return value for variable i.
Definition: float.hpp:72
virtual bool operator()(void) const
Test whether all assignments have been iterated.
Definition: float.hpp:68
struct Gecode::@518::NNF::@57::@58 b
For binary nodes (and, or, eqv)
int arity
Number of variables.
Definition: float.hh:245
std::basic_ostream< Char, Traits > & operator<<(std::basic_ostream< Char, Traits > &os, const FloatView &x)
Print float variable view.
Definition: print.hpp:62
bool failed(void)
Compute a fixpoint and check for failure.
Definition: float.cpp:225
virtual void operator++(void)
Move to next assignment.
Definition: float.cpp:93
Gecode::FloatVal * dsv
Iterator for each variable.
Definition: float.hh:108
bool reified
Does the constraint also exist as reified constraint.
Definition: float.hh:253
Generate all assignments.
Definition: float.hh:106
double FloatNum
Floating point number base type.
Definition: float.hh:108
ReifyMode
Mode for reification.
Definition: int.hh:826
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:296
void rel(int i, Gecode::FloatRelType frt, Gecode::FloatVal n)
Perform integer tell operation on x[i].
Definition: float.cpp:237
virtual void set(int i, const Gecode::FloatVal &val)
Set assignment to value val for variable i.
Definition: float.hpp:77
struct Gecode::@518::NNF::@57::@59 a
For atomic nodes.
Gecode::FloatNum step
Step for going to next solution.
Definition: float.hh:175
Gecode::FloatNum step
Step for next assignment.
Definition: float.hh:130
virtual ~CpltAssignment(void)
Destructor.
Definition: float.hpp:82
int rms
Which reification modes are supported.
Definition: float.hh:255
bool reified
Whether the test is for a reified propagator.
Definition: float.hh:183
bool eqv(void) const
Test whether equivalence as reification mode is supported.
Definition: float.hpp:164
Assignment(int n0, const Gecode::FloatVal &d0)
Initialize assignments for n0 variables and values d0.
Definition: float.hpp:49
virtual Gecode::Space * copy(bool share)
Copy space during cloning.
Definition: float.cpp:185
bool flip(void)
Flip a coin and return true or false randomly.
Definition: float.hpp:277
Base class for assignments
Definition: float.hh:84
virtual bool operator()(void) const =0
Test whether all assignments have been iterated.