Generated on Thu Jan 16 2025 00:00:00 for Gecode by doxygen 1.14.0
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
40namespace Test { namespace Float {
41
43 namespace Rel {
44
50
51 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 }
63
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 }
75
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 }
86
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 }
107
108 virtual MaybeType solution(const Assignment& x) const {
109 return cmp(x[0],frt,x[0]);
110 }
111
113 Gecode::rel(home, x[0], frt, x[0]);
114 }
115
118 Gecode::rel(home, x[0], frt, x[0], r);
119 }
120 };
121
123 class FloatFloat : public Test {
124 protected:
129 public:
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 }
138
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 }
146
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 }
154
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
Float value type.
Definition float.hh:334
Passing float variables.
Definition float.hh:982
Float variable array.
Definition float.hh:1033
Reification specification.
Definition int.hh:891
Computation spaces.
Definition core.hpp:1744
Base class for assignments
Definition float.hh:80
Iterator for float relation types.
Definition float.hh:339
Help class to create and register tests.
Definition rel.cpp:163
Create(void)
Perform creation and registration.
Definition rel.cpp:166
Test for simple relation involving float variable and float constant
Definition rel.cpp:123
Gecode::FloatRelType frt
Float relation type to propagate.
Definition rel.cpp:126
virtual void post(Gecode::Space &home, Gecode::FloatVarArray &x, Gecode::Reify r)
Post reified constraint on x for r.
Definition rel.cpp:155
Gecode::FloatVal c
Float constant.
Definition rel.cpp:128
FloatFloat(Gecode::FloatRelType frt0, int n, Gecode::FloatNum c0, Gecode::FloatNum st)
Create and register test.
Definition rel.cpp:131
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
Test for simple relation involving shared float variables
Definition rel.cpp:95
virtual void post(Gecode::Space &home, Gecode::FloatVarArray &x, Gecode::Reify r)
Post reified constraint on x for r.
Definition rel.cpp:116
virtual void post(Gecode::Space &home, Gecode::FloatVarArray &x)
Post constraint on x.
Definition rel.cpp:112
Gecode::FloatRelType frt
Float relation type to propagate.
Definition rel.cpp:98
virtual MaybeType solution(const Assignment &x) const
Test whether x is solution
Definition rel.cpp:108
FloatVarXX(Gecode::FloatRelType frt0, Gecode::FloatNum st)
Create and register test.
Definition rel.cpp:101
Test for simple relation involving float variables
Definition rel.cpp:51
virtual void post(Gecode::Space &home, Gecode::FloatVarArray &x)
Post constraint on x.
Definition rel.cpp:76
Gecode::FloatRelType frt
Float relation type to propagate.
Definition rel.cpp:54
virtual MaybeType solution(const Assignment &x) const
Test whether x is solution
Definition rel.cpp:64
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
static MaybeType cmp(Gecode::FloatVal x, Gecode::FloatRelType r, Gecode::FloatVal y)
Compare x and y with respect to r.
Definition float.hpp:235
bool testsubsumed
Whether to test for subsumption.
Definition float.hh:263
static std::string str(Gecode::FloatRelType frt)
Map float relation to string.
Definition float.hpp:194
void rel(Home home, FloatVar x0, FloatRelType frt, FloatVar x1)
Post propagator for .
Definition rel.cpp:68
double FloatNum
Floating point number base type.
Definition float.hh:106
FloatRelType
Relation types for floats.
Definition float.hh:1074
Gecode toplevel namespace
Post propagator for SetVar SetOpType SetVar y
Definition set.hh:773
Post propagator for SetVar x
Definition set.hh:773
Tests for relation constraints
Definition rel.cpp:43
Testing domain floats.
Definition float.cpp:43
@ CPLT_ASSIGNMENT
Definition float.hh:62
MaybeType
Type for comparisons and solutions.
Definition float.hh:51
General test support.
Definition afc.cpp:39
Region r
Definition region.cpp:65