Generated on Mon May 30 2016 09:02:56 for Gecode by doxygen 1.8.11
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;
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(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 
Passing float arguments.
Definition: float.hh:937
Gecode::FloatNum step
Step for going to next solution.
Definition: float.hh:249
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:228
virtual bool operator()(void) const =0
Test whether all assignments have been iterated.
const FloatNum max
Largest allowed float value.
Definition: float.hh:831
Gecode::FloatNum step
Step for next assignment.
Definition: float.hh:109
bool testfix
Whether to perform fixpoint test.
Definition: float.hh:259
bool testsubsumed
Whether to test for subsumption.
Definition: float.hh:261
int n
Number of variables.
Definition: float.hh:86
Float variable array.
Definition: float.hh:1016
Computation spaces.
Definition: core.hpp:1362
ExecStatus prune(Space &home, ViewArray< VX > &x, ConstIntView)
Definition: rel.hpp:245
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: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
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
FloatRelType
Relation types for floats.
Definition: float.hh:1054
const Test * curPb
Current problem used to complete assignment.
Definition: float.hh:128
Reification specification.
Definition: int.hh:854
Base class for all tests to be run
Definition: test.hh:107
bool testsearch
Whether to perform search test.
Definition: float.hh:257
struct Gecode::@519::NNF::@60::@62 a
For atomic nodes.
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::@519::NNF::@60::@61 b
For binary nodes (and, or, eqv)
ExecStatus subsumed(Space &home, Propagator &p, TaskArray< Task > &t)
Check tasks t for subsumption.
Definition: subsumption.hpp:42
Float value type.
Definition: float.hh:321
BrancherHandle assign(Home home, const FloatVarArgs &x, FloatAssign fa, FloatBranchFilter bf, FloatVarValPrint vvp)
Assign all x with value selection vals.
Definition: branch.cpp:113
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
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
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
int arity
Number of variables.
Definition: float.hh:245
virtual Gecode::FloatVal operator[](int i) const =0
Return value for variable i.
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 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:255
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
Reify pmi(BoolVar x)
Use reverse implication for reification.
Definition: reify.hpp:81