Generated on for Gecode by doxygen 1.17.0
val.hpp
Go to the documentation of this file.
1/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2/*
3 * Main authors:
4 * Vincent Barichard <Vincent.Barichard@univ-angers.fr>
5 *
6 * Contributing authors:
7 * Christian Schulte <schulte@gecode.dev>
8 *
9 * Copyright:
10 * Christian Schulte, 2012
11 * Vincent Barichard, 2012
12 *
13 * This file is part of Gecode, the generic constraint
14 * development environment:
15 * http://www.gecode.dev
16 *
17 * Permission is hereby granted, free of charge, to any person obtaining
18 * a copy of this software and associated documentation files (the
19 * "Software"), to deal in the Software without restriction, including
20 * without limitation the rights to use, copy, modify, merge, publish,
21 * distribute, sublicense, and/or sell copies of the Software, and to
22 * permit persons to whom the Software is furnished to do so, subject to
23 * the following conditions:
24 *
25 * The above copyright notice and this permission notice shall be
26 * included in all copies or substantial portions of the Software.
27 *
28 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
29 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
30 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
31 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
32 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
33 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
34 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35 *
36 */
37
38namespace Gecode {
39
40 /*
41 * Floating point value: member functions
42 *
43 */
47 FloatVal::FloatVal(const FloatNum& n) : x(n) {}
49 FloatVal::FloatVal(const FloatNum& l, const FloatNum& u) : x(l,u) {}
53 FloatVal::FloatVal(const FloatVal& v) : x(v.x) {}
54
57 x = n; return *this;
58 }
61 x = v.x; return *this;
62 }
63
64 forceinline void
65 FloatVal::assign(FloatNum const &l, FloatNum const &u) {
66 x.assign(l,u);
67 }
68
70 FloatVal::min(void) const {
71 return x.lower();
72 }
74 FloatVal::max(void) const {
75 return x.upper();
76 }
78 FloatVal::size(void) const {
79 return boost::numeric::width(x);
80 }
82 FloatVal::med(void) const {
84 return r.median(x.lower(),x.upper());
85 }
86
87 forceinline bool
88 FloatVal::tight(void) const {
89 return (boost::numeric::singleton(x) ||
90 (nextafter(x.lower(),x.upper()) == x.upper()));
91 }
92 forceinline bool
93 FloatVal::singleton(void) const {
94 return boost::numeric::singleton(x);
95 }
96 forceinline bool
98 return boost::numeric::in(n,x);
99 }
100 forceinline bool
101 FloatVal::zero_in(void) const {
102 return boost::numeric::zero_in(x);
103 }
104
107 FloatVal h(x,y); return h;
108 }
111 FloatVal p(boost::numeric::interval_lib::pi_half<FloatValImpType>());
112 return p;
113 }
116 FloatVal p(boost::numeric::interval_lib::pi<FloatValImpType>());
117 return p;
118 }
121 FloatVal p(boost::numeric::interval_lib::pi_twice<FloatValImpType>());
122 return p;
123 }
124
127 x += n; return *this;
128 }
131 x -= n; return *this;
132 }
135 x *= n; return *this;
136 }
139 x /= n; return *this;
140 }
141
144 x += v.x; return *this;
145 }
148 x -= v.x; return *this;
149 }
152 x *= v.x; return *this;
153 }
156 x /= v.x; return *this;
157 }
158
159 /*
160 * Operators and functions on float values
161 *
162 */
163
166 return FloatVal(+x.x);
167 }
170 FloatNum mmi = (x.min() == 0.0) ? 0.0 : -x.min();
171 FloatNum mma = (x.max() == 0.0) ? 0.0 :-x.max();
172 return FloatVal(mma,mmi);
173 }
175 operator +(const FloatVal& x, const FloatVal& y) {
176 return FloatVal(x.x+y.x);
177 }
179 operator +(const FloatVal& x, const FloatNum& y) {
180 return FloatVal(x.x+y);
181 }
183 operator +(const FloatNum& x, const FloatVal& y) {
184 return FloatVal(x+y.x);
185 }
186
188 operator -(const FloatVal& x, const FloatVal& y) {
189 return FloatVal(x.x-y.x);
190 }
192 operator -(const FloatVal& x, const FloatNum& y) {
193 return FloatVal(x.x-y);
194 }
196 operator -(const FloatNum& x, const FloatVal& y) {
197 return FloatVal(x-y.x);
198 }
199
201 operator *(const FloatVal& x, const FloatVal& y) {
202 return FloatVal(x.x*y.x);
203 }
205 operator *(const FloatVal& x, const FloatNum& y) {
206 return FloatVal(x.x*y);
207 }
209 operator *(const FloatNum& x, const FloatVal& y) {
210 return FloatVal(x*y.x);
211 }
212
214 operator /(const FloatVal& x, const FloatVal& y) {
215 return FloatVal(x.x/y.x);
216 }
218 operator /(const FloatVal& x, const FloatNum& y) {
219 return FloatVal(x.x/y);
220 }
222 operator /(const FloatNum& x, const FloatVal& y) {
223 return FloatVal(x/y.x);
224 }
225
226 inline bool
227 operator <(const FloatVal& x, const FloatVal& y) {
228 try {
229 return x.x < y.x;
230 } catch (boost::numeric::interval_lib::comparison_error&) {
231 return false;
232 }
233 }
234 inline bool
235 operator <(const FloatVal& x, const FloatNum& y) {
236 try {
237 return x.x < y;
238 } catch (boost::numeric::interval_lib::comparison_error&) {
239 return false;
240 }
241 }
242
243 inline bool
244 operator <=(const FloatVal& x, const FloatVal& y) {
245 try {
246 return x.x <= y.x;
247 } catch (boost::numeric::interval_lib::comparison_error&) {
248 return false;
249 }
250 }
251 inline bool
252 operator <=(const FloatVal& x, const FloatNum& y) {
253 try {
254 return x.x <= y;
255 } catch (boost::numeric::interval_lib::comparison_error&) {
256 return false;
257 }
258 }
259
260 inline bool
261 operator >(const FloatVal& x, const FloatVal& y) {
262 try {
263 return x.x > y.x;
264 } catch (boost::numeric::interval_lib::comparison_error&) {
265 return false;
266 }
267 }
268 inline bool
269 operator >(const FloatVal& x, const FloatNum& y) {
270 try {
271 return x.x > y;
272 } catch (boost::numeric::interval_lib::comparison_error&) {
273 return false;
274 }
275 }
276
277 inline bool
278 operator >=(const FloatVal& x, const FloatVal& y) {
279 try {
280 return x.x >= y.x;
281 } catch (boost::numeric::interval_lib::comparison_error&) {
282 return false;
283 }
284 }
285 inline bool
286 operator >=(const FloatVal& x, const FloatNum& y) {
287 try {
288 return x.x >= y;
289 } catch (boost::numeric::interval_lib::comparison_error&) {
290 return false;
291 }
292 }
293
294 inline bool
295 operator ==(const FloatVal& x, const FloatVal& y) {
296 try {
297 return x.x == y.x;
298 } catch (boost::numeric::interval_lib::comparison_error&) {
299 return false;
300 }
301 }
302 inline bool
303 operator ==(const FloatVal& x, const FloatNum& y) {
304 if (!boost::numeric::interval_lib::checking_strict<FloatNum>
305 ::is_empty(x.x.lower(), x.x.upper())) {
306 if ((x.x.lower() == y) && (x.x.upper() == y))
307 return true;
308 }
309 if (((x.x.lower() == y) &&
310 (nextafter(x.x.lower(),x.x.upper()) == x.x.upper())) ||
311 ((x.x.upper() == y) &&
312 (nextafter(x.x.upper(),x.x.lower()) == x.x.lower())))
313 return true;
314 return false;
315 }
316
317 inline bool
318 operator !=(const FloatVal& x, const FloatVal& y) {
319 try {
320 return x.x != y.x;
321 } catch (boost::numeric::interval_lib::comparison_error&) {
322 return false;
323 }
324 }
325 inline bool
326 operator !=(const FloatVal& x, const FloatNum& y) {
327 try {
328 return x.x != y;
329 } catch (boost::numeric::interval_lib::comparison_error&) {
330 return false;
331 }
332 }
333
335 operator <(const FloatNum& x, const FloatVal& y) {
336 return y > x;
337 }
339 operator <=(const FloatNum& x, const FloatVal& y) {
340 return y >= x;
341 }
342 forceinline bool
343 operator >(const FloatNum& x, const FloatVal& y) {
344 return y < x;
345 }
346 forceinline bool
347 operator >=(const FloatNum& x, const FloatVal& y) {
348 return y <= x;
349 }
350 forceinline bool
351 operator ==(const FloatNum& x, const FloatVal& y) {
352 return y == x;
353 }
354 forceinline bool
355 operator !=(const FloatNum& x, const FloatVal& y) {
356 return y != x;
357 }
358
359 template<class Char, class Traits>
360 std::basic_ostream<Char,Traits>&
361 operator <<(std::basic_ostream<Char,Traits>& os, const FloatVal& x) {
362 return os << '[' << x.min() << ".." << x.max() << ']';
363 }
364
365 forceinline FloatVal
366 abs(const FloatVal& x) {
367 return FloatVal(abs(x.x));
368 }
370 sqrt(const FloatVal& x) {
371 return FloatVal(sqrt(x.x));
372 }
374 sqr(const FloatVal& x) {
375 return FloatVal(square(x.x));
376 }
378 pow(const FloatVal& x, int n) {
379 return FloatVal(pow(x.x,n));
380 }
382 nroot(const FloatVal& x, int n) {
383 return FloatVal(nth_root(x.x,n));
384 }
385
387 max(const FloatVal& x, const FloatVal& y) {
388 return FloatVal(max(x.x,y.x));
389 }
391 max(const FloatVal& x, const FloatNum& y) {
392 return FloatVal(max(x.x,y));
393 }
395 max(const FloatNum& x, const FloatVal& y) {
396 return FloatVal(max(x,y.x));
397 }
399 min(const FloatVal& x, const FloatVal& y) {
400 return FloatVal(min(x.x,y.x));
401 }
403 min(const FloatVal& x, const FloatNum& y) {
404 return FloatVal(min(x.x,y));
405 }
407 min(const FloatNum& x, const FloatVal& y) {
408 return FloatVal(min(x,y.x));
409 }
410
411#ifdef GECODE_HAS_MPFR
412
414 exp(const FloatVal& x) {
415 return FloatVal(exp(x.x));
416 }
418 log(const FloatVal& x) {
419 return FloatVal(log(x.x));
420 }
421
423 fmod(const FloatVal& x, const FloatVal& y) {
424 return FloatVal(fmod(x.x,y.x));
425 }
427 fmod(const FloatVal& x, const FloatNum& y) {
428 return FloatVal(fmod(x.x,y));
429 }
431 fmod(const FloatNum& x, const FloatVal& y) {
432 return FloatVal(fmod(x,y.x));
433 }
434
436 sin(const FloatVal& x) {
437 return FloatVal(sin(x.x));
438 }
440 cos(const FloatVal& x) {
441 return FloatVal(cos(x.x));
442 }
444 tan(const FloatVal& x) {
445 return FloatVal(tan(x.x));
446 }
448 asin(const FloatVal& x) {
449 return FloatVal(asin(x.x));
450 }
452 acos(const FloatVal& x) {
453 return FloatVal(acos(x.x));
454 }
456 atan(const FloatVal& x) {
457 return FloatVal(atan(x.x));
458 }
459
461 sinh(const FloatVal& x) {
462 return FloatVal(sinh(x.x));
463 }
465 cosh(const FloatVal& x) {
466 return FloatVal(cosh(x.x));
467 }
469 tanh(const FloatVal& x) {
470 return FloatVal(tanh(x.x));
471 }
473 asinh(const FloatVal& x) {
474 return FloatVal(asinh(x.x));
475 }
477 acosh(const FloatVal& x) {
478 return FloatVal(acosh(x.x));
479 }
481 atanh(const FloatVal& x) {
482 return FloatVal(atanh(x.x));
483 }
484
485#endif
486}
487
488namespace Gecode { namespace Float {
489
490 forceinline bool
491 subset(const FloatVal& x, const FloatVal& y) {
492 return subset(x.x,y.x);
493 }
494 forceinline bool
495 proper_subset(const FloatVal& x, const FloatVal& y) {
496 return proper_subset(x.x,y.x);
497 }
498 forceinline bool
499 overlap(const FloatVal& x, const FloatVal& y) {
500 return overlap(x.x,y.x);
501 }
502
504 intersect(const FloatVal& x, const FloatVal& y) {
505 return FloatVal(intersect(x.x,y.x));
506 }
508 hull(const FloatVal& x, const FloatVal& y) {
509 return FloatVal(hull(x.x,y.x));
510 }
512 hull(const FloatVal& x, const FloatNum& y) {
513 return FloatVal(hull(x.x,y));
514 }
516 hull(const FloatNum& x, const FloatVal& y) {
517 return FloatVal(hull(x,y.x));
518 }
520 hull(const FloatNum& x, const FloatNum& y) {
521 return FloatVal(x,y);
522 }
523
524}}
525
526// STATISTICS: float-var
527
Float value type.
Definition float.hh:329
bool singleton(void) const
Test whether float is a singleton.
Definition val.hpp:93
friend FloatVal Float::hull(const FloatVal &x, const FloatVal &y)
FloatVal & operator/=(const FloatNum &n)
Divide by n.
Definition val.hpp:138
static FloatVal pi(void)
Return lower bound of .
Definition val.hpp:115
boost::numeric::interval< FloatNum, boost::numeric::interval_lib::policies< R, P > > FloatValImpType
Implementation type for float value.
Definition float.hh:418
static FloatVal pi_twice(void)
Return .
Definition val.hpp:120
FloatValImpType x
Implementation of float value.
Definition float.hh:420
bool zero_in(void) const
Test whether zero is included.
Definition val.hpp:101
FloatVal & operator-=(const FloatNum &n)
Subtract by n.
Definition val.hpp:130
bool in(FloatNum n) const
Test whether n is included.
Definition val.hpp:97
FloatVal & operator*=(const FloatNum &n)
Multiply by n.
Definition val.hpp:134
FloatNum max(void) const
Return upper bound.
Definition val.hpp:74
void assign(FloatNum const &l, FloatNum const &u)
Assign lower bound l and upper bound u.
Definition val.hpp:65
FloatVal & operator+=(const FloatNum &n)
Increment by n.
Definition val.hpp:126
FloatNum med(void) const
Return median of float value.
Definition val.hpp:82
FloatVal & operator=(const FloatNum &n)
Assignment operator.
Definition val.hpp:56
friend FloatVal max(const FloatVal &x, const FloatVal &y)
Definition val.hpp:387
friend FloatVal min(const FloatVal &x, const FloatVal &y)
Definition val.hpp:399
bool tight(void) const
Test whether float is tight.
Definition val.hpp:88
FloatNum size(void) const
Return size of float value (distance between maximum and minimum).
Definition val.hpp:78
static FloatVal pi_half(void)
Return .
Definition val.hpp:110
FloatVal(const FloatValImpType &i)
Initialize from implementation i.
Definition val.hpp:51
FloatVal(void)
Default constructor.
Definition val.hpp:45
FloatNum min(void) const
Return lower bound.
Definition val.hpp:70
Floating point rounding policy that restores the caller's mode.
Definition float.hh:269
double FloatNum
Floating point number base type.
Definition float.hh:106
bool subset(const FloatVal &x, const FloatVal &y)
Definition val.hpp:491
bool proper_subset(const FloatVal &x, const FloatVal &y)
Definition val.hpp:495
FloatVal hull(const FloatVal &x, const FloatVal &y)
Definition val.hpp:508
bool overlap(const FloatVal &x, const FloatVal &y)
Definition val.hpp:499
FloatVal intersect(const FloatVal &x, const FloatVal &y)
Definition val.hpp:504
Gecode toplevel namespace
FloatVal operator/(const FloatVal &x, const FloatVal &y)
Definition val.hpp:214
FloatVal operator-(const FloatVal &x)
Definition val.hpp:169
FloatVal asinh(const FloatVal &x)
Definition val.hpp:473
bool operator<=(const FloatVal &x, const FloatVal &y)
Definition val.hpp:244
void sin(Home home, FloatVar x0, FloatVar x1)
Post propagator for .
FloatVal operator+(const FloatVal &x)
Definition val.hpp:165
void sqr(Home home, FloatVar x0, FloatVar x1)
Post propagator for .
Archive & operator<<(Archive &e, FloatNumBranch nl)
Definition val-sel.hpp:39
void cos(Home home, FloatVar x0, FloatVar x1)
Post propagator for .
void min(Home home, FloatVar x0, FloatVar x1, FloatVar x2)
Post propagator for .
void abs(Home home, FloatVar x0, FloatVar x1)
Post propagator for .
bool operator<(const FloatVal &x, const FloatVal &y)
Definition val.hpp:227
void sqrt(Home home, FloatVar x0, FloatVar x1)
Post propagator for .
void acos(Home home, FloatVar x0, FloatVar x1)
Post propagator for .
bool operator>(const FloatVal &x, const FloatVal &y)
Definition val.hpp:261
void log(Home home, FloatVar x0, FloatVar x1)
Post propagator for .
bool operator>=(const FloatVal &x, const FloatVal &y)
Definition val.hpp:278
void exp(Home home, FloatVar x0, FloatVar x1)
Post propagator for .
void atan(Home home, FloatVar x0, FloatVar x1)
Post propagator for .
void max(Home home, FloatVar x0, FloatVar x1, FloatVar x2)
Post propagator for .
FloatVal fmod(const FloatVal &x, const FloatVal &y)
Definition val.hpp:423
FloatVal sinh(const FloatVal &x)
Definition val.hpp:461
FloatVal acosh(const FloatVal &x)
Definition val.hpp:477
FloatVal tanh(const FloatVal &x)
Definition val.hpp:469
void asin(Home home, FloatVar x0, FloatVar x1)
Post propagator for .
void pow(Home home, FloatVar x0, int n, FloatVar x1)
Post propagator for for .
FloatVal atanh(const FloatVal &x)
Definition val.hpp:481
FloatVal operator*(const FloatVal &x, const FloatVal &y)
Definition val.hpp:201
FloatVal cosh(const FloatVal &x)
Definition val.hpp:465
void nroot(Home home, FloatVar x0, int n, FloatVar x1)
Post propagator for for .
bool operator==(const FloatVal &x, const FloatVal &y)
Definition val.hpp:295
bool operator!=(const FloatVal &x, const FloatVal &y)
Definition val.hpp:318
void tan(Home home, FloatVar x0, FloatVar x1)
Post propagator for .
#define forceinline
Definition config.hpp:144