Generated on Mon Jul 27 2020 00:00:00 for Gecode by doxygen 1.8.18
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  * This file is part of Gecode, the generic constraint
12  * development environment:
13  * http://www.gecode.org
14  *
15  * Permission is hereby granted, free of charge, to any person obtaining
16  * a copy of this software and associated documentation files (the
17  * "Software"), to deal in the Software without restriction, including
18  * without limitation the rights to use, copy, modify, merge, publish,
19  * distribute, sublicense, and/or sell copies of the Software, and to
20  * permit persons to whom the Software is furnished to do so, subject to
21  * the following conditions:
22  *
23  * The above copyright notice and this permission notice shall be
24  * included in all copies or substantial portions of the Software.
25  *
26  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
27  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
28  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
29  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
30  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
31  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
32  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
33  *
34  */
35 
36 #include "test/float.hh"
37 
38 #include <gecode/minimodel.hh>
39 
40 namespace Test { namespace Float {
41 
43  namespace Rel {
44 
50  class FloatVarXY : public Test {
52  protected:
55  public:
58  : Test("Rel::Float::Var::XY::"+str(frt0)+"::"+str(n),
59  n+1,-3,3,st,CPLT_ASSIGNMENT,n==1),
60  frt(frt0) {
61  testsubsumed = false;
62  }
64  virtual MaybeType solution(const Assignment& x) const {
65  if (x.size() == 2) {
66  return cmp(x[0],frt,x[1]);
67  } else {
68  MaybeType r1 = cmp(x[0],frt,x[2]);
69  MaybeType r2 = cmp(x[1],frt,x[2]);
70  if ((r1 == MT_TRUE) && (r2 == MT_TRUE)) return MT_TRUE;
71  else if ((r1 == MT_FALSE) || (r2 == MT_FALSE)) return MT_FALSE;
72  else return MT_MAYBE;
73  }
74  }
76  virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
77  using namespace Gecode;
78  if (x.size() == 2) {
79  rel(home, x[0], frt, x[1]);
80  } else {
81  FloatVarArgs y(2);
82  y[0]=x[0]; y[1]=x[1];
83  rel(home, y, frt, x[2]);
84  }
85  }
87  virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x,
88  Gecode::Reify r) {
89  assert(x.size() == 2);
90  Gecode::rel(home, x[0], frt, x[1], r);
91  }
92  };
93 
95  class FloatVarXX : public Test {
96  protected:
99  public:
102  : Test("Rel::Float::Var::XX::"+str(frt0),
103  1,-3,3,st,CPLT_ASSIGNMENT,true),
104  frt(frt0) {
105  testsubsumed = false;
106  }
108  virtual MaybeType solution(const Assignment& x) const {
109  return cmp(x[0],frt,x[0]);
110  }
112  virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
113  Gecode::rel(home, x[0], frt, x[0]);
114  }
117  Gecode::Reify r) {
118  Gecode::rel(home, x[0], frt, x[0], r);
119  }
120  };
121 
123  class FloatFloat : public Test {
124  protected:
129  public:
132  Gecode::FloatNum st)
133  : Test("Rel::Float::Float::"+str(frt0)+"::"+str(n)+"::"+str(c0),
134  n,-3,3,st,CPLT_ASSIGNMENT,n==1),
135  frt(frt0), c(c0) {
136  testsubsumed = false;
137  }
139  virtual MaybeType solution(const Assignment& x) const {
140  if (x.size() == 1) {
141  return cmp(x[0],frt,c);
142  } else {
143  return cmp(x[0],frt,c) & cmp(x[1],frt,c);
144  }
145  }
147  virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
148  using namespace Gecode;
149  if (x.size() == 1)
150  rel(home, x[0], frt, c);
151  else
152  rel(home, x, frt, c);
153  }
156  Gecode::Reify r) {
157  assert(x.size() == 1);
158  Gecode::rel(home, x[0], frt, c, r);
159  }
160  };
161 
163  class Create {
164  public:
166  Create(void) {
167  using namespace Gecode;
168  Gecode::FloatNum step = 0.7;
169  for (FloatRelTypes frts; frts(); ++frts) {
170  (void) new FloatVarXY(frts.frt(),1,step);
171  (void) new FloatVarXY(frts.frt(),2,step);
172  (void) new FloatVarXX(frts.frt(),step);
173  for (int c=-4; c<=4; c++) {
174  (void) new FloatFloat(frts.frt(),1,c,step);
175  (void) new FloatFloat(frts.frt(),2,c,step);
176  }
177  }
178  }
179  };
180 
183 
184  }
185 
186 }}
187 
188 // STATISTICS: test-float
Passing float variables.
Definition: float.hh:979
Gecode::FloatRelType frt
Float relation type to propagate.
Definition: rel.cpp:54
Region r
Definition: region.cpp:65
Post propagator for SetVar SetOpType SetVar y
Definition: set.hh:767
@ MT_MAYBE
Definition: float.hh:54
@ MT_FALSE
Definition: float.hh:52
virtual void post(Gecode::Space &home, Gecode::FloatVarArray &x, Gecode::Reify r)
Post reified constraint on x for r.
Definition: rel.cpp:116
virtual MaybeType solution(const Assignment &x) const
Test whether x is solution
Definition: rel.cpp:139
virtual void post(Gecode::Space &home, Gecode::FloatVarArray &x)
Post constraint on x.
Definition: rel.cpp:147
virtual void post(Gecode::Space &home, Gecode::FloatVarArray &x)
Post constraint on x.
Definition: rel.cpp:112
FloatVarXX(Gecode::FloatRelType frt0, Gecode::FloatNum st)
Create and register test.
Definition: rel.cpp:101
Computation spaces.
Definition: core.hpp:1742
@ MT_TRUE
Definition: float.hh:53
FloatRelType
Relation types for floats.
Definition: float.hh:1068
virtual void post(Gecode::Space &home, Gecode::FloatVarArray &x, Gecode::Reify r)
Post reified constraint on x for r.
Definition: rel.cpp:155
FloatVarXY(Gecode::FloatRelType frt0, int n, Gecode::FloatNum st)
Create and register test.
Definition: rel.cpp:57
virtual void post(Gecode::Space &home, Gecode::FloatVarArray &x, Gecode::Reify r)
Post reified constraint on x for r.
Definition: rel.cpp:87
Gecode::FloatVal c
Float constant.
Definition: rel.cpp:128
Test for simple relation involving float variables
Definition: rel.cpp:51
Gecode toplevel namespace
Node * x
Pointer to corresponding Boolean expression node.
Definition: bool-expr.cpp:249
Reification specification.
Definition: int.hh:876
FloatFloat(Gecode::FloatRelType frt0, int n, Gecode::FloatNum c0, Gecode::FloatNum st)
Create and register test.
Definition: rel.cpp:131
double FloatNum
Floating point number base type.
Definition: float.hh:106
Test for simple relation involving float variable and float constant
Definition: rel.cpp:123
@ CPLT_ASSIGNMENT
Definition: float.hh:62
Create c
Definition: rel.cpp:181
virtual void post(Gecode::Space &home, Gecode::FloatVarArray &x)
Post constraint on x.
Definition: rel.cpp:76
Float value type.
Definition: float.hh:334
Gecode::FloatRelType frt
Float relation type to propagate.
Definition: rel.cpp:98
void rel(Home home, FloatVar x0, FloatRelType frt, FloatVal n)
Propagates .
Definition: rel.cpp:43
static MaybeType cmp(Gecode::FloatVal x, Gecode::FloatRelType r, Gecode::FloatVal y)
Compare x and y with respect to r.
Definition: float.hpp:235
Test for simple relation involving shared float variables
Definition: rel.cpp:95
virtual MaybeType solution(const Assignment &x) const
Test whether x is solution
Definition: rel.cpp:64
Gecode::FloatNum step
Step for going to next solution.
Definition: float.hh:251
static std::string str(Gecode::FloatRelType frt)
Map float relation to string.
Definition: float.hpp:194
Create(void)
Perform creation and registration.
Definition: rel.cpp:166
MaybeType
Type for comparisons and solutions.
Definition: float.hh:51
Float variable array.
Definition: float.hh:1030
Gecode::FloatRelType frt
Float relation type to propagate.
Definition: rel.cpp:126
General test support.
Definition: afc.cpp:39
Base class for assignments
Definition: float.hh:80
Iterator for float relation types.
Definition: float.hh:339
int n
Number of negative literals for node type.
Definition: bool-expr.cpp:234
virtual MaybeType solution(const Assignment &x) const
Test whether x is solution
Definition: rel.cpp:108
Help class to create and register tests.
Definition: rel.cpp:163
bool testsubsumed
Whether to test for subsumption.
Definition: float.hh:263
void rel(Home home, IntVar x, SetRelType rt, SetVar s, Reify r)
Post propagator for .
Definition: rel.cpp:236