Generated on Wed Jan 1 2020 10:37:59 for Gecode by doxygen 1.8.16
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 
41 namespace Gecode { namespace Float {
42 
43  /*
44  * Creation of new variable implementations
45  *
46  */
47 
50  : FloatVarImpBase(home), dom(d) {}
51 
54  : FloatVarImpBase(home, x), dom(x.dom) {}
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
84  FloatVarImp::assigned(void) const {
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
100  FloatVarImp::zero_in(void) const {
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 
229  return FloatVarImpBase::med(me);
230  }
231 
232 }}
233 
234 // STATISTICS: float-var
Post propagator for SetVar x
Definition: set.hh:767
friend FloatVal max(const FloatVal &x, const FloatVal &y)
Definition: val.hpp:386
bool zero_in(void) const
Test whether zero is included.
Definition: val.hpp:100
FloatVarImp(Space &home, FloatVarImp &x)
Constructor for cloning x.
Definition: float.hpp:53
bool zero_in(void) const
Test whether 0 is contained in domain.
Definition: float.hpp:100
friend FloatVal min(const FloatVal &x, const FloatVal &y)
Definition: val.hpp:398
ModEvent fail(Space &home)
Run advisors to be run on failure and returns ME_GEN_FAILED.
Definition: core.hpp:4570
const Gecode::ModEvent ME_FLOAT_VAL
Domain operation has resulted in a value (assigned variable)
Definition: var-type.hpp:264
ModEvent lq(Space &home, FloatNum n)
Restrict domain values to be less or equal than n.
Definition: float.hpp:159
bool assigned(void) const
Test whether variable is assigned.
Definition: float.hpp:84
Computation spaces.
Definition: core.hpp:1742
const Gecode::ModEvent ME_FLOAT_NONE
Domain operation has not changed domain.
Definition: var-type.hpp:262
FloatNum max(void) const
Return maximum of domain.
Definition: float.hpp:71
ModEvent gq(Space &home, FloatNum n)
Restrict domain values to be greater or equal than n.
Definition: float.hpp:133
const Gecode::ModEvent ME_FLOAT_BND
Domain operation has changed the minimum or maximum of the domain.
Definition: var-type.hpp:273
Gecode toplevel namespace
Float variable implementation.
Definition: var-imp.hpp:76
Generic domain change information to be supplied to advisors.
Definition: core.hpp:204
VarImp * forward(void) const
Use forward pointer if variable already copied.
Definition: core.hpp:4228
bool in(FloatNum n) const
Test whether n is included.
Definition: val.hpp:96
ModEvent eq(Space &home, FloatNum n)
Restrict domain values to be equal to n.
Definition: float.hpp:185
void dom(Home home, FloatVar x, FloatVal n)
Propagates .
Definition: dom.cpp:40
double FloatNum
Floating point number base type.
Definition: float.hh:106
bool subset(const FloatVal &x, const FloatVal &y)
Definition: val.hpp:490
FloatNum min(void) const
Return minimum of domain.
Definition: float.hpp:67
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
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
int ModEvent
Type for modification events.
Definition: core.hpp:62
FloatNum size(void) const
Return size of float value (distance between maximum and minimum)
Definition: val.hpp:78
bool tight(void) const
Test whether float is tight.
Definition: val.hpp:87
Base-class for Float-variable implementations.
Definition: var-imp.hpp:185
FloatNum med(void) const
Return median of float value.
Definition: val.hpp:82
Float value type.
Definition: float.hh:334
FloatVal dom
Domain information.
Definition: var-imp.hpp:79
bool overlap(const FloatVal &x, const FloatVal &y)
Definition: val.hpp:498
Gecode::IntSet d(v, 7)
bool in(FloatNum n) const
Test whether n is contained in domain.
Definition: float.hpp:104
static ModEvent me(const ModEventDelta &med)
Project modification event for this variable type from med.
Definition: core.hpp:4270
Float delta information for advisors.
Definition: var-imp.hpp:48
static ModEventDelta med(ModEvent me)
Translate modification event me into modification event delta.
Definition: core.hpp:4276
#define forceinline
Definition: config.hpp:185
FloatVal domain(void) const
Return domain.
Definition: float.hpp:63
bool copied(void) const
Is variable already copied.
Definition: core.hpp:4222
int n
Number of negative literals for node type.
Definition: bool-expr.cpp:234
int ModEventDelta
Modification event deltas.
Definition: core.hpp:89
FloatVal val(void) const
Return value of domain (only if assigned)
Definition: float.hpp:75
FloatVarImp * copy(Space &home)
Return copy of this variable.
Definition: float.hpp:216
FloatVal intersect(const FloatVal &x, const FloatVal &y)
Definition: val.hpp:503
#define GECODE_ASSUME(p)
Assert certain property.
Definition: macros.hpp:114