Generated on for Gecode by doxygen 1.15.0
arithmetic.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.dev>
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.dev
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
40#include <cmath>
41#include <algorithm>
42#include <cfenv>
43#include <limits>
44
45namespace Test { namespace Float {
46
48 namespace Arithmetic {
49
55
56 class PositiveNRootBounds : public Base {
57 protected:
59 class RootSpace : public Gecode::Space {
60 public:
65 bool usePow)
66 : x0(*this, 0.0, usePow ? witness : hi),
67 x1(*this, usePow ? 0.0 : witness, usePow ? hi : witness) {
68 if (usePow) {
69 Gecode::pow(*this,x0,n,x1);
70 Gecode::rel(*this,x0,Gecode::FRT_EQ,witness);
71 } else {
72 Gecode::nroot(*this,x0,n,x1);
73 }
74 }
75
77 x0.update(*this,s.x0);
78 x1.update(*this,s.x1);
79 }
80
81 virtual Gecode::Space* copy(void) {
82 return new RootSpace(*this);
83 }
84 };
85
88 public:
93 : source(*this,0.0,hi),
94 root(*this,0.0,Gecode::Float::Limits::max) {
95 Gecode::nroot(*this,source,n,root);
96 }
97
99 source.update(*this,s.source);
100 root.update(*this,s.root);
101 }
102
103 virtual Gecode::Space* copy(void) {
104 return new NRootBoundSpace(*this);
105 }
106 };
107
109 bool check(Gecode::FloatNum hi, Gecode::FloatNum witness, int n,
110 int mode, bool usePow) const {
111 if (std::fesetround(mode) != 0)
112 return true;
113 RootSpace s(hi,witness,n,usePow);
114 if (s.status() != Gecode::SS_FAILED)
115 return true;
116 olog << "Root bound removed a solution for "
117 << (usePow ? "pow" : "nroot") << ", n=" << n
118 << ", mode=" << mode << std::endl;
119 return false;
120 }
121
123 int n, int mode) const {
124 if (std::fesetround(mode) != 0)
125 return true;
126 NRootBoundSpace s(hi,n);
127 if ((s.status() != Gecode::SS_FAILED) &&
128 (s.root.max() > rejected))
129 return true;
130 olog << "NRoot upper bound was not outward for n=" << n
131 << ", mode=" << mode << std::endl;
132 return false;
133 }
134 public:
137 : Base("Float::Arithmetic::PositiveNRootBounds") {}
138
139 virtual bool run(void) {
140 const int oldMode = std::fegetround();
141 const int modes[] = {
142 FE_TONEAREST, FE_DOWNWARD, FE_UPWARD, FE_TOWARDZERO
143 };
144 struct Case {
146 Gecode::FloatNum witness;
147 int n;
148 } cases[] = {
149 {std::ldexp(static_cast<Gecode::FloatNum>(0x156e1fc2f8f359ULL),
150 -1049),
151 std::ldexp(static_cast<Gecode::FloatNum>(0x14484bfeebc28cULL),
152 -152), 10},
153 {std::numeric_limits<Gecode::FloatNum>::denorm_min(),
154 std::ldexp(static_cast<Gecode::FloatNum>(0x18406003b2ae42ULL),
155 -160), 10},
156 {std::numeric_limits<Gecode::FloatNum>::max(),
157 std::ldexp(static_cast<Gecode::FloatNum>(0x1965fea53d6e0fULL),
158 118), 6}
159 };
160 bool result = true;
161 const Gecode::FloatNum roundingHi =
162 std::ldexp(static_cast<Gecode::FloatNum>(0x1751def03d6f38ULL),
163 458);
164 const Gecode::FloatNum rejectedUpper =
165 std::ldexp(static_cast<Gecode::FloatNum>(0x1350f4c43079ceULL),
166 203);
167 for (unsigned int m=0; m<sizeof(modes)/sizeof(modes[0]); m++) {
168 for (unsigned int c=0; c<sizeof(cases)/sizeof(cases[0]); c++) {
169 result = check(cases[c].hi,cases[c].witness,cases[c].n,
170 modes[m],false) && result;
171 result = check(cases[c].hi,cases[c].witness,cases[c].n,
172 modes[m],true) && result;
173 }
174 result = checkBound(roundingHi,rejectedUpper,2,modes[m]) && result;
175 }
176 if (oldMode != -1)
177 std::fesetround(oldMode);
178 return result;
179 }
181
183 class PowConsistency : public Base {
184 protected:
186 class ZeroSpace : public Gecode::Space {
187 public:
191 ZeroSpace(int n, bool direct)
192 : x(*this,direct ? 0.0 : -1.0,direct ? 0.0 : 1.0),
193 y(*this,-1.0,2.0) {
194 Gecode::pow(*this,x,n,y);
195 }
196
198 x.update(*this,s.x);
199 y.update(*this,s.y);
200 }
201
202 virtual Gecode::Space* copy(void) {
203 return new ZeroSpace(*this);
204 }
205 };
206
209 public:
213 AdjacentZeroSpace(bool positive)
214 : x(*this,
215 positive ? 0.0
216 : -std::numeric_limits<Gecode::FloatNum>::denorm_min(),
217 positive ? std::numeric_limits<Gecode::FloatNum>::denorm_min()
218 : -0.0),
219 y(*this,-1.0,2.0) {
220 Gecode::pow(*this,x,0,y);
221 }
222
224 x.update(*this,s.x);
225 y.update(*this,s.y);
226 }
227
228 virtual Gecode::Space* copy(void) {
229 return new AdjacentZeroSpace(*this);
230 }
231 };
232
235 public:
240 : x(*this,
241 -std::ldexp(static_cast<Gecode::FloatNum>
242 (0x10000000000006ULL),-53),
243 -std::ldexp(static_cast<Gecode::FloatNum>
244 (0x10000000000004ULL),-53)),
245 y(*this,
246 std::ldexp(static_cast<Gecode::FloatNum>
247 (0x1000000000000aULL),-54),
248 std::ldexp(static_cast<Gecode::FloatNum>
249 (0x1000000000000cULL),-54)) {
250 Gecode::pow(*this,x,2,y);
251 }
252
254 x.update(*this,s.x);
255 y.update(*this,s.y);
256 }
257
258 virtual Gecode::Space* copy(void) {
259 return new FixpointSpace(*this);
260 }
261 };
262
265 public:
269 ZeroResultSpace(int n, bool direct)
270 : x(*this,-1.0,1.0),
271 y(*this,direct ? 0.0 : -1.0,direct ? 0.0 : 1.0) {
272 Gecode::pow(*this,x,n,y);
273 }
274
276 x.update(*this,s.x);
277 y.update(*this,s.y);
278 }
279
280 virtual Gecode::Space* copy(void) {
281 return new ZeroResultSpace(*this);
282 }
283 };
284
286 bool checkZero(int n) const {
287 ZeroSpace direct(n,true);
288 ZeroSpace delayed(n,false);
289 if (delayed.status() == Gecode::SS_FAILED) {
290 olog << "Pow wide base failed for n=" << n << std::endl;
291 return false;
292 }
293 ZeroSpace* clone = static_cast<ZeroSpace*>(delayed.clone());
294 Gecode::rel(*clone,clone->x,Gecode::FRT_EQ,0.0);
295 if (n == 0) {
296 const bool zeroRejected =
297 (direct.status() == Gecode::SS_FAILED) &&
298 (clone->status() == Gecode::SS_FAILED);
299 delete clone;
300 ZeroSpace* nonZero = static_cast<ZeroSpace*>(delayed.clone());
301 Gecode::rel(*nonZero,nonZero->x,Gecode::FRT_EQ,0.5);
302 const bool nonZeroAccepted =
303 (nonZero->status() != Gecode::SS_FAILED) &&
304 (nonZero->y.min() == 1.0) && (nonZero->y.max() == 1.0) &&
305 (Gecode::PropagatorGroup::all.size(*nonZero) == 0);
306 delete nonZero;
307 if (!zeroRejected || !nonZeroAccepted)
308 olog << "Pow exponent-zero semantics failed" << std::endl;
309 return zeroRejected && nonZeroAccepted;
310 }
311 const bool result =
312 (direct.status() != Gecode::SS_FAILED) &&
313 (direct.y.min() == 0.0) && (direct.y.max() == 0.0) &&
314 (clone->status() != Gecode::SS_FAILED) &&
315 (clone->y.min() == 0.0) && (clone->y.max() == 0.0);
316 delete clone;
317 if (!result)
318 olog << "Pow delayed zero failed for n=" << n << std::endl;
319 return result;
320 }
321
322 bool checkZeroResult(int n, bool direct) const {
323 ZeroResultSpace initial(n,direct);
324 if (initial.status() == Gecode::SS_FAILED) {
325 olog << "Pow zero result failed for n=" << n << std::endl;
326 return false;
327 }
328 ZeroResultSpace* clone =
329 static_cast<ZeroResultSpace*>(initial.clone());
330 if (!direct)
331 Gecode::rel(*clone,clone->y,Gecode::FRT_EQ,0.0);
332 const bool contracted =
333 (clone->status() != Gecode::SS_FAILED) &&
334 (clone->x.min() == 0.0) && (clone->x.max() == 0.0);
335 Gecode::rel(*clone,clone->x,Gecode::FRT_EQ,1.0);
336 const bool inconsistentRejected =
337 clone->status() == Gecode::SS_FAILED;
338 delete clone;
339 if (!contracted || !inconsistentRejected)
340 olog << "Pow zero result did not force zero base for n=" << n
341 << (direct ? " (direct)" : " (delayed)") << std::endl;
342 return contracted && inconsistentRejected;
343 }
344
345 bool checkAdjacentZero(bool positive) const {
346 AdjacentZeroSpace initial(positive);
347 const bool actorRetained =
348 (initial.status() != Gecode::SS_FAILED) &&
349 (initial.y.min() == 1.0) && (initial.y.max() == 1.0) &&
350 (Gecode::PropagatorGroup::all.size(initial) == 1);
351
352 AdjacentZeroSpace* clone =
353 static_cast<AdjacentZeroSpace*>(initial.clone());
354 const bool cloneRetained =
355 (clone->status() != Gecode::SS_FAILED) &&
356 (clone->y.min() == 1.0) && (clone->y.max() == 1.0) &&
357 (Gecode::PropagatorGroup::all.size(*clone) == 1);
358 delete clone;
359
360 if (!actorRetained || !cloneRetained)
361 olog << "Pow adjacent exponent-zero semantics failed"
362 << (positive ? " (positive)" : " (negative)") << std::endl;
363 return actorRetained && cloneRetained;
364 }
365 public:
367 PowConsistency(void) : Base("Float::Arithmetic::PowConsistency") {}
369 virtual bool run(void) {
370 bool result = true;
371 for (int n=0; n<=3; n++)
372 result = checkZero(n) && result;
373 for (int n=1; n<=3; n++) {
374 result = checkZeroResult(n,true) && result;
375 result = checkZeroResult(n,false) && result;
376 }
377 result = checkAdjacentZero(true) && result;
378 result = checkAdjacentZero(false) && result;
379
380 FixpointSpace once;
381 if (once.status() == Gecode::SS_FAILED) {
382 olog << "Pow fixpoint instance failed" << std::endl;
383 return false;
384 }
385 FixpointSpace* twice = static_cast<FixpointSpace*>(once.clone());
386 Gecode::pow(*twice,twice->x,2,twice->y);
387 const bool fixpoint =
388 (twice->status() != Gecode::SS_FAILED) &&
389 (once.x.min() == twice->x.min()) &&
390 (once.x.max() == twice->x.max()) &&
391 (once.y.min() == twice->y.min()) &&
392 (once.y.max() == twice->y.max());
393 delete twice;
394 if (!fixpoint)
395 olog << "Pow posting did not reach a fixpoint" << std::endl;
396 return fixpoint && result;
397 }
399
401 class MultZeroEndpoint : public Base {
402 protected:
404 class MultSpace : public Gecode::Space {
405 public:
412 : x(*this,xl,xu), y(*this,yl,yu), z(*this,zl,zu) {
413 Gecode::mult(*this,x,y,z);
414 }
415
417 x.update(*this,s.x);
418 y.update(*this,s.y);
419 z.update(*this,s.z);
420 }
421
422 virtual Gecode::Space* copy(void) {
423 return new MultSpace(*this);
424 }
425 };
426
431 Gecode::FloatNum expectedMin,
432 Gecode::FloatNum expectedMax) const {
433 MultSpace s(xl,xu,yl,yu,zl,zu);
434 if ((s.status() == Gecode::SS_FAILED) ||
435 (s.x.min() < expectedMin) || (s.x.max() > expectedMax)) {
436 olog << "Multiplication endpoint-zero contraction failed: x="
437 << s.x << ", y=" << s.y << ", z=" << s.z << std::endl;
438 return false;
439 }
440 MultSpace* clone = static_cast<MultSpace*>(s.clone());
441 Gecode::mult(*clone,clone->x,clone->y,clone->z);
442 const bool fixpoint =
443 (clone->status() != Gecode::SS_FAILED) &&
444 (clone->x.min() == s.x.min()) && (clone->x.max() == s.x.max()) &&
445 (clone->y.min() == s.y.min()) && (clone->y.max() == s.y.max()) &&
446 (clone->z.min() == s.z.min()) && (clone->z.max() == s.z.max());
447 delete clone;
448 if (!fixpoint)
449 olog << "Multiplication endpoint-zero case was not at a fixpoint"
450 << std::endl;
451 return fixpoint;
452 }
453
454 bool fuzz(void) const {
455 unsigned int state = 0x6d756c74U;
456 for (unsigned int i=0; i<5000; i++) {
457 state = state * 1664525U + 1013904223U;
458 const Gecode::FloatNum am =
459 0.125 + static_cast<Gecode::FloatNum>((state >> 8) % 8000) /
460 512.0;
461 state = state * 1664525U + 1013904223U;
462 const Gecode::FloatNum bm =
463 0.125 + static_cast<Gecode::FloatNum>((state >> 8) % 8000) /
464 512.0;
465 const Gecode::FloatNum a = (i & 1U) ? -am : am;
466 const Gecode::FloatNum b = (i & 2U) ? -bm : bm;
467 const Gecode::FloatNum p = a * b;
468 const Gecode::FloatNum slack = 1.0 + am / 4.0;
469 const Gecode::FloatNum xl = a - slack;
470 const Gecode::FloatNum xu = a + slack;
471 const Gecode::FloatNum yl = (b < 0.0) ? -(bm + 1.0) : 0.0;
472 const Gecode::FloatNum yu = (b < 0.0) ? -0.0 : bm + 1.0;
473 MultSpace s(xl,xu,yl,yu,p,p);
474 if ((s.status() == Gecode::SS_FAILED) ||
475 (s.x.min() > a) || (s.x.max() < a) ||
476 (s.y.min() > b) || (s.y.max() < b) ||
477 (s.z.min() > p) || (s.z.max() < p)) {
478 olog << "Multiplication removed supported fuzz point " << i
479 << ": (" << a << ", " << b << ", " << p << ")"
480 << std::endl;
481 return false;
482 }
483 }
484 return true;
485 }
486 public:
489 : Base("Float::Arithmetic::MultZeroEndpoint") {}
490
491 virtual bool run(void) {
492 bool result = true;
493 result = check(-1.0,1.0, 0.0,1.0, 0.5,1.0,
494 0.5,1.0) && result;
495 result = check(-1.0,1.0,-1.0,-0.0, 0.5,1.0,
496 -1.0,-0.5) && result;
497 result = check(-1.0,1.0, 0.0,1.0,-1.0,-0.5,
498 -1.0,-0.5) && result;
499 result = check(-1.0,1.0,-1.0,-0.0,-1.0,-0.5,
500 0.5,1.0) && result;
501
502 // Swapping the factors must recover the same contraction.
503 MultSpace swapped(0.0,1.0,-1.0,1.0,0.5,1.0);
504 result = (swapped.status() != Gecode::SS_FAILED) &&
505 (swapped.y.min() >= 0.5) && result;
506
507 // A zero product gives no sign information about the other factor.
508 MultSpace zeroProduct(-1.0,1.0,0.0,1.0,0.0,0.0);
509 result = (zeroProduct.status() != Gecode::SS_FAILED) &&
510 (zeroProduct.x.min() == -1.0) &&
511 (zeroProduct.x.max() == 1.0) && result;
512 MultSpace zeroFactor(0.0,0.0,-1.0,1.0,0.0,0.0);
513 result = (zeroFactor.status() != Gecode::SS_FAILED) &&
514 (zeroFactor.y.min() == -1.0) &&
515 (zeroFactor.y.max() == 1.0) && result;
516 if (!result)
517 olog << "Multiplication zero or swapped regression failed"
518 << std::endl;
519 return fuzz() && result;
520 }
522
524 class MultXYZ : public Test {
525 public:
527 MultXYZ(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st)
528 : Test("Arithmetic::Mult::XYZ::"+s,3,d,st,CPLT_ASSIGNMENT,false) {}
529
530 virtual MaybeType solution(const Assignment& x) const {
531 return eq(x[0] * x[1], x[2]);
532 }
533
534 virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
535 if (flip())
536 Gecode::mult(home, x[0], x[1], x[2]);
537 else
538 Gecode::rel(home, x[0] * x[1] == x[2]);
539 }
540 };
541
543 class MultXYZSol : public Test {
544 public:
546 MultXYZSol(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st)
547 : Test("Arithmetic::Mult::XYZ::Sol::"+s,3,d,st,EXTEND_ASSIGNMENT,false) {}
548
549 virtual MaybeType solution(const Assignment& x) const {
550 return eq(x[0] * x[1], x[2]);
551 }
552
553 virtual bool extendAssignment(Assignment& x) const {
554 Gecode::FloatVal d = x[0]*x[1];
555 if (Gecode::Float::subset(d, dom)) {
556 x.set(2, d);
557 return true;
558 } else {
559 return false;
560 }
561 }
562
563 virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
564 Gecode::mult(home, x[0], x[1], x[2]);
565 }
566 };
567
569 class MultXXY : public Test {
570 public:
572 MultXXY(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st)
573 : Test("Arithmetic::Mult::XXY::"+s,2,d,st,CPLT_ASSIGNMENT,false) {}
574
575 virtual MaybeType solution(const Assignment& x) const {
576 return eq(x[0] * x[0], x[1]);
577 }
578
579 virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
580 Gecode::mult(home, x[0], x[0], x[1]);
581 }
582 };
583
585 class MultXXYSol : public Test {
586 public:
588 MultXXYSol(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st)
589 : Test("Arithmetic::Mult::XXY::Sol::"+s,2,d,st,EXTEND_ASSIGNMENT,false) {}
590
591 virtual MaybeType solution(const Assignment& x) const {
592 return eq(x[0] * x[0], x[1]);
593 }
594
595 virtual bool extendAssignment(Assignment& x) const {
596 Gecode::FloatVal d = x[0]*x[0];
597 if (Gecode::Float::subset(d, dom)) {
598 x.set(1, d);
599 return true;
600 } else {
601 return false;
602 }
603 }
604
605 virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
606 Gecode::mult(home, x[0], x[0], x[1]);
607 }
608 };
609
611 class MultXYX : public Test {
612 public:
614 MultXYX(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st)
615 : Test("Arithmetic::Mult::XYX::"+s,2,d,st,CPLT_ASSIGNMENT,false) {}
616
617 virtual MaybeType solution(const Assignment& x) const {
618 return eq(x[0] * x[1], x[0]);
619 }
620
621 virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
622 Gecode::mult(home, x[0], x[1], x[0]);
623 }
624 };
625
627 class MultXYY : public Test {
628 public:
630 MultXYY(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st)
631 : Test("Arithmetic::Mult::XYY::"+s,2,d,st,CPLT_ASSIGNMENT,false) {}
632
633 virtual MaybeType solution(const Assignment& x) const {
634 return eq(x[0] * x[1], x[1]);
635 }
636
637 virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
638 Gecode::mult(home, x[0], x[1], x[1]);
639 }
640 };
641
643 class MultXXX : public Test {
644 public:
646 MultXXX(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st)
647 : Test("Arithmetic::Mult::XXX::"+s,1,d,st,CPLT_ASSIGNMENT,false) {}
648
649 virtual MaybeType solution(const Assignment& x) const {
650 return eq(x[0] * x[0], x[0]);
651 }
652
653 virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
654 Gecode::mult(home, x[0], x[0], x[0]);
655 }
656 };
657
659 class Div : public Test {
660 public:
662 Div(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st)
663 : Test("Arithmetic::Div::"+s,3,d,st,CPLT_ASSIGNMENT,false) {}
664
665 virtual MaybeType solution(const Assignment& x) const {
666 return eq(x[0] / x[1], x[2]);
667 }
668
669 virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
670 if (flip())
671 Gecode::div(home, x[0], x[1], x[2]);
672 else
673 Gecode::rel(home, x[0] / x[1] == x[2]);
674 }
675 };
676
678 class DivSol : public Test {
679 public:
681 DivSol(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st)
682 : Test("Arithmetic::Div::Sol::"+s,3,d,st,EXTEND_ASSIGNMENT,false) {}
683
684 virtual MaybeType solution(const Assignment& x) const {
685 return eq(x[0] / x[1], x[2]);
686 }
687
688 virtual bool extendAssignment(Assignment& x) const {
689 Gecode::FloatVal d = x[0]/x[1];
690 if (Gecode::Float::subset(d, dom)) {
691 x.set(2, d);
692 return true;
693 } else {
694 return false;
695 }
696 }
697
698 virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
699 Gecode::div(home, x[0], x[1], x[2]);
700 }
701 };
702
704 class SqrXY : public Test {
705 public:
707 SqrXY(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st)
708 : Test("Arithmetic::Sqr::XY::"+s,2,d,st,CPLT_ASSIGNMENT,false) {}
709
710 virtual MaybeType solution(const Assignment& x) const {
711 return eq(x[0] * x[0], x[1]);
712 }
713
714 virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
715 if (flip())
716 Gecode::sqr(home, x[0], x[1]);
717 else
718 Gecode::rel(home, sqr(x[0]) == x[1]);
719 }
720 };
721
723 class SqrXYSol : public Test {
724 public:
726 SqrXYSol(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st)
727 : Test("Arithmetic::Sqr::XY::Sol::"+s,2,d,st,EXTEND_ASSIGNMENT,false) {}
728
729 virtual MaybeType solution(const Assignment& x) const {
730 return eq(x[0] * x[0], x[1]);
731 }
732
733 virtual bool extendAssignment(Assignment& x) const {
734 Gecode::FloatVal d = sqr(x[0]);
735 if (Gecode::Float::subset(d, dom)) {
736 x.set(1, d);
737 return true;
738 } else {
739 return false;
740 }
741 }
742
743 virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
744 Gecode::sqr(home, x[0], x[1]);
745 }
746 };
747
749 class SqrXX : public Test {
750 public:
752 SqrXX(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st)
753 : Test("Arithmetic::Sqr::XX::"+s,1,d,st,CPLT_ASSIGNMENT,false) {}
754
755 virtual MaybeType solution(const Assignment& x) const {
756 return eq(x[0] * x[0], x[0]);
757 }
758
759 virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
760 Gecode::sqr(home, x[0], x[0]);
761 }
762 };
763
765 class SqrtXY : public Test {
766 public:
768 SqrtXY(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st)
769 : Test("Arithmetic::Sqrt::XY::"+s,2,d,st,CPLT_ASSIGNMENT,false) {}
770
771 virtual MaybeType solution(const Assignment& x) const {
772 switch (cmp(x[0], Gecode::FRT_GQ, 0.0)) {
773 case MT_FALSE: return MT_FALSE;
774 case MT_MAYBE: return MT_MAYBE;
775 default:
776 return eq(sqrt(x[0]), x[1]);
777 }
778 }
779
780 virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
781 if (flip())
782 Gecode::sqrt(home, x[0], x[1]);
783 else
784 Gecode::rel(home, sqrt(x[0]) == x[1]);
785 }
786 };
787
789 class SqrtXYSol : public Test {
790 public:
792 SqrtXYSol(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st)
793 : Test("Arithmetic::Sqrt::XY::Sol::"+s,2,d,st,EXTEND_ASSIGNMENT,false) {}
794
795 virtual MaybeType solution(const Assignment& x) const {
796 switch (cmp(x[0], Gecode::FRT_GQ, 0.0)) {
797 case MT_FALSE: return MT_FALSE;
798 case MT_MAYBE: return MT_MAYBE;
799 default:
800 return eq(sqrt(x[0]), x[1]);
801 }
802 }
803
804 virtual bool extendAssignment(Assignment& x) const {
805 Gecode::FloatVal d = sqrt(abs(x[0]));
806 if (Gecode::Float::subset(d, dom)) {
807 x.set(1, d);
808 return true;
809 } else {
810 return false;
811 }
812 }
813
814 virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
815 Gecode::sqrt(home, x[0], x[1]);
816 }
817 };
818
820 class SqrtXX : public Test {
821 public:
823 SqrtXX(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st)
824 : Test("Arithmetic::Sqrt::XX::"+s,1,d,st,CPLT_ASSIGNMENT,false) {}
825
826 virtual MaybeType solution(const Assignment& x) const {
827 switch (cmp(x[0], Gecode::FRT_GQ, 0.0)) {
828 case MT_FALSE: return MT_FALSE;
829 case MT_MAYBE: return MT_MAYBE;
830 default:
831 return eq(sqrt(x[0]), x[0]);
832 }
833 }
834
835 virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
836 Gecode::sqrt(home, x[0], x[0]);
837 }
838 };
839
841 class PowXY : public Test {
842 unsigned int n;
843 public:
845 PowXY(const std::string& s, const Gecode::FloatVal& d, unsigned int _n, Gecode::FloatNum st)
846 : Test("Arithmetic::Pow::N::"+str(_n)+"::XY::"+s,2,d,st,CPLT_ASSIGNMENT,false), n(_n) {}
847
848 virtual MaybeType solution(const Assignment& x) const {
849 return eq(pow(x[0],n), x[1]);
850 }
851
852 virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
853 if (flip())
854 Gecode::pow(home, x[0], n, x[1]);
855 else
856 Gecode::rel(home, pow(x[0],n) == x[1]);
857 }
858 };
859
861 class PowXYSol : public Test {
862 unsigned int n;
863 public:
865 PowXYSol(const std::string& s, const Gecode::FloatVal& d, unsigned int _n, Gecode::FloatNum st)
866 : Test("Arithmetic::Pow::N::"+str(_n)+"::XY::Sol::"+s,2,d,st,EXTEND_ASSIGNMENT,false), n(_n) {}
867
868 virtual MaybeType solution(const Assignment& x) const {
869 return eq(pow(x[0],n), x[1]);
870 }
871
872 virtual bool extendAssignment(Assignment& x) const {
873 Gecode::FloatVal d = pow(x[0],n);
874 if (Gecode::Float::subset(d, dom)) {
875 x.set(1, d);
876 return true;
877 } else {
878 return false;
879 }
880 }
881
882 virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
883 Gecode::pow(home, x[0], n, x[1]);
884 }
885 };
886
888 class PowXX : public Test {
889 unsigned int n;
890 public:
892 PowXX(const std::string& s, const Gecode::FloatVal& d, unsigned int _n, Gecode::FloatNum st)
893 : Test("Arithmetic::Pow::N::"+str(_n)+"::XX::"+s,1,d,st,CPLT_ASSIGNMENT,false), n(_n) {}
894
895 virtual MaybeType solution(const Assignment& x) const {
896 return eq(pow(x[0],n), x[0]);
897 }
898
899 virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
900 Gecode::pow(home, x[0], n, x[0]);
901 }
902 };
903
905 class NRootXY : public Test {
906 unsigned int n;
907 public:
909 NRootXY(const std::string& s, const Gecode::FloatVal& d, unsigned int _n, Gecode::FloatNum st)
910 : Test("Arithmetic::NRoot::N::"+str(_n)+"::XY::"+s,2,d,st,CPLT_ASSIGNMENT,false), n(_n) {}
911
912 virtual MaybeType solution(const Assignment& x) const {
913 if ((n == 0) || (x[0].min() < 0.0))
914 return MT_FALSE;
915 return eq(nroot(x[0],n), x[1]);
916 }
917
918 virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
919 if (flip())
920 Gecode::nroot(home, x[0], n, x[1]);
921 else
922 Gecode::rel(home, nroot(x[0],n) == x[1]);
923 }
924 };
925
927 class NRootXYSol : public Test {
928 unsigned int n;
929 public:
931 NRootXYSol(const std::string& s, const Gecode::FloatVal& d, unsigned int _n, Gecode::FloatNum st)
932 : Test("Arithmetic::NRoot::N::"+str(_n)+"::XY::Sol::"+s,2,d,st,EXTEND_ASSIGNMENT,false), n(_n) {}
933
934 virtual MaybeType solution(const Assignment& x) const {
935 if ((n == 0) || (x[0].min() < 0.0))
936 return MT_FALSE;
937 return eq(nroot(x[0],n), x[1]);
938 }
939
940 virtual bool extendAssignment(Assignment& x) const {
941 if ((n == 0) || (x[0].min() < 0))
942 return false;
943 Gecode::FloatVal d = nroot(x[0],n);
944 if (Gecode::Float::subset(d, dom)) {
945 x.set(1, d);
946 return true;
947 } else {
948 return false;
949 }
950 }
951
952 virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
953 Gecode::nroot(home, x[0], n, x[1]);
954 }
955 };
956
958 class NRootXX : public Test {
959 unsigned int n;
960 public:
962 NRootXX(const std::string& s, const Gecode::FloatVal& d, unsigned int _n, Gecode::FloatNum st)
963 : Test("Arithmetic::NRoot::N::"+str(_n)+"::XX::"+s,1,d,st,CPLT_ASSIGNMENT,false), n(_n) {}
964
965 virtual MaybeType solution(const Assignment& x) const {
966 if ((n == 0) || (x[0].min() < 0))
967 return MT_FALSE;
968 return eq(nroot(x[0],n), x[0]);
969 }
970
971 virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
972 Gecode::nroot(home, x[0], n, x[0]);
973 }
974 };
975
977 class AbsXY : public Test {
978 public:
980 AbsXY(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st)
981 : Test("Arithmetic::Abs::XY::"+s,2,d,st,CPLT_ASSIGNMENT,false) {}
982
983 virtual MaybeType solution(const Assignment& x) const {
984 return eq(abs(x[0]), x[1]);
985 }
986
987 virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
988 if (flip())
989 Gecode::abs(home, x[0], x[1]);
990 else
991 Gecode::rel(home, abs(x[0]) == x[1]);
992 }
993 };
994
996 class AbsXX : public Test {
997 public:
999 AbsXX(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st)
1000 : Test("Arithmetic::Abs::XX::"+s,1,d,st,CPLT_ASSIGNMENT,false) {}
1001
1002 virtual MaybeType solution(const Assignment& x) const {
1003 return eq(abs(x[0]), x[0]);
1004 }
1005
1006 virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
1007 Gecode::abs(home, x[0], x[0]);
1008 }
1009 };
1010
1012 class MinXYZ : public Test {
1013 public:
1015 MinXYZ(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st)
1016 : Test("Arithmetic::Min::Bin::XYZ::"+s,3,d,st,CPLT_ASSIGNMENT,false) {}
1017
1018 virtual MaybeType solution(const Assignment& x) const {
1019 return eq(min(x[0],x[1]), x[2]);
1020 }
1021
1022 virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
1023 if (flip())
1024 Gecode::min(home, x[0], x[1], x[2]);
1025 else
1026 Gecode::rel(home, min(x[0],x[1]) == x[2]);
1027 }
1028 };
1029
1031 class MinXXY : public Test {
1032 public:
1034 MinXXY(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st)
1035 : Test("Arithmetic::Min::Bin::XXY::"+s,2,d,st,CPLT_ASSIGNMENT,false) {}
1036
1037 virtual MaybeType solution(const Assignment& x) const {
1038 return eq(min(x[0],x[0]), x[1]);
1039 }
1040
1041 virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
1042 Gecode::min(home, x[0], x[0], x[1]);
1043 }
1044 };
1045
1047 class MinXYX : public Test {
1048 public:
1050 MinXYX(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st)
1051 : Test("Arithmetic::Min::Bin::XYX::"+s,2,d,st,CPLT_ASSIGNMENT,false) {}
1052
1053 virtual MaybeType solution(const Assignment& x) const {
1054 return eq(min(x[0],x[1]), x[0]);
1055 }
1056
1057 virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
1058 Gecode::min(home, x[0], x[1], x[0]);
1059 }
1060 };
1061
1063 class MinXYY : public Test {
1064 public:
1066 MinXYY(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st)
1067 : Test("Arithmetic::Min::Bin::XYY::"+s,2,d,st,CPLT_ASSIGNMENT,false) {}
1068
1069 virtual MaybeType solution(const Assignment& x) const {
1070 return eq(min(x[0],x[1]), x[1]);
1071 }
1072
1073 virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
1074 Gecode::min(home, x[0], x[1], x[1]);
1075 }
1076 };
1077
1079 class MinXXX : public Test {
1080 public:
1082 MinXXX(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st)
1083 : Test("Arithmetic::Min::Bin::XXX::"+s,1,d,st,CPLT_ASSIGNMENT,false) {}
1084
1085 virtual MaybeType solution(const Assignment& x) const {
1086 return eq(min(x[0],x[0]), x[0]);
1087 }
1088
1089 virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
1090 Gecode::min(home, x[0], x[0], x[0]);
1091 }
1092 };
1093
1095 class MaxXYZ : public Test {
1096 public:
1098 MaxXYZ(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st)
1099 : Test("Arithmetic::Max::Bin::XYZ::"+s,3,d,st,CPLT_ASSIGNMENT,false) {}
1100
1101 virtual MaybeType solution(const Assignment& x) const {
1102 return eq(max(x[0],x[1]), x[2]);
1103 }
1104
1105 virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
1106 if (flip())
1107 Gecode::max(home, x[0], x[1], x[2]);
1108 else
1109 Gecode::rel(home, max(x[0], x[1]) == x[2]);
1110 }
1111 };
1112
1114 class MaxXXY : public Test {
1115 public:
1117 MaxXXY(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st)
1118 : Test("Arithmetic::Max::Bin::XXY::"+s,2,d,st,CPLT_ASSIGNMENT,false) {}
1119
1120 virtual MaybeType solution(const Assignment& x) const {
1121 return eq(max(x[0],x[0]), x[1]);
1122 }
1123
1124 virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
1125 Gecode::max(home, x[0], x[0], x[1]);
1126 }
1127 };
1128
1130 class MaxXYX : public Test {
1131 public:
1133 MaxXYX(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st)
1134 : Test("Arithmetic::Max::Bin::XYX::"+s,2,d,st,CPLT_ASSIGNMENT,false) {}
1135
1136 virtual MaybeType solution(const Assignment& x) const {
1137 return eq(max(x[0],x[1]), x[0]);
1138 }
1139
1140 virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
1141 Gecode::max(home, x[0], x[1], x[0]);
1142 }
1143 };
1144
1146 class MaxXYY : public Test {
1147 public:
1149 MaxXYY(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st)
1150 : Test("Arithmetic::Max::Bin::XYY::"+s,2,d,st,CPLT_ASSIGNMENT,false) {}
1151
1152 virtual MaybeType solution(const Assignment& x) const {
1153 return eq(max(x[0],x[1]), x[1]);
1154 }
1155
1156 virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
1157 Gecode::max(home, x[0], x[1], x[1]);
1158 }
1159 };
1160
1162 class MaxXXX : public Test {
1163 public:
1165 MaxXXX(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st)
1166 : Test("Arithmetic::Max::Bin::XXX::"+s,1,d,st,CPLT_ASSIGNMENT,false) {}
1167
1168 virtual MaybeType solution(const Assignment& x) const {
1169 return eq(max(x[0],x[0]), x[0]);
1170 }
1171
1172 virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
1173 Gecode::max(home, x[0], x[0], x[0]);
1174 }
1175 };
1176
1178 class MinNary : public Test {
1179 public:
1182 : Test("Arithmetic::Min::Nary",4,-4,4,0.5,CPLT_ASSIGNMENT,false) {}
1183
1184 virtual MaybeType solution(const Assignment& x) const {
1185 return eq(min(min(x[0],x[1]),x[2]), x[3]);
1186 }
1187
1188 virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
1190 m[0]=x[0]; m[1]=x[1]; m[2]=x[2];
1191 if (flip())
1192 Gecode::min(home, m, x[3]);
1193 else
1194 Gecode::rel(home, min(m) == x[3]);
1195 }
1196 };
1197
1199 class MinNaryShared : public Test {
1200 public:
1203 : Test("Arithmetic::Min::Nary::Shared",3,-4,4,0.5,CPLT_ASSIGNMENT,false) {}
1204
1205 virtual MaybeType solution(const Assignment& x) const {
1206 return eq(min(min(x[0],x[1]),x[2]), x[1]);
1207 }
1208
1209 virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
1211 m[0]=x[0]; m[1]=x[1]; m[2]=x[2];
1212 Gecode::min(home, m, x[1]);
1213 }
1214 };
1215
1217 class MaxNary : public Test {
1218 public:
1221 : Test("Arithmetic::Max::Nary",4,-4,4,0.5,CPLT_ASSIGNMENT,false) {}
1222
1223 virtual MaybeType solution(const Assignment& x) const {
1224 return eq(max(max(x[0],x[1]),x[2]), x[3]);
1225 }
1226
1227 virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
1229 m[0]=x[0]; m[1]=x[1]; m[2]=x[2];
1230 if (flip())
1231 Gecode::max(home, m, x[3]);
1232 else
1233 Gecode::rel(home, max(m) == x[3]);
1234 }
1235 };
1236
1238 class MaxNaryShared : public Test {
1239 public:
1242 : Test("Arithmetic::Max::Nary::Shared",3,-4,4,0.5,CPLT_ASSIGNMENT,false) {}
1243
1244 virtual MaybeType solution(const Assignment& x) const {
1245 return eq(max(max(x[0],x[1]),x[2]), x[1]);
1246 }
1247
1248 virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
1250 m[0]=x[0]; m[1]=x[1]; m[2]=x[2];
1251 Gecode::max(home, m, x[1]);
1252 }
1253 };
1254
1259
1263
1267
1271
1275
1279
1283
1287
1291
1295
1299
1303
1307
1311
1315
1319
1323
1327
1331
1335
1339
1343
1347
1351
1355
1359
1363
1367
1371
1375
1379
1383
1387
1391
1395
1399
1403
1407
1411
1415
1419
1423
1427
1431
1435
1439
1445
1446 }
1447}}
1448
1449// STATISTICS: test-float
Float value type.
Definition float.hh:334
Passing float variables.
Definition float.hh:982
Float variable array.
Definition float.hh:1035
Float variables.
Definition float.hh:870
FloatNum min(void) const
Return minimum of domain.
Definition float.hpp:59
FloatNum max(void) const
Return maximum of domain.
Definition float.hpp:67
static PropagatorGroup all
Group of all propagators.
Definition core.hpp:796
Computation spaces.
Definition core.hpp:1775
Base(std::string s)
Create and register test with name s.
Definition test.cpp:60
bool fixpoint(void)
Throw a coin whether to compute a fixpoint.
Definition test.hpp:67
Test for absolute value constraint with shared variables
virtual MaybeType solution(const Assignment &x) const
Test whether x is solution
AbsXX(const std::string &s, const Gecode::FloatVal &d, Gecode::FloatNum st)
Create and register test.
virtual void post(Gecode::Space &home, Gecode::FloatVarArray &x)
Post constraint on x.
Test for absolute value constraint
AbsXY(const std::string &s, const Gecode::FloatVal &d, Gecode::FloatNum st)
Create and register test.
virtual MaybeType solution(const Assignment &x) const
Test whether x is solution
virtual void post(Gecode::Space &home, Gecode::FloatVarArray &x)
Post constraint on x.
Test for division constraint when solution is ensured
virtual MaybeType solution(const Assignment &x) const
Test whether x is solution
virtual bool extendAssignment(Assignment &x) const
Extend assignment x.
virtual void post(Gecode::Space &home, Gecode::FloatVarArray &x)
Post constraint on x.
DivSol(const std::string &s, const Gecode::FloatVal &d, Gecode::FloatNum st)
Create and register test.
Test for division constraint
virtual void post(Gecode::Space &home, Gecode::FloatVarArray &x)
Post constraint on x.
Div(const std::string &s, const Gecode::FloatVal &d, Gecode::FloatNum st)
Create and register test.
virtual MaybeType solution(const Assignment &x) const
Test whether x is solution
Test for n-ary maximum constraint with shared variables
virtual void post(Gecode::Space &home, Gecode::FloatVarArray &x)
Post constraint on x.
MaxNaryShared(void)
Create and register test.
virtual MaybeType solution(const Assignment &x) const
Test whether x is solution
Test for n-ary maximum constraint
MaxNary(void)
Create and register test.
virtual void post(Gecode::Space &home, Gecode::FloatVarArray &x)
Post constraint on x.
virtual MaybeType solution(const Assignment &x) const
Test whether x is solution
Test for binary maximum constraint with shared variables
MaxXXX(const std::string &s, const Gecode::FloatVal &d, Gecode::FloatNum st)
Create and register test.
virtual void post(Gecode::Space &home, Gecode::FloatVarArray &x)
Post constraint on x.
virtual MaybeType solution(const Assignment &x) const
Test whether x is solution
Test for binary maximum constraint with shared variables
virtual void post(Gecode::Space &home, Gecode::FloatVarArray &x)
Post constraint on x.
MaxXXY(const std::string &s, const Gecode::FloatVal &d, Gecode::FloatNum st)
Create and register test.
virtual MaybeType solution(const Assignment &x) const
Test whether x is solution
Test for binary maximum constraint with shared variables
virtual MaybeType solution(const Assignment &x) const
Test whether x is solution
virtual void post(Gecode::Space &home, Gecode::FloatVarArray &x)
Post constraint on x.
MaxXYX(const std::string &s, const Gecode::FloatVal &d, Gecode::FloatNum st)
Create and register test.
Test for binary maximum constraint with shared variables
virtual MaybeType solution(const Assignment &x) const
Test whether x is solution
MaxXYY(const std::string &s, const Gecode::FloatVal &d, Gecode::FloatNum st)
Create and register test.
virtual void post(Gecode::Space &home, Gecode::FloatVarArray &x)
Post constraint on x.
Test for binary maximum constraint
MaxXYZ(const std::string &s, const Gecode::FloatVal &d, Gecode::FloatNum st)
Create and register test.
virtual MaybeType solution(const Assignment &x) const
Test whether x is solution
virtual void post(Gecode::Space &home, Gecode::FloatVarArray &x)
Post constraint on x.
Test for n-ary minimmum constraint with shared variables
MinNaryShared(void)
Create and register test.
virtual MaybeType solution(const Assignment &x) const
Test whether x is solution
virtual void post(Gecode::Space &home, Gecode::FloatVarArray &x)
Post constraint on x.
Test for n-ary minimmum constraint
virtual MaybeType solution(const Assignment &x) const
Test whether x is solution
virtual void post(Gecode::Space &home, Gecode::FloatVarArray &x)
Post constraint on x.
MinNary(void)
Create and register test.
Test for binary minimum constraint with shared variables
virtual MaybeType solution(const Assignment &x) const
Test whether x is solution
MinXXX(const std::string &s, const Gecode::FloatVal &d, Gecode::FloatNum st)
Create and register test.
virtual void post(Gecode::Space &home, Gecode::FloatVarArray &x)
Post constraint on x.
Test for binary minimum constraint with shared variables
MinXXY(const std::string &s, const Gecode::FloatVal &d, Gecode::FloatNum st)
Create and register test.
virtual void post(Gecode::Space &home, Gecode::FloatVarArray &x)
Post constraint on x.
virtual MaybeType solution(const Assignment &x) const
Test whether x is solution
Test for binary minimum constraint with shared variables
MinXYX(const std::string &s, const Gecode::FloatVal &d, Gecode::FloatNum st)
Create and register test.
virtual MaybeType solution(const Assignment &x) const
Test whether x is solution
virtual void post(Gecode::Space &home, Gecode::FloatVarArray &x)
Post constraint on x.
Test for binary minimum constraint with shared variables
virtual MaybeType solution(const Assignment &x) const
Test whether x is solution
MinXYY(const std::string &s, const Gecode::FloatVal &d, Gecode::FloatNum st)
Create and register test.
virtual void post(Gecode::Space &home, Gecode::FloatVarArray &x)
Post constraint on x.
Test for binary minimum constraint
virtual MaybeType solution(const Assignment &x) const
Test whether x is solution
virtual void post(Gecode::Space &home, Gecode::FloatVarArray &x)
Post constraint on x.
MinXYZ(const std::string &s, const Gecode::FloatVal &d, Gecode::FloatNum st)
Create and register test.
Test for multiplication constraint with shared variables
virtual void post(Gecode::Space &home, Gecode::FloatVarArray &x)
Post constraint on x.
virtual MaybeType solution(const Assignment &x) const
Test whether x is solution
MultXXX(const std::string &s, const Gecode::FloatVal &d, Gecode::FloatNum st)
Create and register test.
Test for multiplication constraint with shared variables when solution is ensured
virtual bool extendAssignment(Assignment &x) const
Extend assignment x.
MultXXYSol(const std::string &s, const Gecode::FloatVal &d, Gecode::FloatNum st)
Create and register test.
virtual MaybeType solution(const Assignment &x) const
Test whether x is solution
virtual void post(Gecode::Space &home, Gecode::FloatVarArray &x)
Post constraint on x.
Test for multiplication constraint with shared variables
virtual void post(Gecode::Space &home, Gecode::FloatVarArray &x)
Post constraint on x.
virtual MaybeType solution(const Assignment &x) const
Test whether x is solution
MultXXY(const std::string &s, const Gecode::FloatVal &d, Gecode::FloatNum st)
Create and register test.
Test for multiplication constraint with shared variables
virtual void post(Gecode::Space &home, Gecode::FloatVarArray &x)
Post constraint on x.
MultXYX(const std::string &s, const Gecode::FloatVal &d, Gecode::FloatNum st)
Create and register test.
virtual MaybeType solution(const Assignment &x) const
Test whether x is solution
Test for multiplication constraint with shared variables
MultXYY(const std::string &s, const Gecode::FloatVal &d, Gecode::FloatNum st)
Create and register test.
virtual MaybeType solution(const Assignment &x) const
Test whether x is solution
virtual void post(Gecode::Space &home, Gecode::FloatVarArray &x)
Post constraint on x.
Test for multiplication constraint when solution is ensured
virtual MaybeType solution(const Assignment &x) const
Test whether x is solution
virtual void post(Gecode::Space &home, Gecode::FloatVarArray &x)
Post constraint on x.
virtual bool extendAssignment(Assignment &x) const
Extend assignment x.
MultXYZSol(const std::string &s, const Gecode::FloatVal &d, Gecode::FloatNum st)
Create and register test.
Test for multiplication constraint
MultXYZ(const std::string &s, const Gecode::FloatVal &d, Gecode::FloatNum st)
Create and register test.
virtual MaybeType solution(const Assignment &x) const
Test whether x is solution
virtual void post(Gecode::Space &home, Gecode::FloatVarArray &x)
Post constraint on x.
Space exposing multiplication propagation at the public API.
MultSpace(Gecode::FloatNum xl, Gecode::FloatNum xu, Gecode::FloatNum yl, Gecode::FloatNum yu, Gecode::FloatNum zl, Gecode::FloatNum zu)
Post x * y = z for the supplied intervals.
virtual Gecode::Space * copy(void)
Copy space during cloning.
Gecode::FloatVar x
Factors and product.
bool check(Gecode::FloatNum xl, Gecode::FloatNum xu, Gecode::FloatNum yl, Gecode::FloatNum yu, Gecode::FloatNum zl, Gecode::FloatNum zu, Gecode::FloatNum expectedMin, Gecode::FloatNum expectedMax) const
Check one endpoint-zero sign and magnitude contraction.
MultZeroEndpoint(void)
Create and register test.
virtual bool run(void)
Run sign, symmetry, signed-zero, and zero-product cases.
bool fuzz(void) const
Exercise supported points across endpoint-zero sign combinations.
Test for nroot constraint with shared variables
virtual void post(Gecode::Space &home, Gecode::FloatVarArray &x)
Post constraint on x.
NRootXX(const std::string &s, const Gecode::FloatVal &d, unsigned int _n, Gecode::FloatNum st)
Create and register test.
virtual MaybeType solution(const Assignment &x) const
Test whether x is solution
Test for nroot constraint where solution is ensured
virtual MaybeType solution(const Assignment &x) const
Test whether x is solution
virtual void post(Gecode::Space &home, Gecode::FloatVarArray &x)
Post constraint on x.
virtual bool extendAssignment(Assignment &x) const
Extend assignment x.
NRootXYSol(const std::string &s, const Gecode::FloatVal &d, unsigned int _n, Gecode::FloatNum st)
Create and register test.
Test for nroot constraint
virtual void post(Gecode::Space &home, Gecode::FloatVarArray &x)
Post constraint on x.
NRootXY(const std::string &s, const Gecode::FloatVal &d, unsigned int _n, Gecode::FloatNum st)
Create and register test.
virtual MaybeType solution(const Assignment &x) const
Test whether x is solution
Space exposing the propagated NthRoot upper bound.
virtual Gecode::Space * copy(void)
Copy space during cloning.
Gecode::FloatVar source
Source and root variables.
NRootBoundSpace(NRootBoundSpace &s)
Clone constructor.
NRootBoundSpace(Gecode::FloatNum hi, int n)
Post an NthRoot constraint with an unconstrained root.
Space exercising the Pow and NthRoot propagators.
virtual Gecode::Space * copy(void)
Copy space during cloning.
RootSpace(Gecode::FloatNum hi, Gecode::FloatNum witness, int n, bool usePow)
Post an extreme Pow or NthRoot instance.
Gecode::FloatVar x0
Variables used by the propagator.
bool checkBound(Gecode::FloatNum hi, Gecode::FloatNum rejected, int n, int mode) const
Check that propagation returns a genuinely outward upper bound.
bool check(Gecode::FloatNum hi, Gecode::FloatNum witness, int n, int mode, bool usePow) const
Check that a known feasible boundary value is not removed.
virtual bool run(void)
Run test under every supported IEEE-754 rounding mode.
PositiveNRootBounds(void)
Create and register test.
Space for an adjacent interval containing zero at one endpoint.
virtual Gecode::Space * copy(void)
Copy space during cloning.
Gecode::FloatVar x
Base and result variables.
AdjacentZeroSpace(AdjacentZeroSpace &s)
Clone constructor.
AdjacentZeroSpace(bool positive)
Post exponent zero on a positive or negative adjacent interval.
Space reproducing a Pow inverse-to-forward fixpoint.
virtual Gecode::Space * copy(void)
Copy space during cloning.
FixpointSpace(FixpointSpace &s)
Clone constructor.
FixpointSpace(void)
Post the fixpoint regression instance.
Gecode::FloatVar x
Base and result variables.
Space for direct and delayed assignment of the result to zero.
Gecode::FloatVar x
Base and result variables.
ZeroResultSpace(ZeroResultSpace &s)
Clone constructor.
ZeroResultSpace(int n, bool direct)
Post a power constraint with either a zero or a wide result.
virtual Gecode::Space * copy(void)
Copy space during cloning.
Space for direct and delayed assignment of the base to zero.
virtual Gecode::Space * copy(void)
Copy space during cloning.
Gecode::FloatVar x
Base and result variables.
ZeroSpace(int n, bool direct)
Post a power constraint with either a zero or a wide base.
bool checkZero(int n) const
Test one exponent with direct and delayed zero assignment.
bool checkAdjacentZero(bool positive) const
Test exponent zero on an adjacent interval containing zero.
virtual bool run(void)
Run zero and fixpoint regressions.
bool checkZeroResult(int n, bool direct) const
Test that a zero result forces a zero base.
PowConsistency(void)
Create and register test.
Test for pow constraint with shared variables
virtual void post(Gecode::Space &home, Gecode::FloatVarArray &x)
Post constraint on x.
PowXX(const std::string &s, const Gecode::FloatVal &d, unsigned int _n, Gecode::FloatNum st)
Create and register test.
virtual MaybeType solution(const Assignment &x) const
Test whether x is solution
Test for pow constraint where solution is ensured
PowXYSol(const std::string &s, const Gecode::FloatVal &d, unsigned int _n, Gecode::FloatNum st)
Create and register test.
virtual MaybeType solution(const Assignment &x) const
Test whether x is solution
virtual void post(Gecode::Space &home, Gecode::FloatVarArray &x)
Post constraint on x.
virtual bool extendAssignment(Assignment &x) const
Extend assignment x.
Test for pow constraint
virtual MaybeType solution(const Assignment &x) const
Test whether x is solution
PowXY(const std::string &s, const Gecode::FloatVal &d, unsigned int _n, Gecode::FloatNum st)
Create and register test.
virtual void post(Gecode::Space &home, Gecode::FloatVarArray &x)
Post constraint on x.
Test for squaring constraint with shared variables
virtual void post(Gecode::Space &home, Gecode::FloatVarArray &x)
Post constraint on x.
SqrXX(const std::string &s, const Gecode::FloatVal &d, Gecode::FloatNum st)
Create and register test.
virtual MaybeType solution(const Assignment &x) const
Test whether x is solution
Test for squaring constraint where solution is ensured
virtual void post(Gecode::Space &home, Gecode::FloatVarArray &x)
Post constraint on x.
SqrXYSol(const std::string &s, const Gecode::FloatVal &d, Gecode::FloatNum st)
Create and register test.
virtual bool extendAssignment(Assignment &x) const
Extend assignment x.
virtual MaybeType solution(const Assignment &x) const
Test whether x is solution
Test for squaring constraint
SqrXY(const std::string &s, const Gecode::FloatVal &d, Gecode::FloatNum st)
Create and register test.
virtual MaybeType solution(const Assignment &x) const
Test whether x is solution
virtual void post(Gecode::Space &home, Gecode::FloatVarArray &x)
Post constraint on x.
Test for square root constraint with shared variables
virtual void post(Gecode::Space &home, Gecode::FloatVarArray &x)
Post constraint on x.
SqrtXX(const std::string &s, const Gecode::FloatVal &d, Gecode::FloatNum st)
Create and register test.
virtual MaybeType solution(const Assignment &x) const
Test whether x is solution
Test for square root constraint where solution is ensured
virtual MaybeType solution(const Assignment &x) const
Test whether x is solution
virtual bool extendAssignment(Assignment &x) const
Extend assignment x.
SqrtXYSol(const std::string &s, const Gecode::FloatVal &d, Gecode::FloatNum st)
Create and register test.
virtual void post(Gecode::Space &home, Gecode::FloatVarArray &x)
Post constraint on x.
Test for square root constraint
virtual void post(Gecode::Space &home, Gecode::FloatVarArray &x)
Post constraint on x.
SqrtXY(const std::string &s, const Gecode::FloatVal &d, Gecode::FloatNum st)
Create and register test.
virtual MaybeType solution(const Assignment &x) const
Test whether x is solution
Base class for assignments
Definition float.hh:80
virtual void set(int i, const Gecode::FloatVal &val)=0
Set assignment to value val for variable i.
static MaybeType eq(Gecode::FloatVal x, Gecode::FloatVal y)
Whether x and y are equal.
Definition float.hpp:269
static MaybeType cmp(Gecode::FloatVal x, Gecode::FloatRelType r, Gecode::FloatVal y)
Compare x and y with respect to r.
Definition float.hpp:236
static std::string str(Gecode::FloatRelType frt)
Map float relation to string.
Definition float.hpp:195
bool flip(void)
Flip a coin and return true or false randomly.
Definition float.hpp:274
Gecode::FloatVal dom
Domain of variables.
Definition float.hh:250
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
@ FRT_EQ
Equality ( ).
Definition float.hh:1076
@ FRT_GQ
Greater or equal ( ).
Definition float.hh:1080
Space(void)
Default constructor.
Definition core.cpp:121
Space * clone(void) const
Clone space.
Definition core.hpp:3312
SpaceStatus status(StatusStatistics &stat)
Query space status.
Definition core.cpp:282
@ SS_FAILED
Space is failed
Definition core.hpp:1715
bool subset(const FloatVal &x, const FloatVal &y)
Definition val.hpp:507
Gecode toplevel namespace
void sqr(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 .
void div(Home home, FloatVar x0, FloatVar x1, FloatVar x2)
Post propagator for .
void mult(Home home, FloatVar x0, FloatVar x1, FloatVar x2)
Post propagator for .
void sqrt(Home home, FloatVar x0, FloatVar x1)
Post propagator for .
void max(Home home, FloatVar x0, FloatVar x1, FloatVar x2)
Post propagator for .
void pow(Home home, FloatVar x0, int n, FloatVar x1)
Post propagator for for .
void nroot(Home home, FloatVar x0, int n, FloatVar x1)
Post propagator for for .
Tests for arithmetic constraints
AbsXY abs_xy_b("B", b, step)
Div div_b("B", b, step)
SqrtXY sqrt_xy_b("B", b, step)
MinXYX min_xyx_b("B", b, step)
MultXYY mult_xyy_b("B", b, step)
AbsXY abs_xy_a("A", a, step)
PowXX pow_xx_b_3("B", b, 0, step)
MaxXYZ max_xyz_b("B", b, step)
MinXYY min_xyy_a("A", a, step)
MultXYY mult_xyy_c("C", c, step)
NRootXX nroot_xx_b_1("B", b, 2, step)
MaxXYZ max_xyz_c("C", c, step)
MinXXY min_xxy_c("C", c, step)
NRootXX nroot_xx_b_2("B", b, 3, step)
DivSol div_sol_a("A", a, step)
SqrtXYSol sqrt_xy_sol_a("A", a, step)
NRootXYSol nroot_xy_sol_c_3("C", c, 0, step)
SqrXYSol sqr_xy_sol_b("B", b, step)
AbsXX abs_xx_c("C", c, step)
PowXX pow_xx_b_2("B", b, 3, step)
Div div_c("C", c, step)
PowXYSol pow_xy_sol_b_1("B", b, 2, step)
SqrXY sqr_xy_b("B", b, step)
PowXX pow_xx_c_1("C", c, 2, step)
SqrtXYSol sqrt_xy_sol_c("C", c, step)
Gecode::FloatVal c(-8, 8)
PowXY pow_xy_b_2("B", b, 3, step)
MultXXY mult_xxy_c("C", c, step)
NRootXX nroot_xx_a_2("A", a, 3, step)
PowXYSol pow_xy_sol_c_3("C", c, 0, step)
NRootXYSol nroot_xy_sol_c_1("C", c, 2, step)
MinXYZ min_xyz_a("A", a, step)
NRootXYSol nroot_xy_sol_b_1("B", b, 2, step)
NRootXY nroot_xy_a_1("A", a, 2, step)
MaxXYX max_xyx_a("A", a, step)
MaxXYY max_xyy_a("A", a, step)
Test::Float::Arithmetic::MultZeroEndpoint mult_zero_endpoint
SqrtXX sqrt_xx_b("B", b, step)
SqrXX sqr_xx_c("C", c, step)
MinXYX min_xyx_a("A", a, step)
PowXX pow_xx_a_3("A", a, 0, step)
PowXY pow_xy_c_2("C", c, 3, step)
MultXYZ mult_xyz_b("B", b, step)
NRootXY nroot_xy_b_2("B", b, 3, step)
MultXYX mult_xyx_a("A", a, step)
MultXYZ mult_xyz_c("C", c, step)
MultXYZ mult_xyz_a("A", a, step)
MultXXX mult_xxx_c("C", c, step)
PowXYSol pow_xy_sol_a_1("A", a, 2, step)
Test::Float::Arithmetic::PositiveNRootBounds positive_nroot_bounds
MultXYZSol mult_xyz_sol_c("C", c, step)
NRootXY nroot_xy_b_3("B", b, 0, step)
MinXXX min_xxx_b("B", b, step)
MinXXY min_xxy_b("B", b, step)
NRootXY nroot_xy_c_1("C", c, 2, step)
MinXYY min_xyy_b("B", b, step)
MinXYY min_xyy_c("C", c, step)
NRootXX nroot_xx_c_3("C", c, 0, step)
NRootXY nroot_xy_c_2("C", c, 3, step)
MinXYX min_xyx_c("C", c, step)
SqrtXY sqrt_xy_c("C", c, step)
SqrXX sqr_xx_b("B", b, step)
SqrtXY sqrt_xy_a("A", a, step)
MaxXXY max_xxy_b("B", b, step)
PowXY pow_xy_b_3("B", b, 0, step)
NRootXX nroot_xx_a_3("A", a, 0, step)
SqrtXYSol sqrt_xy_sol_b("B", b, step)
Gecode::FloatVal b(9, 12)
MultXYX mult_xyx_b("B", b, step)
MaxXYZ max_xyz_a("A", a, step)
SqrXYSol sqr_xy_sol_a("A", a, step)
PowXYSol pow_xy_sol_b_2("B", b, 3, step)
NRootXYSol nroot_xy_sol_a_2("A", a, 3, step)
SqrXX sqr_xx_a("A", a, step)
PowXYSol pow_xy_sol_c_1("C", c, 2, step)
Test::Float::Arithmetic::PowConsistency pow_consistency
NRootXYSol nroot_xy_sol_b_3("B", b, 0, step)
MultXXYSol mult_xxy_sol_c("C", c, step)
MaxXYY max_xyy_b("B", b, step)
PowXY pow_xy_a_1("A", a, 2, step)
SqrtXX sqrt_xx_a("A", a, step)
MaxXXX max_xxx_c("C", c, step)
PowXY pow_xy_a_2("A", a, 3, step)
NRootXYSol nroot_xy_sol_b_2("B", b, 3, step)
Gecode::FloatVal a(-8, 5)
SqrXY sqr_xy_c("C", c, step)
MultXXYSol mult_xxy_sol_b("B", b, step)
DivSol div_sol_c("C", c, step)
PowXX pow_xx_a_2("A", a, 3, step)
DivSol div_sol_b("B", b, step)
PowXY pow_xy_c_3("C", c, 0, step)
NRootXYSol nroot_xy_sol_a_3("A", a, 0, step)
MaxXYX max_xyx_b("B", b, step)
MaxXXY max_xxy_c("C", c, step)
MaxXXX max_xxx_b("B", b, step)
PowXYSol pow_xy_sol_b_3("B", b, 0, step)
NRootXY nroot_xy_b_1("B", b, 2, step)
PowXYSol pow_xy_sol_a_2("A", a, 3, step)
MultXXY mult_xxy_b("B", b, step)
MinXXX min_xxx_c("C", c, step)
MultXYZSol mult_xyz_sol_b("B", b, step)
PowXY pow_xy_b_1("B", b, 2, step)
AbsXY abs_xy_c("C", c, step)
const Gecode::FloatNum step
MinXYZ min_xyz_b("B", b, step)
MultXYX mult_xyx_c("C", c, step)
MultXXX mult_xxx_a("A", a, step)
MinXYZ min_xyz_c("C", c, step)
NRootXX nroot_xx_b_3("B", b, 0, step)
MultXXYSol mult_xxy_sol_a("A", a, step)
MaxXYY max_xyy_c("C", c, step)
MinXXX min_xxx_a("A", a, step)
PowXY pow_xy_a_3("A", a, 0, step)
NRootXY nroot_xy_a_2("A", a, 3, step)
PowXX pow_xx_b_1("B", b, 2, step)
MultXXY mult_xxy_a("A", a, step)
AbsXX abs_xx_b("B", b, step)
NRootXYSol nroot_xy_sol_a_1("A", a, 2, step)
PowXX pow_xx_c_2("C", c, 3, step)
MinXXY min_xxy_a("A", a, step)
Div div_a("A", a, step)
MultXYZSol mult_xyz_sol_a("A", a, step)
MaxXYX max_xyx_c("C", c, step)
NRootXYSol nroot_xy_sol_c_2("C", c, 3, step)
PowXY pow_xy_c_1("C", c, 2, step)
PowXYSol pow_xy_sol_a_3("A", a, 0, step)
MultXXX mult_xxx_b("B", b, step)
NRootXX nroot_xx_a_1("A", a, 2, step)
SqrXY sqr_xy_a("A", a, step)
SqrXYSol sqr_xy_sol_c("C", c, step)
NRootXX nroot_xx_c_2("C", c, 3, step)
PowXX pow_xx_c_3("C", c, 0, step)
SqrtXX sqrt_xx_c("C", c, step)
PowXYSol pow_xy_sol_c_2("C", c, 3, step)
NRootXX nroot_xx_c_1("C", c, 2, step)
MaxXXY max_xxy_a("A", a, step)
AbsXX abs_xx_a("A", a, step)
MultXYY mult_xyy_a("A", a, step)
PowXX pow_xx_a_1("A", a, 2, step)
NRootXY nroot_xy_c_3("C", c, 0, step)
MaxXXX max_xxx_a("A", a, step)
NRootXY nroot_xy_a_3("A", a, 0, step)
Testing domain floats.
Definition float.cpp:43
@ EXTEND_ASSIGNMENT
Definition float.hh:64
@ CPLT_ASSIGNMENT
Definition float.hh:62
MaybeType
Type for comparisons and solutions.
Definition float.hh:51
General test support.
Definition afc.cpp:39
std::ostringstream olog
Stream used for logging.
Definition test.cpp:54