Generated on Thu Apr 5 2018 19:44:19 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  * Last modified:
14  * $Date$ by $Author$
15  * $Revision$
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;
152  Gecode::FloatNum randval(void);
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(TestSpace& s);
205  virtual Gecode::Space* copy(void);
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 
Passing float arguments.
Definition: float.hh:954
Gecode::FloatNum step
Step for going to next solution.
Definition: float.hh:255
NodeType t
Type of node.
Definition: bool-expr.cpp:234
AssignmentType
Assignment possible types.
Definition: float.hh:65
void post(Home home, Term *t, int n, FloatRelType frt, FloatVal c)
Post propagator for linear constraint over floats.
Definition: post.cpp:242
const FloatNum max
Largest allowed float value.
Definition: float.hh:848
ExecStatus subsumed(Space &home, Propagator &p, int c, TaskArray< Task > &t)
Check for subsumption (all tasks must be assigned)
Definition: subsumption.hpp:42
Gecode::FloatNum step
Step for next assignment.
Definition: float.hh:109
bool testfix
Whether to perform fixpoint test.
Definition: float.hh:265
bool testsubsumed
Whether to test for subsumption.
Definition: float.hh:267
int n
Number of variables.
Definition: float.hh:86
Float variable array.
Definition: float.hh:1031
Computation spaces.
Definition: core.hpp:1668
ExecStatus prune(Space &home, ViewArray< VX > &x, ConstIntView)
Definition: rel.hpp:268
int a
How many assigments still to be generated Generate new value according to domain. ...
Definition: float.hh:151
Test * test
The test currently run.
Definition: float.hh:181
Reify imp(BoolVar x)
Use implication for reification.
Definition: reify.hpp:77
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
Generate all assignments except the last variable and complete it to get a solution.
Definition: float.hh:126
FloatRelType
Relation types for floats.
Definition: float.hh:1069
const Test * curPb
Current problem used to complete assignment.
Definition: float.hh:128
Reification specification.
Definition: int.hh:855
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
Generate random selection of assignments.
Definition: float.hh:148
Reify eqv(BoolVar x)
Use equivalence for reification.
Definition: reify.hpp:73
Gecode::Reify r
Reification information.
Definition: float.hh:179
std::basic_ostream< Char, Traits > & operator<<(std::basic_ostream< Char, Traits > &os, const Dictionary &d)
Print statistics summary.
Definition: scowl.hpp:13621
virtual void operator++(void)=0
Move to next assignment.
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
struct Gecode::@585::NNF::@62::@63 b
For binary nodes (and, or, eqv)
Post propagator for SetVar SetOpType SetVar y
Definition: set.hh:769
Float value type.
Definition: float.hh:338
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:253
struct Gecode::@585::NNF::@62::@64 a
For atomic nodes.
Gecode::FloatVal d
Domain for each variable.
Definition: float.hh:87
Region r
Definition: region.cpp:69
Gecode::FloatVal dom
Domain of variables.
Definition: float.hh:253
AssignmentType assigmentType
Gives the type of assignment to use.
Definition: float.hh:257
bool assigned(View x, int v)
Whether x is assigned to value v.
Definition: single.hpp:47
MaybeType
Type for comparisons and solutions.
Definition: float.hh:55
void rel(Home home, FloatVar x0, FloatRelType frt, FloatVal n)
Propagates .
Definition: rel.cpp:47
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
int size(void) const
Return number of variables.
Definition: float.hpp:52
int arity
Number of variables.
Definition: float.hh:251
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
void assign(Home home, const FloatVarArgs &x, FloatAssign fa, FloatBranchFilter bf, FloatVarValPrint vvp)
Assign all x with value selection vals.
Definition: branch.cpp:115
double FloatNum
Floating point number base type.
Definition: float.hh:110
ReifyMode
Mode for reification.
Definition: int.hh:827
Gecode::FloatNum step
Step for going to next solution.
Definition: float.hh:175
Gecode::FloatNum step
Step for next assignment.
Definition: float.hh:130
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
Base class for assignments
Definition: float.hh:84
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:81