this repo has no description
1/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2/*
3 * Main authors:
4 * Christian Schulte <schulte@gecode.org>
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.org
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
43namespace Test { namespace Float {
44
45 /// %Tests for arithmetic constraints
46 namespace Arithmetic {
47
48 /**
49 * \defgroup TaskTestFloatArithmetic Arithmetic constraints
50 * \ingroup TaskTestFloat
51 */
52 //@{
53 /// %Test for multiplication constraint
54 class MultXYZ : public Test {
55 public:
56 /// Create and register test
57 MultXYZ(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st)
58 : Test("Arithmetic::Mult::XYZ::"+s,3,d,st,CPLT_ASSIGNMENT,false) {}
59 /// %Test whether \a x is solution
60 virtual MaybeType solution(const Assignment& x) const {
61 return eq(x[0] * x[1], x[2]);
62 }
63 /// Post constraint on \a x
64 virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
65 if (flip())
66 Gecode::mult(home, x[0], x[1], x[2]);
67 else
68 Gecode::rel(home, x[0] * x[1] == x[2]);
69 }
70 };
71
72 /// %Test for multiplication constraint when solution is ensured
73 class MultXYZSol : public Test {
74 public:
75 /// Create and register test
76 MultXYZSol(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st)
77 : Test("Arithmetic::Mult::XYZ::Sol::"+s,3,d,st,EXTEND_ASSIGNMENT,false) {}
78 /// %Test whether \a x is solution
79 virtual MaybeType solution(const Assignment& x) const {
80 return eq(x[0] * x[1], x[2]);
81 }
82 /// Extend assignment \a x
83 virtual bool extendAssignement(Assignment& x) const {
84 Gecode::FloatVal d = x[0]*x[1];
85 if (Gecode::Float::subset(d, dom)) {
86 x.set(2, d);
87 return true;
88 } else {
89 return false;
90 }
91 }
92 /// Post constraint on \a x
93 virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
94 Gecode::mult(home, x[0], x[1], x[2]);
95 }
96 };
97
98 /// %Test for multiplication constraint with shared variables
99 class MultXXY : public Test {
100 public:
101 /// Create and register test
102 MultXXY(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st)
103 : Test("Arithmetic::Mult::XXY::"+s,2,d,st,CPLT_ASSIGNMENT,false) {}
104 /// %Test whether \a x is solution
105 virtual MaybeType solution(const Assignment& x) const {
106 return eq(x[0] * x[0], x[1]);
107 }
108 /// Post constraint on \a x
109 virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
110 Gecode::mult(home, x[0], x[0], x[1]);
111 }
112 };
113
114 /// %Test for multiplication constraint with shared variables when solution is ensured
115 class MultXXYSol : public Test {
116 public:
117 /// Create and register test
118 MultXXYSol(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st)
119 : Test("Arithmetic::Mult::XXY::Sol::"+s,2,d,st,EXTEND_ASSIGNMENT,false) {}
120 /// %Test whether \a x is solution
121 virtual MaybeType solution(const Assignment& x) const {
122 return eq(x[0] * x[0], x[1]);
123 }
124 /// Extend assignment \a x
125 virtual bool extendAssignement(Assignment& x) const {
126 Gecode::FloatVal d = x[0]*x[0];
127 if (Gecode::Float::subset(d, dom)) {
128 x.set(1, d);
129 return true;
130 } else {
131 return false;
132 }
133 }
134 /// Post constraint on \a x
135 virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
136 Gecode::mult(home, x[0], x[0], x[1]);
137 }
138 };
139
140 /// %Test for multiplication constraint with shared variables
141 class MultXYX : public Test {
142 public:
143 /// Create and register test
144 MultXYX(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st)
145 : Test("Arithmetic::Mult::XYX::"+s,2,d,st,CPLT_ASSIGNMENT,false) {}
146 /// %Test whether \a x is solution
147 virtual MaybeType solution(const Assignment& x) const {
148 return eq(x[0] * x[1], x[0]);
149 }
150 /// Post constraint on \a x
151 virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
152 Gecode::mult(home, x[0], x[1], x[0]);
153 }
154 };
155
156 /// %Test for multiplication constraint with shared variables
157 class MultXYY : public Test {
158 public:
159 /// Create and register test
160 MultXYY(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st)
161 : Test("Arithmetic::Mult::XYY::"+s,2,d,st,CPLT_ASSIGNMENT,false) {}
162 /// %Test whether \a x is solution
163 virtual MaybeType solution(const Assignment& x) const {
164 return eq(x[0] * x[1], x[1]);
165 }
166 /// Post constraint on \a x
167 virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
168 Gecode::mult(home, x[0], x[1], x[1]);
169 }
170 };
171
172 /// %Test for multiplication constraint with shared variables
173 class MultXXX : public Test {
174 public:
175 /// Create and register test
176 MultXXX(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st)
177 : Test("Arithmetic::Mult::XXX::"+s,1,d,st,CPLT_ASSIGNMENT,false) {}
178 /// %Test whether \a x is solution
179 virtual MaybeType solution(const Assignment& x) const {
180 return eq(x[0] * x[0], x[0]);
181 }
182 /// Post constraint on \a x
183 virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
184 Gecode::mult(home, x[0], x[0], x[0]);
185 }
186 };
187
188 /// %Test for division constraint
189 class Div : public Test {
190 public:
191 /// Create and register test
192 Div(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st)
193 : Test("Arithmetic::Div::"+s,3,d,st,CPLT_ASSIGNMENT,false) {}
194 /// %Test whether \a x is solution
195 virtual MaybeType solution(const Assignment& x) const {
196 return eq(x[0] / x[1], x[2]);
197 }
198 /// Post constraint on \a x
199 virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
200 if (flip())
201 Gecode::div(home, x[0], x[1], x[2]);
202 else
203 Gecode::rel(home, x[0] / x[1] == x[2]);
204 }
205 };
206
207 /// %Test for division constraint when solution is ensured
208 class DivSol : public Test {
209 public:
210 /// Create and register test
211 DivSol(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st)
212 : Test("Arithmetic::Div::Sol::"+s,3,d,st,EXTEND_ASSIGNMENT,false) {}
213 /// %Test whether \a x is solution
214 virtual MaybeType solution(const Assignment& x) const {
215 return eq(x[0] / x[1], x[2]);
216 }
217 /// Extend assignment \a x
218 virtual bool extendAssignement(Assignment& x) const {
219 Gecode::FloatVal d = x[0]/x[1];
220 if (Gecode::Float::subset(d, dom)) {
221 x.set(2, d);
222 return true;
223 } else {
224 return false;
225 }
226 }
227 /// Post constraint on \a x
228 virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
229 Gecode::div(home, x[0], x[1], x[2]);
230 }
231 };
232
233 /// %Test for squaring constraint
234 class SqrXY : public Test {
235 public:
236 /// Create and register test
237 SqrXY(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st)
238 : Test("Arithmetic::Sqr::XY::"+s,2,d,st,CPLT_ASSIGNMENT,false) {}
239 /// %Test whether \a x is solution
240 virtual MaybeType solution(const Assignment& x) const {
241 return eq(x[0] * x[0], x[1]);
242 }
243 /// Post constraint on \a x
244 virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
245 if (flip())
246 Gecode::sqr(home, x[0], x[1]);
247 else
248 Gecode::rel(home, sqr(x[0]) == x[1]);
249 }
250 };
251
252 /// %Test for squaring constraint where solution is ensured
253 class SqrXYSol : public Test {
254 public:
255 /// Create and register test
256 SqrXYSol(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st)
257 : Test("Arithmetic::Sqr::XY::Sol::"+s,2,d,st,EXTEND_ASSIGNMENT,false) {}
258 /// %Test whether \a x is solution
259 virtual MaybeType solution(const Assignment& x) const {
260 return eq(x[0] * x[0], x[1]);
261 }
262 /// Extend assignment \a x
263 virtual bool extendAssignement(Assignment& x) const {
264 Gecode::FloatVal d = sqr(x[0]);
265 if (Gecode::Float::subset(d, dom)) {
266 x.set(1, d);
267 return true;
268 } else {
269 return false;
270 }
271 }
272 /// Post constraint on \a x
273 virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
274 Gecode::sqr(home, x[0], x[1]);
275 }
276 };
277
278 /// %Test for squaring constraint with shared variables
279 class SqrXX : public Test {
280 public:
281 /// Create and register test
282 SqrXX(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st)
283 : Test("Arithmetic::Sqr::XX::"+s,1,d,st,CPLT_ASSIGNMENT,false) {}
284 /// %Test whether \a x is solution
285 virtual MaybeType solution(const Assignment& x) const {
286 return eq(x[0] * x[0], x[0]);
287 }
288 /// Post constraint on \a x
289 virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
290 Gecode::sqr(home, x[0], x[0]);
291 }
292 };
293
294 /// %Test for square root constraint
295 class SqrtXY : public Test {
296 public:
297 /// Create and register test
298 SqrtXY(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st)
299 : Test("Arithmetic::Sqrt::XY::"+s,2,d,st,CPLT_ASSIGNMENT,false) {}
300 /// %Test whether \a x is solution
301 virtual MaybeType solution(const Assignment& x) const {
302 switch (cmp(x[0], Gecode::FRT_GQ, 0.0)) {
303 case MT_FALSE: return MT_FALSE;
304 case MT_MAYBE: return MT_MAYBE;
305 default:
306 return eq(sqrt(x[0]), x[1]);
307 }
308 }
309 /// Post constraint on \a x
310 virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
311 if (flip())
312 Gecode::sqrt(home, x[0], x[1]);
313 else
314 Gecode::rel(home, sqrt(x[0]) == x[1]);
315 }
316 };
317
318 /// %Test for square root constraint where solution is ensured
319 class SqrtXYSol : public Test {
320 public:
321 /// Create and register test
322 SqrtXYSol(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st)
323 : Test("Arithmetic::Sqrt::XY::Sol::"+s,2,d,st,EXTEND_ASSIGNMENT,false) {}
324 /// %Test whether \a x is solution
325 virtual MaybeType solution(const Assignment& x) const {
326 switch (cmp(x[0], Gecode::FRT_GQ, 0.0)) {
327 case MT_FALSE: return MT_FALSE;
328 case MT_MAYBE: return MT_MAYBE;
329 default:
330 return eq(sqrt(x[0]), x[1]);
331 }
332 }
333 /// Extend assignment \a x
334 virtual bool extendAssignement(Assignment& x) const {
335 Gecode::FloatVal d = sqrt(abs(x[0]));
336 if (Gecode::Float::subset(d, dom)) {
337 x.set(1, d);
338 return true;
339 } else {
340 return false;
341 }
342 }
343 /// Post constraint on \a x
344 virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
345 Gecode::sqrt(home, x[0], x[1]);
346 }
347 };
348
349 /// %Test for square root constraint with shared variables
350 class SqrtXX : public Test {
351 public:
352 /// Create and register test
353 SqrtXX(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st)
354 : Test("Arithmetic::Sqrt::XX::"+s,1,d,st,CPLT_ASSIGNMENT,false) {}
355 /// %Test whether \a x is solution
356 virtual MaybeType solution(const Assignment& x) const {
357 switch (cmp(x[0], Gecode::FRT_GQ, 0.0)) {
358 case MT_FALSE: return MT_FALSE;
359 case MT_MAYBE: return MT_MAYBE;
360 default:
361 return eq(sqrt(x[0]), x[0]);
362 }
363 }
364 /// Post constraint on \a x
365 virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
366 Gecode::sqrt(home, x[0], x[0]);
367 }
368 };
369
370 /// %Test for pow constraint
371 class PowXY : public Test {
372 unsigned int n;
373 public:
374 /// Create and register test
375 PowXY(const std::string& s, const Gecode::FloatVal& d, unsigned int _n, Gecode::FloatNum st)
376 : Test("Arithmetic::Pow::N::"+str(_n)+"::XY::"+s,2,d,st,CPLT_ASSIGNMENT,false), n(_n) {}
377 /// %Test whether \a x is solution
378 virtual MaybeType solution(const Assignment& x) const {
379 return eq(pow(x[0],n), x[1]);
380 }
381 /// Post constraint on \a x
382 virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
383 if (flip())
384 Gecode::pow(home, x[0], n, x[1]);
385 else
386 Gecode::rel(home, pow(x[0],n) == x[1]);
387 }
388 };
389
390 /// %Test for pow constraint where solution is ensured
391 class PowXYSol : public Test {
392 unsigned int n;
393 public:
394 /// Create and register test
395 PowXYSol(const std::string& s, const Gecode::FloatVal& d, unsigned int _n, Gecode::FloatNum st)
396 : Test("Arithmetic::Pow::N::"+str(_n)+"::XY::Sol::"+s,2,d,st,EXTEND_ASSIGNMENT,false), n(_n) {}
397 /// %Test whether \a x is solution
398 virtual MaybeType solution(const Assignment& x) const {
399 return eq(pow(x[0],n), x[1]);
400 }
401 /// Extend assignment \a x
402 virtual bool extendAssignement(Assignment& x) const {
403 Gecode::FloatVal d = pow(x[0],n);
404 if (Gecode::Float::subset(d, dom)) {
405 x.set(1, d);
406 return true;
407 } else {
408 return false;
409 }
410 }
411 /// Post constraint on \a x
412 virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
413 Gecode::pow(home, x[0], n, x[1]);
414 }
415 };
416
417 /// %Test for pow constraint with shared variables
418 class PowXX : public Test {
419 unsigned int n;
420 public:
421 /// Create and register test
422 PowXX(const std::string& s, const Gecode::FloatVal& d, unsigned int _n, Gecode::FloatNum st)
423 : Test("Arithmetic::Pow::N::"+str(_n)+"::XX::"+s,1,d,st,CPLT_ASSIGNMENT,false) {}
424 /// %Test whether \a x is solution
425 virtual MaybeType solution(const Assignment& x) const {
426 return eq(pow(x[0],n), x[0]);
427 }
428 /// Post constraint on \a x
429 virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
430 Gecode::pow(home, x[0], n, x[0]);
431 }
432 };
433
434 /// %Test for nroot constraint
435 class NRootXY : public Test {
436 unsigned int n;
437 public:
438 /// Create and register test
439 NRootXY(const std::string& s, const Gecode::FloatVal& d, unsigned int _n, Gecode::FloatNum st)
440 : Test("Arithmetic::NRoot::N::"+str(_n)+"::XY::"+s,2,d,st,CPLT_ASSIGNMENT,false), n(_n) {}
441 /// %Test whether \a x is solution
442 virtual MaybeType solution(const Assignment& x) const {
443 if ((n == 0) || (x[0].max() < 0.0))
444 return MT_FALSE;
445 return eq(nroot(x[0],n), x[1]);
446 }
447 /// Post constraint on \a x
448 virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
449 if (flip())
450 Gecode::nroot(home, x[0], n, x[1]);
451 else
452 Gecode::rel(home, nroot(x[0],n) == x[1]);
453 }
454 };
455
456 /// %Test for nroot constraint where solution is ensured
457 class NRootXYSol : public Test {
458 unsigned int n;
459 public:
460 /// Create and register test
461 NRootXYSol(const std::string& s, const Gecode::FloatVal& d, unsigned int _n, Gecode::FloatNum st)
462 : Test("Arithmetic::NRoot::N::"+str(_n)+"::XY::Sol::"+s,2,d,st,EXTEND_ASSIGNMENT,false), n(_n) {}
463 /// %Test whether \a x is solution
464 virtual MaybeType solution(const Assignment& x) const {
465 if ((n == 0) || (x[0].max() < 0.0))
466 return MT_FALSE;
467 return eq(nroot(x[0],n), x[1]);
468 }
469 /// Extend assignment \a x
470 virtual bool extendAssignement(Assignment& x) const {
471 if ((n == 0) || (x[0].max() < 0))
472 return false;
473 Gecode::FloatVal d = nroot(x[0],n);
474 if (Gecode::Float::subset(d, dom)) {
475 x.set(1, d);
476 return true;
477 } else {
478 return false;
479 }
480 }
481 /// Post constraint on \a x
482 virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
483 Gecode::nroot(home, x[0], n, x[1]);
484 }
485 };
486
487 /// %Test for nroot constraint with shared variables
488 class NRootXX : public Test {
489 unsigned int n;
490 public:
491 /// Create and register test
492 NRootXX(const std::string& s, const Gecode::FloatVal& d, unsigned int _n, Gecode::FloatNum st)
493 : Test("Arithmetic::NRoot::N::"+str(_n)+"::XX::"+s,1,d,st,CPLT_ASSIGNMENT,false) {}
494 /// %Test whether \a x is solution
495 virtual MaybeType solution(const Assignment& x) const {
496 if ((n == 0) || (x[0].max() < 0))
497 return MT_FALSE;
498 return eq(nroot(x[0],n), x[0]);
499 }
500 /// Post constraint on \a x
501 virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
502 Gecode::nroot(home, x[0], n, x[0]);
503 }
504 };
505
506 /// %Test for absolute value constraint
507 class AbsXY : public Test {
508 public:
509 /// Create and register test
510 AbsXY(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st)
511 : Test("Arithmetic::Abs::XY::"+s,2,d,st,CPLT_ASSIGNMENT,false) {}
512 /// %Test whether \a x is solution
513 virtual MaybeType solution(const Assignment& x) const {
514 return eq(abs(x[0]), x[1]);
515 }
516 /// Post constraint on \a x
517 virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
518 if (flip())
519 Gecode::abs(home, x[0], x[1]);
520 else
521 Gecode::rel(home, abs(x[0]) == x[1]);
522 }
523 };
524
525 /// %Test for absolute value constraint with shared variables
526 class AbsXX : public Test {
527 public:
528 /// Create and register test
529 AbsXX(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st)
530 : Test("Arithmetic::Abs::XX::"+s,1,d,st,CPLT_ASSIGNMENT,false) {}
531 /// %Test whether \a x is solution
532 virtual MaybeType solution(const Assignment& x) const {
533 return eq(abs(x[0]), x[0]);
534 }
535 /// Post constraint on \a x
536 virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
537 Gecode::abs(home, x[0], x[0]);
538 }
539 };
540
541 /// %Test for binary minimum constraint
542 class MinXYZ : public Test {
543 public:
544 /// Create and register test
545 MinXYZ(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st)
546 : Test("Arithmetic::Min::Bin::XYZ::"+s,3,d,st,CPLT_ASSIGNMENT,false) {}
547 /// %Test whether \a x is solution
548 virtual MaybeType solution(const Assignment& x) const {
549 return eq(min(x[0],x[1]), x[2]);
550 }
551 /// Post constraint on \a x
552 virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
553 if (flip())
554 Gecode::min(home, x[0], x[1], x[2]);
555 else
556 Gecode::rel(home, min(x[0],x[1]) == x[2]);
557 }
558 };
559
560 /// %Test for binary minimum constraint with shared variables
561 class MinXXY : public Test {
562 public:
563 /// Create and register test
564 MinXXY(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st)
565 : Test("Arithmetic::Min::Bin::XXY::"+s,2,d,st,CPLT_ASSIGNMENT,false) {}
566 /// %Test whether \a x is solution
567 virtual MaybeType solution(const Assignment& x) const {
568 return eq(min(x[0],x[0]), x[1]);
569 }
570 /// Post constraint on \a x
571 virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
572 Gecode::min(home, x[0], x[0], x[1]);
573 }
574 };
575
576 /// %Test for binary minimum constraint with shared variables
577 class MinXYX : public Test {
578 public:
579 /// Create and register test
580 MinXYX(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st)
581 : Test("Arithmetic::Min::Bin::XYX::"+s,2,d,st,CPLT_ASSIGNMENT,false) {}
582 /// %Test whether \a x is solution
583 virtual MaybeType solution(const Assignment& x) const {
584 return eq(min(x[0],x[1]), x[0]);
585 }
586 /// Post constraint on \a x
587 virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
588 Gecode::min(home, x[0], x[1], x[0]);
589 }
590 };
591
592 /// %Test for binary minimum constraint with shared variables
593 class MinXYY : public Test {
594 public:
595 /// Create and register test
596 MinXYY(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st)
597 : Test("Arithmetic::Min::Bin::XYY::"+s,2,d,st,CPLT_ASSIGNMENT,false) {}
598 /// %Test whether \a x is solution
599 virtual MaybeType solution(const Assignment& x) const {
600 return eq(min(x[0],x[1]), x[1]);
601 }
602 /// Post constraint on \a x
603 virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
604 Gecode::min(home, x[0], x[1], x[1]);
605 }
606 };
607
608 /// %Test for binary minimum constraint with shared variables
609 class MinXXX : public Test {
610 public:
611 /// Create and register test
612 MinXXX(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st)
613 : Test("Arithmetic::Min::Bin::XXX::"+s,1,d,st,CPLT_ASSIGNMENT,false) {}
614 /// %Test whether \a x is solution
615 virtual MaybeType solution(const Assignment& x) const {
616 return eq(min(x[0],x[0]), x[0]);
617 }
618 /// Post constraint on \a x
619 virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
620 Gecode::min(home, x[0], x[0], x[0]);
621 }
622 };
623
624 /// %Test for binary maximum constraint
625 class MaxXYZ : public Test {
626 public:
627 /// Create and register test
628 MaxXYZ(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st)
629 : Test("Arithmetic::Max::Bin::XYZ::"+s,3,d,st,CPLT_ASSIGNMENT,false) {}
630 /// %Test whether \a x is solution
631 virtual MaybeType solution(const Assignment& x) const {
632 return eq(max(x[0],x[1]), x[2]);
633 }
634 /// Post constraint on \a x
635 virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
636 if (flip())
637 Gecode::max(home, x[0], x[1], x[2]);
638 else
639 Gecode::rel(home, max(x[0], x[1]) == x[2]);
640 }
641 };
642
643 /// %Test for binary maximum constraint with shared variables
644 class MaxXXY : public Test {
645 public:
646 /// Create and register test
647 MaxXXY(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st)
648 : Test("Arithmetic::Max::Bin::XXY::"+s,2,d,st,CPLT_ASSIGNMENT,false) {}
649 /// %Test whether \a x is solution
650 virtual MaybeType solution(const Assignment& x) const {
651 return eq(max(x[0],x[0]), x[1]);
652 }
653 /// Post constraint on \a x
654 virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
655 Gecode::max(home, x[0], x[0], x[1]);
656 }
657 };
658
659 /// %Test for binary maximum constraint with shared variables
660 class MaxXYX : public Test {
661 public:
662 /// Create and register test
663 MaxXYX(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st)
664 : Test("Arithmetic::Max::Bin::XYX::"+s,2,d,st,CPLT_ASSIGNMENT,false) {}
665 /// %Test whether \a x is solution
666 virtual MaybeType solution(const Assignment& x) const {
667 return eq(max(x[0],x[1]), x[0]);
668 }
669 /// Post constraint on \a x
670 virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
671 Gecode::max(home, x[0], x[1], x[0]);
672 }
673 };
674
675 /// %Test for binary maximum constraint with shared variables
676 class MaxXYY : public Test {
677 public:
678 /// Create and register test
679 MaxXYY(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st)
680 : Test("Arithmetic::Max::Bin::XYY::"+s,2,d,st,CPLT_ASSIGNMENT,false) {}
681 /// %Test whether \a x is solution
682 virtual MaybeType solution(const Assignment& x) const {
683 return eq(max(x[0],x[1]), x[1]);
684 }
685 /// Post constraint on \a x
686 virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
687 Gecode::max(home, x[0], x[1], x[1]);
688 }
689 };
690
691 /// %Test for binary maximum constraint with shared variables
692 class MaxXXX : public Test {
693 public:
694 /// Create and register test
695 MaxXXX(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st)
696 : Test("Arithmetic::Max::Bin::XXX::"+s,1,d,st,CPLT_ASSIGNMENT,false) {}
697 /// %Test whether \a x is solution
698 virtual MaybeType solution(const Assignment& x) const {
699 return eq(max(x[0],x[0]), x[0]);
700 }
701 /// Post constraint on \a x
702 virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
703 Gecode::max(home, x[0], x[0], x[0]);
704 }
705 };
706
707 /// %Test for n-ary minimmum constraint
708 class MinNary : public Test {
709 public:
710 /// Create and register test
711 MinNary(void)
712 : Test("Arithmetic::Min::Nary",4,-4,4,0.5,CPLT_ASSIGNMENT,false) {}
713 /// %Test whether \a x is solution
714 virtual MaybeType solution(const Assignment& x) const {
715 return eq(min(min(x[0],x[1]),x[2]), x[3]);
716 }
717 /// Post constraint on \a x
718 virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
719 Gecode::FloatVarArgs m(3);
720 m[0]=x[0]; m[1]=x[1]; m[2]=x[2];
721 if (flip())
722 Gecode::min(home, m, x[3]);
723 else
724 Gecode::rel(home, min(m) == x[3]);
725 }
726 };
727
728 /// %Test for n-ary minimmum constraint with shared variables
729 class MinNaryShared : public Test {
730 public:
731 /// Create and register test
732 MinNaryShared(void)
733 : Test("Arithmetic::Min::Nary::Shared",3,-4,4,0.5,CPLT_ASSIGNMENT,false) {}
734 /// %Test whether \a x is solution
735 virtual MaybeType solution(const Assignment& x) const {
736 return eq(min(min(x[0],x[1]),x[2]), x[1]);
737 }
738 /// Post constraint on \a x
739 virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
740 Gecode::FloatVarArgs m(3);
741 m[0]=x[0]; m[1]=x[1]; m[2]=x[2];
742 Gecode::min(home, m, x[1]);
743 }
744 };
745
746 /// %Test for n-ary maximum constraint
747 class MaxNary : public Test {
748 public:
749 /// Create and register test
750 MaxNary(void)
751 : Test("Arithmetic::Max::Nary",4,-4,4,0.5,CPLT_ASSIGNMENT,false) {}
752 /// %Test whether \a x is solution
753 virtual MaybeType solution(const Assignment& x) const {
754 return eq(max(max(x[0],x[1]),x[2]), x[3]);
755 }
756 /// Post constraint on \a x
757 virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
758 Gecode::FloatVarArgs m(3);
759 m[0]=x[0]; m[1]=x[1]; m[2]=x[2];
760 if (flip())
761 Gecode::max(home, m, x[3]);
762 else
763 Gecode::rel(home, max(m) == x[3]);
764 }
765 };
766
767 /// %Test for n-ary maximum constraint with shared variables
768 class MaxNaryShared : public Test {
769 public:
770 /// Create and register test
771 MaxNaryShared(void)
772 : Test("Arithmetic::Max::Nary::Shared",3,-4,4,0.5,CPLT_ASSIGNMENT,false) {}
773 /// %Test whether \a x is solution
774 virtual MaybeType solution(const Assignment& x) const {
775 return eq(max(max(x[0],x[1]),x[2]), x[1]);
776 }
777 /// Post constraint on \a x
778 virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
779 Gecode::FloatVarArgs m(3);
780 m[0]=x[0]; m[1]=x[1]; m[2]=x[2];
781 Gecode::max(home, m, x[1]);
782 }
783 };
784
785 const Gecode::FloatNum step = 0.15;
786 Gecode::FloatVal a(-8,5);
787 Gecode::FloatVal b(9,12);
788 Gecode::FloatVal c(-8,8);
789
790 MultXXY mult_xxy_a("A",a,step);
791 MultXXY mult_xxy_b("B",b,step);
792 MultXXY mult_xxy_c("C",c,step);
793
794 MultXXYSol mult_xxy_sol_a("A",a,step);
795 MultXXYSol mult_xxy_sol_b("B",b,step);
796 MultXXYSol mult_xxy_sol_c("C",c,step);
797
798 MultXYX mult_xyx_a("A",a,step);
799 MultXYX mult_xyx_b("B",b,step);
800 MultXYX mult_xyx_c("C",c,step);
801
802 MultXYY mult_xyy_a("A",a,step);
803 MultXYY mult_xyy_b("B",b,step);
804 MultXYY mult_xyy_c("C",c,step);
805
806 MultXXX mult_xxx_a("A",a,step);
807 MultXXX mult_xxx_b("B",b,step);
808 MultXXX mult_xxx_c("C",c,step);
809
810 MultXYZ mult_xyz_a("A",a,step);
811 MultXYZ mult_xyz_b("B",b,step);
812 MultXYZ mult_xyz_c("C",c,step);
813
814 MultXYZSol mult_xyz_sol_a("A",a,step);
815 MultXYZSol mult_xyz_sol_b("B",b,step);
816 MultXYZSol mult_xyz_sol_c("C",c,step);
817
818 Div div_a("A",a,step);
819 Div div_b("B",b,step);
820 Div div_c("C",c,step);
821
822 DivSol div_sol_a("A",a,step);
823 DivSol div_sol_b("B",b,step);
824 DivSol div_sol_c("C",c,step);
825
826 SqrXY sqr_xy_a("A",a,step);
827 SqrXY sqr_xy_b("B",b,step);
828 SqrXY sqr_xy_c("C",c,step);
829
830 SqrXYSol sqr_xy_sol_a("A",a,step);
831 SqrXYSol sqr_xy_sol_b("B",b,step);
832 SqrXYSol sqr_xy_sol_c("C",c,step);
833
834 SqrXX sqr_xx_a("A",a,step);
835 SqrXX sqr_xx_b("B",b,step);
836 SqrXX sqr_xx_c("C",c,step);
837
838 SqrtXY sqrt_xy_a("A",a,step);
839 SqrtXY sqrt_xy_b("B",b,step);
840 SqrtXY sqrt_xy_c("C",c,step);
841
842 SqrtXYSol sqrt_xy_sol_a("A",a,step);
843 SqrtXYSol sqrt_xy_sol_b("B",b,step);
844 SqrtXYSol sqrt_xy_sol_c("C",c,step);
845
846 SqrtXX sqrt_xx_a("A",a,step);
847 SqrtXX sqrt_xx_b("B",b,step);
848 SqrtXX sqrt_xx_c("C",c,step);
849
850 PowXY pow_xy_a_1("A",a,2,step);
851 PowXY pow_xy_b_1("B",b,2,step);
852 PowXY pow_xy_c_1("C",c,2,step);
853
854 PowXYSol pow_xy_sol_a_1("A",a,2,step);
855 PowXYSol pow_xy_sol_b_1("B",b,2,step);
856 PowXYSol pow_xy_sol_c_1("C",c,2,step);
857
858 PowXX pow_xx_a_1("A",a,2,step);
859 PowXX pow_xx_b_1("B",b,2,step);
860 PowXX pow_xx_c_1("C",c,2,step);
861
862 PowXY pow_xy_a_2("A",a,3,step);
863 PowXY pow_xy_b_2("B",b,3,step);
864 PowXY pow_xy_c_2("C",c,3,step);
865
866 PowXYSol pow_xy_sol_a_2("A",a,3,step);
867 PowXYSol pow_xy_sol_b_2("B",b,3,step);
868 PowXYSol pow_xy_sol_c_2("C",c,3,step);
869
870 PowXX pow_xx_a_2("A",a,3,step);
871 PowXX pow_xx_b_2("B",b,3,step);
872 PowXX pow_xx_c_2("C",c,3,step);
873
874 PowXY pow_xy_a_3("A",a,0,step);
875 PowXY pow_xy_b_3("B",b,0,step);
876 PowXY pow_xy_c_3("C",c,0,step);
877
878 PowXYSol pow_xy_sol_a_3("A",a,0,step);
879 PowXYSol pow_xy_sol_b_3("B",b,0,step);
880 PowXYSol pow_xy_sol_c_3("C",c,0,step);
881
882 PowXX pow_xx_a_3("A",a,0,step);
883 PowXX pow_xx_b_3("B",b,0,step);
884 PowXX pow_xx_c_3("C",c,0,step);
885
886 NRootXY nroot_xy_a_1("A",a,2,step);
887 NRootXY nroot_xy_b_1("B",b,2,step);
888 NRootXY nroot_xy_c_1("C",c,2,step);
889
890 NRootXYSol nroot_xy_sol_a_1("A",a,2,step);
891 NRootXYSol nroot_xy_sol_b_1("B",b,2,step);
892 NRootXYSol nroot_xy_sol_c_1("C",c,2,step);
893
894 NRootXX nroot_xx_a_1("A",a,2,step);
895 NRootXX nroot_xx_b_1("B",b,2,step);
896 NRootXX nroot_xx_c_1("C",c,2,step);
897
898 NRootXY nroot_xy_a_2("A",a,3,step);
899 NRootXY nroot_xy_b_2("B",b,3,step);
900 NRootXY nroot_xy_c_2("C",c,3,step);
901
902 NRootXYSol nroot_xy_sol_a_2("A",a,3,step);
903 NRootXYSol nroot_xy_sol_b_2("B",b,3,step);
904 NRootXYSol nroot_xy_sol_c_2("C",c,3,step);
905
906 NRootXX nroot_xx_a_2("A",a,3,step);
907 NRootXX nroot_xx_b_2("B",b,3,step);
908 NRootXX nroot_xx_c_2("C",c,3,step);
909
910 NRootXY nroot_xy_a_3("A",a,0,step);
911 NRootXY nroot_xy_b_3("B",b,0,step);
912 NRootXY nroot_xy_c_3("C",c,0,step);
913
914 NRootXYSol nroot_xy_sol_a_3("A",a,0,step);
915 NRootXYSol nroot_xy_sol_b_3("B",b,0,step);
916 NRootXYSol nroot_xy_sol_c_3("C",c,0,step);
917
918 NRootXX nroot_xx_a_3("A",a,0,step);
919 NRootXX nroot_xx_b_3("B",b,0,step);
920 NRootXX nroot_xx_c_3("C",c,0,step);
921
922 AbsXY abs_xy_a("A",a,step);
923 AbsXY abs_xy_b("B",b,step);
924 AbsXY abs_xy_c("C",c,step);
925
926 AbsXX abs_xx_a("A",a,step);
927 AbsXX abs_xx_b("B",b,step);
928 AbsXX abs_xx_c("C",c,step);
929
930 MinXYZ min_xyz_a("A",a,step);
931 MinXYZ min_xyz_b("B",b,step);
932 MinXYZ min_xyz_c("C",c,step);
933
934 MinXXY min_xxy_a("A",a,step);
935 MinXXY min_xxy_b("B",b,step);
936 MinXXY min_xxy_c("C",c,step);
937
938 MinXYX min_xyx_a("A",a,step);
939 MinXYX min_xyx_b("B",b,step);
940 MinXYX min_xyx_c("C",c,step);
941
942 MinXYY min_xyy_a("A",a,step);
943 MinXYY min_xyy_b("B",b,step);
944 MinXYY min_xyy_c("C",c,step);
945
946 MinXXX min_xxx_a("A",a,step);
947 MinXXX min_xxx_b("B",b,step);
948 MinXXX min_xxx_c("C",c,step);
949
950 MaxXYZ max_xyz_a("A",a,step);
951 MaxXYZ max_xyz_b("B",b,step);
952 MaxXYZ max_xyz_c("C",c,step);
953
954 MaxXXY max_xxy_a("A",a,step);
955 MaxXXY max_xxy_b("B",b,step);
956 MaxXXY max_xxy_c("C",c,step);
957
958 MaxXYX max_xyx_a("A",a,step);
959 MaxXYX max_xyx_b("B",b,step);
960 MaxXYX max_xyx_c("C",c,step);
961
962 MaxXYY max_xyy_a("A",a,step);
963 MaxXYY max_xyy_b("B",b,step);
964 MaxXYY max_xyy_c("C",c,step);
965
966 MaxXXX max_xxx_a("A",a,step);
967 MaxXXX max_xxx_b("B",b,step);
968 MaxXXX max_xxx_c("C",c,step);
969
970 MinNary min_nary;
971 MinNaryShared min_s_nary;
972 MaxNary max_nary;
973 MaxNaryShared max_s_nary;
974 //@}
975
976 }
977}}
978
979// STATISTICS: test-float