Generated on Sat Jan 12 2019 20:58:51 for Gecode by doxygen 1.8.13
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  * This file is part of Gecode, the generic constraint
14  * development environment:
15  * http://www.gecode.org
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 
45 namespace 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 
65  };
66 
67  class Test;
68 
79  class Assignment {
81  protected:
82  int n;
84  public:
86  Assignment(int n0, const Gecode::FloatVal& d0);
88  virtual bool operator()(void) const = 0;
90  virtual void operator++(void) = 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 operator()(void) const;
112  virtual void operator++(void);
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);
131  virtual bool operator()(void) const;
133  virtual void operator++(void);
135  virtual Gecode::FloatVal operator[](int i) const;
137  virtual void set(int i, const Gecode::FloatVal& val);
139  virtual ~ExtAssignment(void);
140  };
141 
142 
144  class RandomAssignment : public Assignment {
145  protected:
147  int a;
148  Gecode::FloatNum randval(void);
150  public:
152  RandomAssignment(int n, const Gecode::FloatVal& d, int a);
154  virtual bool operator()(void) const;
156  virtual void operator++(void);
158  virtual Gecode::FloatVal operator[](int i) const;
160  virtual void set(int i, const Gecode::FloatVal& val);
162  virtual ~RandomAssignment(void);
163  };
164 
166  class TestSpace : public Gecode::Space {
167  public:
179  bool reified;
180 
197  Gecode::ReifyMode rm);
199  TestSpace(TestSpace& s);
201  virtual Gecode::Space* copy(void);
203  virtual void dropUntil(const Assignment& a);
205  bool assigned(void) const;
207  bool matchAssignment(const Assignment& a) const;
209  void post(void);
211  bool failed(void);
213  void rel(int i, Gecode::FloatRelType frt, Gecode::FloatVal n);
215  void rel(bool sol);
219  void assign(const Assignment& a, MaybeType& sol, bool skip=false);
221  void bound(void);
225  Gecode::FloatNum cut(int* cutDirections);
227  void prune(int i);
229  void prune(void);
231  bool prune(const Assignment& a, bool testfix);
233  void disable(void);
235  void enable(void);
237  unsigned int propagators(void);
238  };
239 
244  class Test : public Base {
245  protected:
247  int arity;
255  bool reified;
257  int rms;
261  bool testfix;
265 
266  bool eqv(void) const;
269  bool imp(void) const;
271  bool pmi(void) const;
273  public:
281  Test(const std::string& s, int a, const Gecode::FloatVal& d,
283  bool r);
291  Test(const std::string& s, int a,
294  bool r);
296  virtual Assignment* assignment(void) const;
299  virtual bool extendAssignement(Assignment& a) const;
301  virtual MaybeType solution(const Assignment&) const = 0;
304  bool subsumed(const TestSpace& ts) const;
306  virtual bool ignore(const Assignment& a) const;
308  virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) = 0;
310  virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x,
311  Gecode::Reify r);
313  virtual bool run(void);
315 
316  static std::string str(Gecode::FloatRelType frt);
319  static std::string str(Gecode::FloatNum f);
321  static std::string str(Gecode::FloatVal f);
323  static std::string str(const Gecode::FloatValArgs& f);
325 
333  bool flip(void);
335  };
337 
340  private:
342  static const Gecode::FloatRelType frts[6];
344  int i;
345  public:
347  FloatRelTypes(void);
349  void reset(void);
351  bool operator()(void) const;
353  void operator++(void);
355  Gecode::FloatRelType frt(void) const;
356  };
357 
358  }
359 }
360 
365 std::ostream& operator<<(std::ostream& os, const Test::Float::Assignment& a);
366 
367 #include "test/float.hpp"
368 
369 #endif
370 
371 // STATISTICS: test-float
372 
Passing float arguments.
Definition: float.hh:950
Gecode::FloatNum step
Step for going to next solution.
Definition: float.hh:251
NodeType t
Type of node.
Definition: bool-expr.cpp:230
AssignmentType
Assignment possible types.
Definition: float.hh:61
void post(Home home, Term *t, int n, FloatRelType frt, FloatVal c)
Post propagator for linear constraint over floats.
Definition: post.cpp:238
const FloatNum max
Largest allowed float value.
Definition: float.hh:844
ExecStatus subsumed(Space &home, Propagator &p, int c, TaskArray< Task > &t)
Check for subsumption (all tasks must be assigned)
Definition: subsumption.hpp:38
Gecode::FloatNum step
Step for next assignment.
Definition: float.hh:105
bool testfix
Whether to perform fixpoint test.
Definition: float.hh:261
bool testsubsumed
Whether to test for subsumption.
Definition: float.hh:263
int n
Number of variables.
Definition: float.hh:82
Float variable array.
Definition: float.hh:1030
Computation spaces.
Definition: core.hpp:1701
ExecStatus prune(Space &home, ViewArray< VX > &x, ConstIntView)
Definition: rel.hpp:264
int a
How many assigments still to be generated Generate new value according to domain. ...
Definition: float.hh:147
Test * test
The test currently run.
Definition: float.hh:177
Reify imp(BoolVar x)
Use implication for reification.
Definition: reify.hpp:73
const FloatNum min
Smallest allowed float value.
Definition: float.hh:846
Iterator for float relation types.
Definition: float.hh:339
virtual ~Assignment(void)
Destructor.
Definition: float.hpp:52
Gecode::IntArgs i({1, 2, 3, 4})
Generate all assignments except the last variable and complete it to get a solution.
Definition: float.hh:122
FloatRelType
Relation types for floats.
Definition: float.hh:1068
const Test * curPb
Current problem used to complete assignment.
Definition: float.hh:124
struct Gecode::@593::NNF::@62::@63 b
For binary nodes (and, or, eqv)
Reification specification.
Definition: int.hh:876
Base class for all tests to be run
Definition: test.hh:103
MaybeType operator&(MaybeType a, MaybeType b)
Three-valued conjunction of MaybeType.
Definition: float.hpp:278
bool testsearch
Whether to perform search test.
Definition: float.hh:259
Generate random selection of assignments.
Definition: float.hh:144
Reify eqv(BoolVar x)
Use equivalence for reification.
Definition: reify.hpp:69
Gecode::Reify r
Reification information.
Definition: float.hh:175
std::basic_ostream< Char, Traits > & operator<<(std::basic_ostream< Char, Traits > &os, const Dictionary &d)
Print statistics summary.
Definition: scowl.hpp:13617
virtual void operator++(void)=0
Move to next assignment.
Gecode::FloatVarArray x
Variables to be tested.
Definition: float.hh:173
Gecode::FloatVal d
Initial domain.
Definition: float.hh:169
General test support.
Definition: afc.cpp:39
Post propagator for SetVar SetOpType SetVar y
Definition: set.hh:767
Float value type.
Definition: float.hh:334
virtual Gecode::FloatVal operator[](int i) const =0
Return value for variable i.
Node * x
Pointer to corresponding Boolean expression node.
Definition: bool-expr.cpp:249
Gecode::FloatVal d
Domain for each variable.
Definition: float.hh:83
Region r
Definition: region.cpp:65
Gecode::FloatVal dom
Domain of variables.
Definition: float.hh:249
AssignmentType assigmentType
Gives the type of assignment to use.
Definition: float.hh:253
bool assigned(View x, int v)
Whether x is assigned to value v.
Definition: single.hpp:43
MaybeType
Type for comparisons and solutions.
Definition: float.hh:51
void rel(Home home, FloatVar x0, FloatRelType frt, FloatVal n)
Propagates .
Definition: rel.cpp:43
Space for executing tests.
Definition: float.hh:166
Gecode::FloatVal * dsv
Iterator for each variable.
Definition: float.hh:125
Gecode::FloatVal * vals
The current values for the variables.
Definition: float.hh:146
int size(void) const
Return number of variables.
Definition: float.hpp:48
int arity
Number of variables.
Definition: float.hh:247
Gecode::FloatVal * dsv
Iterator for each variable.
Definition: float.hh:104
bool reified
Does the constraint also exist as reified constraint.
Definition: float.hh:255
Generate all assignments.
Definition: float.hh:102
void assign(Home home, const FloatVarArgs &x, FloatAssign fa, FloatBranchFilter bf, FloatVarValPrint vvp)
Assign all x with value selection vals.
Definition: branch.cpp:111
double FloatNum
Floating point number base type.
Definition: float.hh:106
ReifyMode
Mode for reification.
Definition: int.hh:848
struct Gecode::@593::NNF::@62::@64 a
For atomic nodes.
Gecode::FloatNum step
Step for going to next solution.
Definition: float.hh:171
Gecode::FloatNum step
Step for next assignment.
Definition: float.hh:126
int rms
Which reification modes are supported.
Definition: float.hh:257
bool reified
Whether the test is for a reified propagator.
Definition: float.hh:179
Assignment(int n0, const Gecode::FloatVal &d0)
Initialize assignments for n0 variables and values d0.
Definition: float.hpp:45
Base class for assignments
Definition: float.hh:80
virtual bool operator()(void) const =0
Test whether all assignments have been iterated.
Reify pmi(BoolVar x)
Use reverse implication for reification.
Definition: reify.hpp:77