Generated on Thu Jan 16 2025 00:00:00 for Gecode by doxygen 1.14.0
float.hpp
Go to the documentation of this file.
1/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2/*
3 * Main authors:
4 * Filip Konvicka <filip.konvicka@logis.cz>
5 * Lubomir Moric <lubomir.moric@logis.cz>
6 * Vincent Barichard <Vincent.Barichard@univ-angers.fr>
7 *
8 * Contributing authors:
9 * Christian Schulte <schulte@gecode.org>
10 *
11 * Copyright:
12 * LOGIS, s.r.o., 2008
13 * Christian Schulte, 2010
14 * Vincent Barichard, 2012
15 *
16 * This file is part of Gecode, the generic constraint
17 * development environment:
18 * http://www.gecode.org
19 *
20 * Permission is hereby granted, free of charge, to any person obtaining
21 * a copy of this software and associated documentation files (the
22 * "Software"), to deal in the Software without restriction, including
23 * without limitation the rights to use, copy, modify, merge, publish,
24 * distribute, sublicense, and/or sell copies of the Software, and to
25 * permit persons to whom the Software is furnished to do so, subject to
26 * the following conditions:
27 *
28 * The above copyright notice and this permission notice shall be
29 * included in all copies or substantial portions of the Software.
30 *
31 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
32 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
33 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
34 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
35 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
36 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
37 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
38 *
39 */
40
41namespace Gecode { namespace Float {
42
43 /*
44 * Creation of new variable implementations
45 *
46 */
47
50 : FloatVarImpBase(home), dom(d) {}
51
55
56
57 /*
58 * Operations on float variable implementations
59 *
60 */
61
63 FloatVarImp::domain(void) const {
64 return dom;
65 }
67 FloatVarImp::min(void) const {
68 return dom.min();
69 }
71 FloatVarImp::max(void) const {
72 return dom.max();
73 }
75 FloatVarImp::val(void) const {
76 return dom;
77 }
79 FloatVarImp::med(void) const {
80 return dom.med();
81 }
82
83 forceinline bool
85 return dom.tight();
86 }
87
89 FloatVarImp::size(void) const {
90 return dom.size();
91 }
92
93
94 /*
95 * Tests
96 *
97 */
98
99 forceinline bool
101 return dom.zero_in();
102 }
103 forceinline bool
105 return dom.in(n);
106 }
107 forceinline bool
108 FloatVarImp::in(const FloatVal& n) const {
109 return subset(n,dom);
110 }
111
112
113 /*
114 * Support for delta information
115 *
116 */
119 return static_cast<const FloatDelta&>(d).min();
120 }
123 return static_cast<const FloatDelta&>(d).max();
124 }
125
126
127 /*
128 * Tell operations (to be inlined: performing bounds checks first)
129 *
130 */
131
134 if (n > dom.max()) return fail(home);
135 if ((n <= dom.min()) || assigned()) return ME_FLOAT_NONE;
136 FloatDelta d(dom.min(),n);
138 dom = intersect(dom,FloatVal(n,dom.max()));
139 if (assigned()) me = ME_FLOAT_VAL;
141 (me == ME_FLOAT_BND));
142 return notify(home,me,d);
143 }
145 FloatVarImp::gq(Space& home, const FloatVal& n) {
146 if (n.min() > dom.max()) return fail(home);
147 if ((n.min() <= dom.min()) || assigned()) return ME_FLOAT_NONE;
148 FloatDelta d(dom.min(),n.min());
150 dom = intersect(dom,FloatVal(n.min(),dom.max()));
151 if (assigned()) me = ME_FLOAT_VAL;
153 (me == ME_FLOAT_BND));
154 return notify(home,me,d);
155 }
156
157
160 if (n < dom.min()) return fail(home);
161 if ((n >= dom.max()) || assigned()) return ME_FLOAT_NONE;
162 FloatDelta d(n,dom.max());
164 dom = intersect(dom,FloatVal(dom.min(),n));
165 if (assigned()) me = ME_FLOAT_VAL;
167 (me == ME_FLOAT_BND));
168 return notify(home,me,d);
169 }
171 FloatVarImp::lq(Space& home, const FloatVal& n) {
172 if (n.max() < dom.min()) return fail(home);
173 if ((n.max() >= dom.max()) || assigned()) return ME_FLOAT_NONE;
174 FloatDelta d(n.max(),dom.max());
176 dom = intersect(dom,FloatVal(dom.min(),n.max()));
177 if (assigned()) me = ME_FLOAT_VAL;
179 (me == ME_FLOAT_BND));
180 return notify(home,me,d);
181 }
182
183
186 if (!dom.in(n))
187 return fail(home);
188 if (assigned())
189 return ME_FLOAT_NONE;
190 FloatDelta d;
191 dom = n;
192 return notify(home,ME_FLOAT_VAL,d);
193 }
195 FloatVarImp::eq(Space& home, const FloatVal& n) {
196 if (!overlap(dom,n))
197 return fail(home);
198 if (assigned() || subset(dom,n))
199 return ME_FLOAT_NONE;
200 FloatDelta d;
202 dom = intersect(dom,n);
203 if (assigned()) me = ME_FLOAT_VAL;
205 (me == ME_FLOAT_BND));
206 return notify(home,me,d);
207 }
208
209
210 /*
211 * Copying a variable
212 *
213 */
214
217 return copied() ? static_cast<FloatVarImp*>(forward())
218 : perform_copy(home);
219 }
220
223 FloatVarImp::perform_copy(Space& home) {
224 return new (home) FloatVarImp(home, *this);
225 }
226
231
232}}
233
234// STATISTICS: float-var
Generic domain change information to be supplied to advisors.
Definition core.hpp:204
Float value type.
Definition float.hh:334
friend FloatVal max(const FloatVal &x, const FloatVal &y)
Definition val.hpp:386
friend FloatVal min(const FloatVal &x, const FloatVal &y)
Definition val.hpp:398
Float delta information for advisors.
Definition var-imp.hpp:48
FloatVarImpBase(Gecode::Space &home, FloatVarImpBase &x)
Constructor for cloning x.
Definition var-imp.hpp:435
Gecode::ModEvent notify(Gecode::Space &home, Gecode::ModEvent me, Gecode::Delta &d)
Notify that variable implementation has been modified with modification event me and delta informatio...
Definition var-imp.hpp:457
Float variable implementation.
Definition var-imp.hpp:76
bool zero_in(void) const
Test whether 0 is contained in domain.
Definition float.hpp:100
FloatNum min(void) const
Return minimum of domain.
Definition float.hpp:67
FloatVarImp(Space &home, FloatVarImp &x)
Constructor for cloning x.
Definition float.hpp:53
ModEvent eq(Space &home, FloatNum n)
Restrict domain values to be equal to n.
Definition float.hpp:185
FloatNum max(void) const
Return maximum of domain.
Definition float.hpp:71
FloatVal val(void) const
Return value of domain (only if assigned)
Definition float.hpp:75
FloatVal dom
Domain information.
Definition var-imp.hpp:79
bool in(FloatNum n) const
Test whether n is contained in domain.
Definition float.hpp:104
FloatVarImp * copy(Space &home)
Return copy of this variable.
Definition float.hpp:216
FloatNum size(void) const
Return width of domain (distance between maximum and minimum)
Definition float.hpp:89
FloatNum med(void) const
Return median of domain (closest representation)
Definition float.hpp:79
ModEvent lq(Space &home, FloatNum n)
Restrict domain values to be less or equal than n.
Definition float.hpp:159
ModEvent gq(Space &home, FloatNum n)
Restrict domain values to be greater or equal than n.
Definition float.hpp:133
bool assigned(void) const
Test whether variable is assigned.
Definition float.hpp:84
FloatVal domain(void) const
Return domain.
Definition float.hpp:63
Computation spaces.
Definition core.hpp:1744
static ModEvent me(const ModEventDelta &med)
Definition core.hpp:4277
static ModEventDelta med(ModEvent me)
Definition core.hpp:4283
int ModEventDelta
Modification event deltas.
Definition core.hpp:89
double FloatNum
Floating point number base type.
Definition float.hh:106
Floating point numbers.
bool subset(const FloatVal &x, const FloatVal &y)
Definition val.hpp:490
const Gecode::ModEvent ME_FLOAT_VAL
Domain operation has resulted in a value (assigned variable)
Definition var-type.hpp:264
bool overlap(const FloatVal &x, const FloatVal &y)
Definition val.hpp:498
FloatVal intersect(const FloatVal &x, const FloatVal &y)
Definition val.hpp:503
const Gecode::ModEvent ME_FLOAT_BND
Domain operation has changed the minimum or maximum of the domain.
Definition var-type.hpp:273
const Gecode::ModEvent ME_FLOAT_NONE
Domain operation has not changed domain.
Definition var-type.hpp:262
Gecode toplevel namespace
Post propagator for SetVar x
Definition set.hh:773
int ModEvent
Type for modification events.
Definition core.hpp:62
#define forceinline
Definition config.hpp:194
#define GECODE_ASSUME(p)
Assert certain property.
Definition macros.hpp:114