Generated on Sat Jul 28 2018 17:09:41 for Gecode by doxygen 1.8.14
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: 2016-10-20 17:25:30 +0200 (Thu, 20 Oct 2016) $ by $Author: schulte $
15  * $Revision: 15217 $
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);
237  void disable(void);
239  void enable(void);
241  unsigned int propagators(void);
242  };
243 
248  class Test : public Base {
249  protected:
251  int arity;
259  bool reified;
261  int rms;
265  bool testfix;
269 
270  bool eqv(void) const;
273  bool imp(void) const;
275  bool pmi(void) const;
277  public:
285  Test(const std::string& s, int a, const Gecode::FloatVal& d,
287  bool r);
295  Test(const std::string& s, int a,
298  bool r);
300  virtual Assignment* assignment(void) const;
303  virtual bool extendAssignement(Assignment& a) const;
305  virtual MaybeType solution(const Assignment&) const = 0;
308  bool subsumed(const TestSpace& ts) const;
310  virtual bool ignore(const Assignment& a) const;
312  virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) = 0;
314  virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x,
315  Gecode::Reify r);
317  virtual bool run(void);
319 
320  static std::string str(Gecode::FloatRelType frt);
323  static std::string str(Gecode::FloatNum f);
325  static std::string str(Gecode::FloatVal f);
327  static std::string str(const Gecode::FloatValArgs& f);
329 
337  bool flip(void);
339  };
341 
344  private:
346  static const Gecode::FloatRelType frts[6];
348  int i;
349  public:
351  FloatRelTypes(void);
353  void reset(void);
355  bool operator()(void) const;
357  void operator++(void);
359  Gecode::FloatRelType frt(void) const;
360  };
361 
362  }
363 }
364 
369 std::ostream& operator<<(std::ostream& os, const Test::Float::Assignment& a);
370 
371 #include "test/float.hpp"
372 
373 #endif
374 
375 // STATISTICS: test-float
376 
static MaybeType eq(Gecode::FloatVal x, Gecode::FloatVal y)
Whether x and y are equal.
Definition: float.hpp:272
Passing float arguments.
Definition: float.hh:954
Gecode::FloatNum step
Step for going to next solution.
Definition: float.hh:255
virtual ~RandomAssignment(void)
Destructor.
Definition: float.hpp:155
NodeType t
Type of node.
Definition: bool-expr.cpp:234
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:445
AssignmentType
Assignment possible types.
Definition: float.hh:65
void reset(void)
Reset iterator.
Definition: float.hpp:296
unsigned int propagators(void)
Return the number of propagators.
Definition: float.cpp:414
Gecode::FloatRelType frt(void) const
Return current relation type.
Definition: float.hpp:308
const FloatNum max
Largest allowed float value.
Definition: float.hh:848
void enable(void)
Enable propagators in space.
Definition: float.cpp:190
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:352
bool operator()(void) const
Test whether iterator is done.
Definition: float.hpp:300
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:265
bool imp(void) const
Test whether implication as reification mode is supported.
Definition: float.hpp:168
static MaybeType cmp(Gecode::FloatVal x, Gecode::FloatRelType r, Gecode::FloatVal y)
Compare x and y with respect to r.
Definition: float.hpp:239
bool testsubsumed
Whether to test for subsumption.
Definition: float.hh:267
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:223
void bound(void)
Assing a random variable to a random bound.
Definition: float.cpp:292
Float variable array.
Definition: float.hh:1031
Computation spaces.
Definition: core.hpp:1748
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
Gecode::IntSet d(v, 7)
Test * test
The test currently run.
Definition: float.hh:181
struct Gecode::@579::NNF::@61::@63 a
For atomic nodes.
virtual MaybeType solution(const Assignment &) const =0
Check for solution.
const FloatNum min
Smallest allowed float value.
Definition: float.hh:850
Iterator for float relation types.
Definition: float.hh:343
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
virtual bool ignore(const Assignment &a) const
Whether to ignore assignment for reification.
Definition: float.cpp:469
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:1069
RandomAssignment(int n, const Gecode::FloatVal &d, int a)
Initialize for a assignments for n variables and values d.
Definition: float.hpp:134
void disable(void)
Disable propagators in space and compute fixpoint (make all idle)
Definition: float.cpp:195
const Test * curPb
Current problem used to complete assignment.
Definition: float.hh:128
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:439
virtual void dropUntil(const Assignment &a)
Add constraints to skip solutions to the a assignment.
Definition: float.cpp:201
virtual bool operator()(void) const
Test whether all assignments have been iterated.
Definition: float.hpp:68
Reification specification.
Definition: int.hh:857
struct Gecode::@579::NNF::@61::@62 b
For binary nodes (and, or, eqv)
Base class for all tests to be run
Definition: test.hh:107
MaybeType operator&(MaybeType a, MaybeType b)
Three-valued conjunction of MaybeType.
Definition: float.hpp:282
bool testsearch
Whether to perform search test.
Definition: float.hh:263
virtual void operator++(void)
Move to next assignment.
Definition: float.cpp:54
virtual Gecode::FloatVal operator[](int i) const
Return value for variable i.
Definition: float.hpp:145
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
bool assigned(void) const
Test whether all variables are assigned.
Definition: float.cpp:207
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
bool pmi(void) const
Test whether reverse implication as reification mode is supported.
Definition: float.hpp:172
Post propagator for f(x \diamond_{\mathit{op}} y) \sim_r z \f$ void rel(Home home
Post propagator for SetVar SetOpType SetVar y
Definition: set.hh:784
Float value type.
Definition: float.hh:338
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:274
Node * x
Pointer to corresponding Boolean expression node.
Definition: bool-expr.cpp:253
Gecode::FloatVal d
Domain for each variable.
Definition: float.hh:87
bool matchAssignment(const Assignment &a) const
Test whether all variables match assignment a.
Definition: float.cpp:215
Region r
Definition: region.cpp:82
Gecode::FloatVal dom
Domain of variables.
Definition: float.hh:253
AssignmentType assigmentType
Gives the type of assignment to use.
Definition: float.hh:257
MaybeType
Type for comparisons and solutions.
Definition: float.hh:55
Space for executing tests.
Definition: float.hh:170
Gecode::FloatVal * dsv
Iterator for each variable.
Definition: float.hh:129
Gecode::FloatVal * vals
The current values for the variables.
Definition: float.hh:150
virtual bool operator()(void) const
Test whether all assignments have been iterated.
Definition: float.hpp:97
virtual bool run(void)
Perform test.
Definition: float.cpp:478
int size(void) const
Return number of variables.
Definition: float.hpp:52
virtual Gecode::FloatVal operator[](int i) const
Return value for variable i.
Definition: float.hpp:101
int arity
Number of variables.
Definition: float.hh:251
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:236
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:259
Generate all assignments.
Definition: float.hh:106
virtual bool operator()(void) const
Test whether all assignments have been iterated.
Definition: float.hpp:141
double FloatNum
Floating point number base type.
Definition: float.hh:110
ReifyMode
Mode for reification.
Definition: int.hh:829
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:307
virtual Assignment * assignment(void) const
Create assignment.
Definition: float.cpp:424
void rel(int i, Gecode::FloatRelType frt, Gecode::FloatVal n)
Perform integer tell operation on x[i].
Definition: float.cpp:248
bool eqv(void) const
Test whether equivalence as reification mode is supported.
Definition: float.hpp:164
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:261
bool reified
Whether the test is for a reified propagator.
Definition: float.hh:183
Assignment(int n0, const Gecode::FloatVal &d0)
Initialize assignments for n0 variables and values d0.
Definition: float.hpp:49
virtual Gecode::FloatVal operator[](int i) const
Return value for variable i.
Definition: float.hpp:72
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.