Generated on Sat Feb 7 2015 02:01:17 for Gecode by doxygen 1.8.9.1
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  * Last modified:
17  * $Date: 2013-02-04 17:54:05 +0100 (Mon, 04 Feb 2013) $ by $Author: schulte $
18  * $Revision: 13260 $
19  *
20  * This file is part of Gecode, the generic constraint
21  * development environment:
22  * http://www.gecode.org
23  *
24  * Permission is hereby granted, free of charge, to any person obtaining
25  * a copy of this software and associated documentation files (the
26  * "Software"), to deal in the Software without restriction, including
27  * without limitation the rights to use, copy, modify, merge, publish,
28  * distribute, sublicense, and/or sell copies of the Software, and to
29  * permit persons to whom the Software is furnished to do so, subject to
30  * the following conditions:
31  *
32  * The above copyright notice and this permission notice shall be
33  * included in all copies or substantial portions of the Software.
34  *
35  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
36  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
37  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
38  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
39  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
40  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
41  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
42  *
43  */
44 
45 namespace Gecode { namespace Float {
46 
47  /*
48  * Creation of new variable implementations
49  *
50  */
51 
54  : FloatVarImpBase(home), dom(d) {}
55 
58  : FloatVarImpBase(home, share, x), dom(x.dom) {}
59 
60 
61  /*
62  * Operations on float variable implementations
63  *
64  */
65 
67  FloatVarImp::domain(void) const {
68  return dom;
69  }
71  FloatVarImp::min(void) const {
72  return dom.min();
73  }
75  FloatVarImp::max(void) const {
76  return dom.max();
77  }
79  FloatVarImp::val(void) const {
80  return dom;
81  }
83  FloatVarImp::med(void) const {
84  return dom.med();
85  }
86 
87  forceinline bool
88  FloatVarImp::assigned(void) const {
89  return dom.tight();
90  }
91 
93  FloatVarImp::size(void) const {
94  return dom.size();
95  }
96 
97 
98  /*
99  * Tests
100  *
101  */
102 
103  forceinline bool
104  FloatVarImp::zero_in(void) const {
105  return dom.zero_in();
106  }
107  forceinline bool
109  return dom.in(n);
110  }
111  forceinline bool
112  FloatVarImp::in(const FloatVal& n) const {
113  return subset(n,dom);
114  }
115 
116 
117  /*
118  * Support for delta information
119  *
120  */
123  return static_cast<const FloatDelta&>(d).min();
124  }
127  return static_cast<const FloatDelta&>(d).max();
128  }
129 
130 
131  /*
132  * Tell operations (to be inlined: performing bounds checks first)
133  *
134  */
135 
138  if (n > dom.max()) return ME_FLOAT_FAILED;
139  if ((n <= dom.min()) || assigned()) return ME_FLOAT_NONE;
140  FloatDelta d(dom.min(),n);
142  dom = intersect(dom,FloatVal(n,dom.max()));
143  if (assigned()) me = ME_FLOAT_VAL;
144  GECODE_ASSUME((me == ME_FLOAT_VAL) |
145  (me == ME_FLOAT_BND));
146  return notify(home,me,d);
147  }
149  FloatVarImp::gq(Space& home, const FloatVal& n) {
150  if (n.min() > dom.max()) return ME_FLOAT_FAILED;
151  if ((n.min() <= dom.min()) || assigned()) return ME_FLOAT_NONE;
152  FloatDelta d(dom.min(),n.min());
154  dom = intersect(dom,FloatVal(n.min(),dom.max()));
155  if (assigned()) me = ME_FLOAT_VAL;
156  GECODE_ASSUME((me == ME_FLOAT_VAL) |
157  (me == ME_FLOAT_BND));
158  return notify(home,me,d);
159  }
160 
161 
164  if (n < dom.min()) return ME_FLOAT_FAILED;
165  if ((n >= dom.max()) || assigned()) return ME_FLOAT_NONE;
166  FloatDelta d(n,dom.max());
168  dom = intersect(dom,FloatVal(dom.min(),n));
169  if (assigned()) me = ME_FLOAT_VAL;
170  GECODE_ASSUME((me == ME_FLOAT_VAL) |
171  (me == ME_FLOAT_BND));
172  return notify(home,me,d);
173  }
175  FloatVarImp::lq(Space& home, const FloatVal& n) {
176  if (n.max() < dom.min()) return ME_FLOAT_FAILED;
177  if ((n.max() >= dom.max()) || assigned()) return ME_FLOAT_NONE;
178  FloatDelta d(n.max(),dom.max());
180  dom = intersect(dom,FloatVal(dom.min(),n.max()));
181  if (assigned()) me = ME_FLOAT_VAL;
182  GECODE_ASSUME((me == ME_FLOAT_VAL) |
183  (me == ME_FLOAT_BND));
184  return notify(home,me,d);
185  }
186 
187 
190  if (!dom.in(n))
191  return ME_FLOAT_FAILED;
192  if (assigned())
193  return ME_FLOAT_NONE;
194  FloatDelta d;
195  dom = n;
196  return notify(home,ME_FLOAT_VAL,d);
197  }
199  FloatVarImp::eq(Space& home, const FloatVal& n) {
200  if (!overlap(dom,n))
201  return ME_FLOAT_FAILED;
202  if (assigned() || subset(dom,n))
203  return ME_FLOAT_NONE;
204  FloatDelta d;
206  dom = intersect(dom,n);
207  if (assigned()) me = ME_FLOAT_VAL;
208  GECODE_ASSUME((me == ME_FLOAT_VAL) |
209  (me == ME_FLOAT_BND));
210  return notify(home,me,d);
211  }
212 
213 
214  /*
215  * Copying a variable
216  *
217  */
218 
220  FloatVarImp::copy(Space& home, bool share) {
221  return copied() ? static_cast<FloatVarImp*>(forward())
222  : perform_copy(home,share);
223  }
224 
227  FloatVarImp::perform_copy(Space& home, bool share) {
228  return new (home) FloatVarImp(home, share, *this);
229  }
230 
231  /*
232  * Dependencies
233  *
234  */
235  forceinline void
236  FloatVarImp::subscribe(Space& home, Propagator& p, PropCond pc, bool schedule) {
237  FloatVarImpBase::subscribe(home,p,pc,assigned(),schedule);
238  }
239  forceinline void
241  FloatVarImpBase::cancel(home,p,pc,assigned());
242  }
243 
244  forceinline void
247  }
248  forceinline void
251  }
252 
255  return FloatVarImpBase::med(me);
256  }
257 
258 }}
259 
260 // STATISTICS: float-var
FloatNum min(void) const
Return minimum of domain.
Definition: float.hpp:71
bool assigned(void) const
Test whether variable is assigned.
Definition: float.hpp:88
bool subset(const FloatVal &x, const FloatVal &y)
Definition: val.hpp:494
#define GECODE_ASSUME(p)
Assert certain property.
Definition: macros.hpp:99
void cancel(Space &home, Propagator &p, PropCond pc)
Cancel subscription of propagator p with propagation condition pc.
Definition: float.hpp:240
FloatVal dom
Domain information.
Definition: var-imp.hpp:83
bool zero_in(void) const
Test whether 0 is contained in domain.
Definition: float.hpp:104
bool overlap(const FloatVal &x, const FloatVal &y)
Definition: val.hpp:502
void dom(Home home, FloatVar x, FloatVal n)
Propagates .
Definition: dom.cpp:44
int ModEvent
Type for modification events.
Definition: core.hpp:146
Base-class for propagators.
Definition: core.hpp:755
const Gecode::ModEvent ME_FLOAT_FAILED
Domain operation has resulted in failure.
Definition: var-type.hpp:260
Base-class for advisors.
Definition: core.hpp:926
static ModEventDelta med(ModEvent me)
Translate modification event me into modification event delta.
const Gecode::ModEvent ME_FLOAT_VAL
Domain operation has resulted in a value (assigned variable)
Definition: var-type.hpp:264
Computation spaces.
Definition: core.hpp:1362
void cancel(Space &home)
Cancel all subscriptions when variable implementation is assigned.
Gecode::IntSet d(v, 7)
FloatVarImp(Space &home, bool share, FloatVarImp &x)
Constructor for cloning x.
Definition: float.hpp:57
bool tight(void) const
Test whether float is tight.
Definition: val.hpp:91
FloatNum size(void) const
Return width of domain (distance between maximum and minimum)
Definition: float.hpp:93
int p
Number of positive literals for node type.
Definition: bool-expr.cpp:236
bool copied(void) const
Is variable already copied.
FloatNum med(void) const
Return median of float value.
Definition: val.hpp:86
int n
Number of negative literals for node type.
Definition: bool-expr.cpp:238
FloatNum med(void) const
Return median of domain (closest representation)
Definition: float.hpp:83
static ModEvent me(const ModEventDelta &med)
Project modification event for this variable type from med.
FloatVal intersect(const FloatVal &x, const FloatVal &y)
Definition: val.hpp:507
bool in(FloatNum n) const
Test whether n is contained in domain.
Definition: float.hpp:108
Float variable implementation.
Definition: var-imp.hpp:80
int PropCond
Type for propagation conditions.
Definition: core.hpp:156
Float delta information for advisors.
Definition: var-imp.hpp:52
FloatVarImp * copy(Space &home, bool share)
Return copy of this variable.
Definition: float.hpp:220
FloatVal val(void) const
Return value of domain (only if assigned)
Definition: float.hpp:79
Float value type.
Definition: float.hh:321
ModEvent eq(Space &home, FloatNum n)
Restrict domain values to be equal to n.
Definition: float.hpp:189
Node * x
Pointer to corresponding Boolean expression node.
Definition: bool-expr.cpp:253
Generic domain change information to be supplied to advisors.
Definition: core.hpp:275
FloatVal domain(void) const
Return domain.
Definition: float.hpp:67
bool in(FloatNum n) const
Test whether n is included.
Definition: val.hpp:100
#define forceinline
Definition: config.hpp:132
bool zero_in(void) const
Test whether zero is included.
Definition: val.hpp:104
const Gecode::ModEvent ME_FLOAT_NONE
Domain operation has not changed domain.
Definition: var-type.hpp:262
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:377
FloatNum size(void) const
Return size of float value (distance between maximum and minimum)
Definition: val.hpp:82
ModEvent gq(Space &home, FloatNum n)
Restrict domain values to be greater or equal than n.
Definition: float.hpp:137
Gecode toplevel namespace
FloatNum max(void) const
Return maximum of domain.
Definition: float.hpp:75
void subscribe(Space &home, Propagator &p, PropCond pc, bool schedule=true)
Subscribe propagator p with propagation condition pc to variable.
Definition: float.hpp:236
const Gecode::ModEvent ME_FLOAT_BND
Domain operation has changed the minimum or maximum of the domain.
Definition: var-type.hpp:273
Base-class for Float-variable implementations.
Definition: var-imp.hpp:152
void subscribe(Gecode::Space &home, Gecode::Propagator &p, Gecode::PropCond pc, bool assigned, bool schedule)
Subscribe propagator p with propagation condition pc.
Definition: var-imp.hpp:368
friend FloatVal max(const FloatVal &x, const FloatVal &y)
Definition: val.hpp:390
int ModEventDelta
Modification event deltas.
Definition: core.hpp:173
friend FloatVal min(const FloatVal &x, const FloatVal &y)
Definition: val.hpp:402
double FloatNum
Floating point number base type.
Definition: float.hh:108
struct Gecode::@518::NNF::@57::@59 a
For atomic nodes.
VarImp * forward(void) const
Use forward pointer if variable already copied.
ModEvent lq(Space &home, FloatNum n)
Restrict domain values to be less or equal than n.
Definition: float.hpp:163