Generated on Sat Feb 7 2015 02:01:16 for Gecode by doxygen 1.8.9.1
rel.cpp
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  * Vincent Barichard <Vincent.Barichard@univ-angers.fr>
6  *
7  * Copyright:
8  * Christian Schulte, 2005
9  * Vincent Barichard, 2012
10  *
11  * Last modified:
12  * $Date: 2015-01-20 20:48:23 +0100 (Tue, 20 Jan 2015) $ by $Author: schulte $
13  * $Revision: 14369 $
14  *
15  * This file is part of Gecode, the generic constraint
16  * development environment:
17  * http://www.gecode.org
18  *
19  * Permission is hereby granted, free of charge, to any person obtaining
20  * a copy of this software and associated documentation files (the
21  * "Software"), to deal in the Software without restriction, including
22  * without limitation the rights to use, copy, modify, merge, publish,
23  * distribute, sublicense, and/or sell copies of the Software, and to
24  * permit persons to whom the Software is furnished to do so, subject to
25  * the following conditions:
26  *
27  * The above copyright notice and this permission notice shall be
28  * included in all copies or substantial portions of the Software.
29  *
30  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
31  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
32  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
33  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
34  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
35  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
36  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
37  *
38  */
39 
40 #include "test/float.hh"
41 
42 #include <gecode/minimodel.hh>
43 
44 namespace Test { namespace Float {
45 
47  namespace Rel {
48 
54  class FloatVarXY : public Test {
56  protected:
59  public:
62  : Test("Rel::Float::Var::XY::"+str(frt0)+"::"+str(n),
63  n+1,-3,3,st,CPLT_ASSIGNMENT,n==1),
64  frt(frt0) {
65  testsubsumed = false;
66  }
68  virtual MaybeType solution(const Assignment& x) const {
69  if (x.size() == 2) {
70  return cmp(x[0],frt,x[1]);
71  } else {
72  MaybeType r1 = cmp(x[0],frt,x[2]);
73  MaybeType r2 = cmp(x[1],frt,x[2]);
74  if ((r1 == MT_TRUE) && (r2 == MT_TRUE)) return MT_TRUE;
75  else if ((r1 == MT_FALSE) || (r2 == MT_FALSE)) return MT_FALSE;
76  else return MT_MAYBE;
77  }
78  }
80  virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
81  using namespace Gecode;
82  if (x.size() == 2) {
83  rel(home, x[0], frt, x[1]);
84  } else {
85  FloatVarArgs y(2);
86  y[0]=x[0]; y[1]=x[1];
87  rel(home, y, frt, x[2]);
88  }
89  }
91  virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x,
92  Gecode::Reify r) {
93  assert(x.size() == 2);
94  Gecode::rel(home, x[0], frt, x[1], r);
95  }
96  };
97 
99  class FloatVarXX : public Test {
100  protected:
103  public:
106  : Test("Rel::Float::Var::XX::"+str(frt0),
107  1,-3,3,st,CPLT_ASSIGNMENT,true),
108  frt(frt0) {
109  testsubsumed = false;
110  }
112  virtual MaybeType solution(const Assignment& x) const {
113  return cmp(x[0],frt,x[0]);
114  }
116  virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
117  Gecode::rel(home, x[0], frt, x[0]);
118  }
121  Gecode::Reify r) {
122  Gecode::rel(home, x[0], frt, x[0], r);
123  }
124  };
125 
127  class FloatFloat : public Test {
128  protected:
133  public:
136  Gecode::FloatNum st)
137  : Test("Rel::Float::Float::"+str(frt0)+"::"+str(n)+"::"+str(c0),
138  n,-3,3,st,CPLT_ASSIGNMENT,n==1),
139  frt(frt0), c(c0) {
140  testsubsumed = false;
141  }
143  virtual MaybeType solution(const Assignment& x) const {
144  if (x.size() == 1) {
145  return cmp(x[0],frt,c);
146  } else {
147  return cmp(x[0],frt,c) & cmp(x[1],frt,c);
148  }
149  }
151  virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
152  using namespace Gecode;
153  if (x.size() == 1)
154  rel(home, x[0], frt, c);
155  else
156  rel(home, x, frt, c);
157  }
160  Gecode::Reify r) {
161  assert(x.size() == 1);
162  Gecode::rel(home, x[0], frt, c, r);
163  }
164  };
165 
167  class Create {
168  public:
170  Create(void) {
171  using namespace Gecode;
172  Gecode::FloatNum step = 0.7;
173  for (FloatRelTypes frts; frts(); ++frts) {
174  (void) new FloatVarXY(frts.frt(),1,step);
175  (void) new FloatVarXY(frts.frt(),2,step);
176  (void) new FloatVarXX(frts.frt(),step);
177  for (int c=-4; c<=4; c++) {
178  (void) new FloatFloat(frts.frt(),1,c,step);
179  (void) new FloatFloat(frts.frt(),2,c,step);
180  }
181  }
182  }
183  };
184 
187 
188  }
189 
190 }}
191 
192 // STATISTICS: test-float
virtual void post(Gecode::Space &home, Gecode::FloatVarArray &x, Gecode::Reify r)
Post reified constraint on x for r.
Definition: rel.cpp:120
Create c
Definition: rel.cpp:185
virtual MaybeType solution(const Assignment &x) const
Test whether x is solution
Definition: rel.cpp:112
Gecode::FloatNum step
Step for going to next solution.
Definition: float.hh:249
virtual void post(Gecode::Space &home, Gecode::FloatVarArray &x, Gecode::Reify r)
Post reified constraint on x for r.
Definition: rel.cpp:91
Create(void)
Perform creation and registration.
Definition: rel.cpp:170
virtual void post(Gecode::Space &home, Gecode::FloatVarArray &x)
Post constraint on x.
Definition: rel.cpp:151
Help class to create and register tests.
Definition: rel.cpp:167
Passing float variables.
Definition: float.hh:966
Test for simple relation involving float variables
Definition: rel.cpp:55
Gecode::FloatVal c
Float constant.
Definition: rel.cpp:132
static MaybeType cmp(Gecode::FloatVal x, Gecode::FloatRelType r, Gecode::FloatVal y)
Compare x and y with respect to r.
Definition: float.hpp:239
FloatVarXX(Gecode::FloatRelType frt0, Gecode::FloatNum st)
Create and register test.
Definition: rel.cpp:105
bool testsubsumed
Whether to test for subsumption.
Definition: float.hh:261
static std::string str(Gecode::FloatRelType frt)
Map float relation to string.
Definition: float.hpp:198
Float variable array.
Definition: float.hh:1016
Computation spaces.
Definition: core.hpp:1362
Gecode::FloatRelType frt
Float relation type to propagate.
Definition: rel.cpp:102
Iterator for float relation types.
Definition: float.hh:337
int n
Number of negative literals for node type.
Definition: bool-expr.cpp:238
virtual void post(Gecode::Space &home, Gecode::FloatVarArray &x)
Post constraint on x.
Definition: rel.cpp:80
void rel(Home home, IntVar x, SetRelType rt, SetVar s, Reify r)
Post propagator for .
Definition: rel.cpp:229
NNF * r
Right subtree.
Definition: bool-expr.cpp:246
FloatRelType
Relation types for floats.
Definition: float.hh:1054
Reification specification.
Definition: int.hh:854
Test for simple relation involving shared float variables
Definition: rel.cpp:99
virtual void post(Gecode::Space &home, Gecode::FloatVarArray &x, Gecode::Reify r)
Post reified constraint on x for r.
Definition: rel.cpp:159
FloatFloat(Gecode::FloatRelType frt0, int n, Gecode::FloatNum c0, Gecode::FloatNum st)
Create and register test.
Definition: rel.cpp:135
General test support.
Definition: afc.cpp:43
virtual MaybeType solution(const Assignment &x) const
Test whether x is solution
Definition: rel.cpp:68
FloatVarXY(Gecode::FloatRelType frt0, int n, Gecode::FloatNum st)
Create and register test.
Definition: rel.cpp:61
Float value type.
Definition: float.hh:321
Node * x
Pointer to corresponding Boolean expression node.
Definition: bool-expr.cpp:253
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
Gecode::FloatRelType frt
Float relation type to propagate.
Definition: rel.cpp:130
int size(void) const
Return number of variables.
Definition: float.hpp:52
virtual MaybeType solution(const Assignment &x) const
Test whether x is solution
Definition: rel.cpp:143
virtual void post(Gecode::Space &home, Gecode::FloatVarArray &x)
Post constraint on x.
Definition: rel.cpp:116
Gecode toplevel namespace
int size(void) const
Return size of array (number of elements)
Definition: array.hpp:985
double FloatNum
Floating point number base type.
Definition: float.hh:108
Test for simple relation involving float variable and float constant
Definition: rel.cpp:127
Base class for assignments
Definition: float.hh:84
Gecode::FloatRelType frt
Float relation type to propagate.
Definition: rel.cpp:58