Generated on Thu Jan 16 2025 00:00:00 for Gecode by doxygen 1.14.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.org>
5 *
6 * Copyright:
7 * Christian Schulte, 2005
8 *
9 * This file is part of Gecode, the generic constraint
10 * development environment:
11 * http://www.gecode.org
12 *
13 * Permission is hereby granted, free of charge, to any person obtaining
14 * a copy of this software and associated documentation files (the
15 * "Software"), to deal in the Software without restriction, including
16 * without limitation the rights to use, copy, modify, merge, publish,
17 * distribute, sublicense, and/or sell copies of the Software, and to
18 * permit persons to whom the Software is furnished to do so, subject to
19 * the following conditions:
20 *
21 * The above copyright notice and this permission notice shall be
22 * included in all copies or substantial portions of the Software.
23 *
24 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
28 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
29 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
30 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 *
32 */
33
34#include "test/int.hh"
35
36#include <cmath>
37#include <algorithm>
38
39#include <gecode/minimodel.hh>
40
41namespace Test { namespace Int {
42
44 namespace Arithmetic {
45
51
52 class MultXYZ : public Test {
53 public:
55 MultXYZ(const std::string& s, const Gecode::IntSet& d,
57 : Test("Arithmetic::Mult::XYZ::"+str(ipl)+"::"+s,3,d,false,ipl) {}
58
59 virtual bool solution(const Assignment& x) const {
60 double d0 = static_cast<double>(x[0]);
61 double d1 = static_cast<double>(x[1]);
62 double d2 = static_cast<double>(x[2]);
63 return d0*d1 == d2;
64 }
65
66 virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
67 Gecode::mult(home, x[0], x[1], x[2], ipl);
68 }
69 };
70
72 class MultXXY : public Test {
73 public:
75 MultXXY(const std::string& s, const Gecode::IntSet& d,
77 : Test("Arithmetic::Mult::XXY::"+str(ipl)+"::"+s,2,d,false,ipl) {}
78
79 virtual bool solution(const Assignment& x) const {
80 double d0 = static_cast<double>(x[0]);
81 double d1 = static_cast<double>(x[0]);
82 double d2 = static_cast<double>(x[1]);
83 return d0*d1 == d2;
84 }
85
86 virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
87 Gecode::mult(home, x[0], x[0], x[1], ipl);
88 }
89 };
90
92 class MultXYX : public Test {
93 public:
95 MultXYX(const std::string& s, const Gecode::IntSet& d,
97 : Test("Arithmetic::Mult::XYX::"+str(ipl)+"::"+s,2,d,false,ipl) {}
98
99 virtual bool solution(const Assignment& x) const {
100 double d0 = static_cast<double>(x[0]);
101 double d1 = static_cast<double>(x[1]);
102 double d2 = static_cast<double>(x[0]);
103 return d0*d1 == d2;
104 }
105
106 virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
107 Gecode::mult(home, x[0], x[1], x[0], ipl);
108 }
109 };
110
112 class MultXYY : public Test {
113 public:
115 MultXYY(const std::string& s, const Gecode::IntSet& d,
117 : Test("Arithmetic::Mult::XYY::"+str(ipl)+"::"+s,2,d,false,ipl) {}
118
119 virtual bool solution(const Assignment& x) const {
120 double d0 = static_cast<double>(x[0]);
121 double d1 = static_cast<double>(x[1]);
122 double d2 = static_cast<double>(x[1]);
123 return d0*d1 == d2;
124 }
125
126 virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
127 Gecode::mult(home, x[0], x[1], x[1], ipl);
128 }
129 };
130
132 class MultXXX : public Test {
133 public:
135 MultXXX(const std::string& s, const Gecode::IntSet& d,
137 : Test("Arithmetic::Mult::XXX::"+str(ipl)+"::"+s,1,d,false,ipl) {}
138
139 virtual bool solution(const Assignment& x) const {
140 double d0 = static_cast<double>(x[0]);
141 double d1 = static_cast<double>(x[0]);
142 double d2 = static_cast<double>(x[0]);
143 return d0*d1 == d2;
144 }
145
146 virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
147 Gecode::mult(home, x[0], x[0], x[0], ipl);
148 }
149 };
150
152 class SqrXY : public Test {
153 public:
155 SqrXY(const std::string& s, const Gecode::IntSet& d,
157 : Test("Arithmetic::Sqr::XY::"+str(ipl)+"::"+s,2,d,false,ipl) {}
158
159 virtual bool solution(const Assignment& x) const {
160 double d0 = static_cast<double>(x[0]);
161 double d1 = static_cast<double>(x[1]);
162 return d0*d0 == d1;
163 }
164
165 virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
166 Gecode::sqr(home, x[0], x[1], ipl);
167 }
168 };
169
171 class SqrXX : public Test {
172 public:
174 SqrXX(const std::string& s, const Gecode::IntSet& d,
176 : Test("Arithmetic::Sqr::XX::"+str(ipl)+"::"+s,1,d,false,ipl) {}
177
178 virtual bool solution(const Assignment& x) const {
179 double d0 = static_cast<double>(x[0]);
180 return d0*d0 == d0;
181 }
182
183 virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
184 Gecode::sqr(home, x[0], x[0], ipl);
185 }
186 };
187
189 class SqrtXY : public Test {
190 public:
192 SqrtXY(const std::string& s, const Gecode::IntSet& d,
194 : Test("Arithmetic::Sqrt::XY::"+str(ipl)+"::"+s,2,d,false,ipl) {}
195
196 virtual bool solution(const Assignment& x) const {
197 double d0 = static_cast<double>(x[0]);
198 double d1 = static_cast<double>(x[1]);
199 return (d0 >= 0) && (d0 >= d1*d1) && (d0 < (d1+1)*(d1+1));
200 }
201
202 virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
203 Gecode::sqrt(home, x[0], x[1], ipl);
204 }
205 };
206
208 class SqrtXX : public Test {
209 public:
211 SqrtXX(const std::string& s, const Gecode::IntSet& d,
213 : Test("Arithmetic::Sqrt::XX::"+str(ipl)+"::"+s,1,d,false,ipl) {}
214
215 virtual bool solution(const Assignment& x) const {
216 double d0 = static_cast<double>(x[0]);
217 return (d0 >= 0) && (d0 >= d0*d0) && (d0 < (d0+1)*(d0+1));
218 }
219
220 virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
221 Gecode::sqrt(home, x[0], x[0], ipl);
222 }
223 };
224
226 class PowXY : public Test {
227 protected:
229 int n;
230 public:
232 PowXY(const std::string& s, int n0, const Gecode::IntSet& d,
234 : Test("Arithmetic::Pow::XY::"+str(n0)+"::"+str(ipl)+"::"+s,
235 2,d,false,ipl), n(n0) {}
236
237 virtual bool solution(const Assignment& x) const {
238 long long int p = 1;
239 for (int i=0; i<n; i++) {
240 p *= x[0];
241 if ((p < Gecode::Int::Limits::min) ||
243 return false;
244 }
245 return p == x[1];
246 }
247
248 virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
249 using namespace Gecode;
250 if (n > 4)
251 pow(home, x[0], n, x[1], ipl);
252 else
253 rel(home, expr(home, pow(x[0],n), ipl), IRT_EQ, x[1], ipl);
254 }
255 };
256
258 class PowXX : public Test {
259 protected:
261 int n;
262 public:
264 PowXX(const std::string& s, int n0, const Gecode::IntSet& d,
266 : Test("Arithmetic::Pow::XX::"+str(n0)+"::"+str(ipl)+"::"+s,
267 1,d,false,ipl), n(n0) {}
268
269 virtual bool solution(const Assignment& x) const {
270 long long int p = 1;
271 for (int i=0; i<n; i++) {
272 p *= x[0];
273 if ((p < Gecode::Int::Limits::min) ||
275 return false;
276 }
277 return p == x[0];
278 }
279
280 virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
281 Gecode::pow(home, x[0], n, x[0], ipl);
282 }
283 };
284
285 bool powgr(int n, long long int r, int x) {
286 assert(r >= 0);
287 long long int y = r;
288 long long int p = 1;
289 do {
290 p *= y; n--;
291 if (p > x)
292 return true;
293 } while (n > 0);
294 return false;
295 }
296
297 int fnroot(int n, int x) {
298 if (x < 2)
299 return x;
300 /*
301 * We look for l such that: l^n <= x < (l+1)^n
302 */
303 long long int l = 1;
304 long long int u = x;
305 do {
306 long long int m = (l + u) >> 1;
307 if (powgr(n,m,x)) u=m; else l=m;
308 } while (l+1 < u);
309 return static_cast<int>(l);
310 }
311
312 bool powle(int n, long long int r, int x) {
313 assert(r >= 0);
314 long long int y = r;
315 long long int p = 1;
316 do {
317 p *= y; n--;
318 if (p >= x)
319 return false;
320 } while (n > 0);
321 assert(y < x);
322 return true;
323 }
324
325 int cnroot(int n, int x) {
326 if (x < 2)
327 return x;
328 /*
329 * We look for u such that: (u-1)^n < x <= u^n
330 */
331 long long int l = 1;
332 long long int u = x;
333 do {
334 long long int m = (l + u) >> 1;
335 if (powle(n,m,x)) l=m; else u=m;
336 } while (l+1 < u);
337 return static_cast<int>(u);
338 }
339
341 class NrootXY : public Test {
342 protected:
344 int n;
346 public:
348 NrootXY(const std::string& s, int n0, const Gecode::IntSet& d,
350 : Test("Arithmetic::Nroot::XY::"+str(n0)+"::"+str(ipl)+"::"+s,
351 2,d,false,ipl), n(n0) {}
352
353 virtual bool solution(const Assignment& x) const {
354 if (n == 1)
355 return x[0] == x[1];
356 if ((n % 2 == 0) && ((x[0] < 0) || (x[1] < 0)))
357 return false;
358 int r = (x[0] < 0) ? -cnroot(n,-x[0]) : fnroot(n,x[0]);
359 return r == x[1];
360 }
361
362 virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
363 using namespace Gecode;
364 if (n > 4)
365 nroot(home, x[0], n, x[1], ipl);
366 else
367 rel(home, expr(home, nroot(x[0],n), ipl), IRT_EQ, x[1], ipl);
368 }
369 };
370
372 class NrootXX : public Test {
373 protected:
375 int n;
376 public:
378 NrootXX(const std::string& s, int n0, const Gecode::IntSet& d,
380 : Test("Arithmetic::Nroot::XX::"+str(n0)+"::"+str(ipl)+"::"+s,
381 1,d,false,ipl), n(n0) {}
382
383 virtual bool solution(const Assignment& x) const {
384 if (n == 1)
385 return true;
386 if (n % 2 == 0) {
387 return (x[0] >= 0) && (x[0] <= 1);
388 } else {
389 return (x[0] >= -2) && (x[0] <= 1);
390 }
391 }
392
393 virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
394 Gecode::nroot(home, x[0], n, x[0], ipl);
395 }
396 };
397
399 class DivMod : public Test {
400 private:
402 static int abs(int a) { return a<0 ? -a:a; }
404 static int sgn(int a) { return a<0 ? -1:1; }
405 public:
407 DivMod(const std::string& s, const Gecode::IntSet& d)
408 : Test("Arithmetic::DivMod::"+s,4,d) {}
409
410 virtual bool solution(const Assignment& x) const {
411 return x[0] == x[1]*x[2]+x[3] &&
412 abs(x[3]) < abs(x[1]) &&
413 (x[3] == 0 || sgn(x[3]) == sgn(x[0]));
414 }
415
416 virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
417 Gecode::divmod(home, x[0], x[1], x[2], x[3]);
418 }
419 };
420
422 class Div : public Test {
423 public:
425 Div(const std::string& s, const Gecode::IntSet& d)
426 : Test("Arithmetic::Div::"+s,3,d) {}
427
428 virtual bool solution(const Assignment& x) const {
429 if (x[1] == 0)
430 return false;
431 int divsign = (x[0] / x[1] < 0) ? -1 : 1;
432 int divresult =
433 divsign *
434 static_cast<int>(floor(static_cast<double>(std::abs(x[0]))/
435 static_cast<double>(std::abs(x[1]))));
436 return x[2] == divresult;
437 }
438
439 virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
440 Gecode::div(home, x[0], x[1], x[2]);
441 }
442 };
443
445 class Mod : public Test {
446 public:
448 Mod(const std::string& s, const Gecode::IntSet& d)
449 : Test("Arithmetic::Mod::"+s,3,d) {}
450
451 virtual bool solution(const Assignment& x) const {
452 if (x[1] == 0)
453 return false;
454 int divsign = (x[0] / x[1] < 0) ? -1 : 1;
455 int divresult =
456 divsign *
457 static_cast<int>(floor(static_cast<double>(std::abs(x[0]))/
458 static_cast<double>(std::abs(x[1]))));
459 return x[0] == x[1]*divresult+x[2];
460 }
461
462 virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
463 Gecode::mod(home, x[0], x[1], x[2]);
464 }
465 };
466
468 class AbsXY : public Test {
469 public:
471 AbsXY(const std::string& s, const Gecode::IntSet& d,
473 : Test("Arithmetic::Abs::XY::"+str(ipl)+"::"+s,2,d,false,ipl) {}
474
475 virtual bool solution(const Assignment& x) const {
476 double d0 = static_cast<double>(x[0]);
477 double d1 = static_cast<double>(x[1]);
478 return (d0<0 ? -d0 : d0) == d1;
479 }
480
481 virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
482 Gecode::abs(home, x[0], x[1], ipl);
483 }
484 };
485
487 class AbsXX : public Test {
488 public:
490 AbsXX(const std::string& s, const Gecode::IntSet& d,
492 : Test("Arithmetic::Abs::XX::"+str(ipl)+"::"+s,1,d,false,ipl) {}
493
494 virtual bool solution(const Assignment& x) const {
495 double d0 = static_cast<double>(x[0]);
496 double d1 = static_cast<double>(x[0]);
497 return (d0<0 ? -d0 : d0) == d1;
498 }
499
500 virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
501 Gecode::abs(home, x[0], x[0], ipl);
502 }
503 };
504
506 class MinXYZ : public Test {
507 public:
509 MinXYZ(const std::string& s, const Gecode::IntSet& d,
511 : Test("Arithmetic::Min::Bin::XYZ::"+str(ipl)+"::"+s,3,d,false,ipl) {}
512
513 virtual bool solution(const Assignment& x) const {
514 return std::min(x[0],x[1]) == x[2];
515 }
516
517 virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
518 Gecode::min(home, x[0], x[1], x[2], ipl);
519 }
520 };
521
523 class MinXXY : public Test {
524 public:
526 MinXXY(const std::string& s, const Gecode::IntSet& d,
528 : Test("Arithmetic::Min::Bin::XYX::"+str(ipl)+"::"+s,2,d) {}
529
530 virtual bool solution(const Assignment& x) const {
531 return std::min(x[0],x[0]) == x[1];
532 }
533
534 virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
535 Gecode::min(home, x[0], x[0], x[1], ipl);
536 }
537 };
538
540 class MinXYX : public Test {
541 public:
543 MinXYX(const std::string& s, const Gecode::IntSet& d,
545 : Test("Arithmetic::Min::Bin::XYX::"+str(ipl)+"::"+s,2,d) {}
546
547 virtual bool solution(const Assignment& x) const {
548 return std::min(x[0],x[1]) == x[0];
549 }
550
551 virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
552 Gecode::min(home, x[0], x[1], x[0], ipl);
553 }
554 };
555
557 class MinXYY : public Test {
558 public:
560 MinXYY(const std::string& s, const Gecode::IntSet& d,
562 : Test("Arithmetic::Min::Bin::XYY::"+str(ipl)+"::"+s,2,d) {}
563
564 virtual bool solution(const Assignment& x) const {
565 return std::min(x[0],x[1]) == x[1];
566 }
567
568 virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
569 Gecode::min(home, x[0], x[1], x[1], ipl);
570 }
571 };
572
574 class MinXXX : public Test {
575 public:
577 MinXXX(const std::string& s, const Gecode::IntSet& d,
579 : Test("Arithmetic::Min::Bin::XXX::"+str(ipl)+"::"+s,1,d) {}
580
581 virtual bool solution(const Assignment& x) const {
582 return std::min(x[0],x[0]) == x[0];
583 }
584
585 virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
586 Gecode::min(home, x[0], x[0], x[0], ipl);
587 }
588 };
589
591 class MaxXYZ : public Test {
592 public:
594 MaxXYZ(const std::string& s, const Gecode::IntSet& d,
596 : Test("Arithmetic::Max::Bin::XYZ::"+str(ipl)+"::"+s,3,d) {
598 }
599
600 virtual bool solution(const Assignment& x) const {
601 return std::max(x[0],x[1]) == x[2];
602 }
603
604 virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
605 Gecode::max(home, x[0], x[1], x[2], ipl);
606 }
607 };
608
610 class MaxXXY : public Test {
611 public:
613 MaxXXY(const std::string& s, const Gecode::IntSet& d,
615 : Test("Arithmetic::Max::Bin::XXY::"+str(ipl)+"::"+s,2,d) {}
616
617 virtual bool solution(const Assignment& x) const {
618 return std::max(x[0],x[0]) == x[1];
619 }
620
621 virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
622 Gecode::max(home, x[0], x[0], x[1], ipl);
623 }
624 };
625
627 class MaxXYX : public Test {
628 public:
630 MaxXYX(const std::string& s, const Gecode::IntSet& d,
632 : Test("Arithmetic::Max::Bin::XYX::"+str(ipl)+"::"+s,2,d) {}
633
634 virtual bool solution(const Assignment& x) const {
635 return std::max(x[0],x[1]) == x[0];
636 }
637
638 virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
639 Gecode::max(home, x[0], x[1], x[0], ipl);
640 }
641 };
642
644 class MaxXYY : public Test {
645 public:
647 MaxXYY(const std::string& s, const Gecode::IntSet& d,
649 : Test("Arithmetic::Max::Bin::XYY::"+str(ipl)+"::"+s,2,d) {}
650
651 virtual bool solution(const Assignment& x) const {
652 return std::max(x[0],x[1]) == x[1];
653 }
654
655 virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
656 Gecode::max(home, x[0], x[1], x[1], ipl);
657 }
658 };
659
661 class MaxXXX : public Test {
662 public:
664 MaxXXX(const std::string& s, const Gecode::IntSet& d,
666 : Test("Arithmetic::Max::Bin::XXX::"+str(ipl)+"::"+s,1,d) {}
667
668 virtual bool solution(const Assignment& x) const {
669 return std::max(x[0],x[0]) == x[0];
670 }
671
672 virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
673 Gecode::max(home, x[0], x[0], x[0], ipl);
674 }
675 };
676
678 class MinNary : public Test {
679 public:
682 : Test("Arithmetic::Min::Nary::"+str(ipl),4,-4,4,false,ipl) {}
683
684 virtual bool solution(const Assignment& x) const {
685 return std::min(std::min(x[0],x[1]), x[2]) == x[3];
686 }
687
688 virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
690 m[0]=x[0]; m[1]=x[1]; m[2]=x[2];
691 Gecode::min(home, m, x[3], ipl);
692 }
693 };
694
696 class MinNaryShared : public Test {
697 public:
700 : Test("Arithmetic::Min::Nary::Shared::"+str(ipl),3,-4,4,false,ipl) {}
701
702 virtual bool solution(const Assignment& x) const {
703 return std::min(std::min(x[0],x[1]), x[2]) == x[1];
704 }
705
706 virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
708 m[0]=x[0]; m[1]=x[1]; m[2]=x[2];
709 Gecode::min(home, m, x[1], ipl);
710 }
711 };
712
714 class MaxNary : public Test {
715 public:
718 : Test("Arithmetic::Max::Nary::"+str(ipl),4,-4,4,false,ipl) {}
719
720 virtual bool solution(const Assignment& x) const {
721 return std::max(std::max(x[0],x[1]), x[2]) == x[3];
722 }
723
724 virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
726 m[0]=x[0]; m[1]=x[1]; m[2]=x[2];
727 Gecode::max(home, m, x[3], ipl);
728 }
729 };
730
732 class MaxNaryShared : public Test {
733 public:
736 : Test("Arithmetic::Max::Nary::Shared::"+str(ipl),3,-4,4,false,ipl) {}
737
738 virtual bool solution(const Assignment& x) const {
739 return std::max(std::max(x[0],x[1]), x[2]) == x[1];
740 }
741
742 virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
744 m[0]=x[0]; m[1]=x[1]; m[2]=x[2];
745 Gecode::max(home, m, x[1], ipl);
746 }
747 };
748
750 class ArgMax : public Test {
751 protected:
756 public:
758 ArgMax(int n, int o, bool tb)
759 : Test("Arithmetic::ArgMax::"+str(o)+"::"+str(tb)+"::"+str(n),
760 n+1,0,n+1,
761 false,tb ? Gecode::IPL_DEF : Gecode::IPL_DOM),
762 offset(o), tiebreak(tb) {}
763
764 virtual bool solution(const Assignment& x) const {
765 int n=x.size()-1;
766 if ((x[n] < offset) || (x[n] >= n + offset))
767 return false;
768 int m=x[0]; int p=0;
769 for (int i=1; i<n; i++)
770 if (x[i] > m) {
771 p=i; m=x[i];
772 }
773 return tiebreak ? (p + offset == x[n]) : (m == x[x[n]-offset]);
774 }
775
776 virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
777 int n=x.size()-1;
779 for (int i=0; i<n; i++)
780 m[i]=x[i];
781 Gecode::argmax(home, m, offset, x[n], tiebreak);
782 }
783 };
784
786 class ArgMaxShared : public Test {
787 protected:
790 public:
792 ArgMaxShared(int n, bool tb)
793 : Test("Arithmetic::ArgMax::Shared::"+str(tb)+"::"+str(n),n+1,0,n+1,
794 false),
795 tiebreak(tb) {
796 testfix=false;
797 }
798
799 virtual bool solution(const Assignment& x) const {
800 int n=x.size()-1;
801 if ((x[n] < 0) || (x[n] >= 2*n))
802 return false;
803 Gecode::IntArgs y(2*n);
804 for (int i=0; i<n; i++)
805 y[2*i+0]=y[2*i+1]=x[i];
806 int m=y[0]; int p=0;
807 for (int i=1; i<2*n; i++)
808 if (y[i] > m) {
809 p=i; m=y[i];
810 }
811 return tiebreak ? (p == x[n]) : (m == y[x[n]]);
812 }
813
814 virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
815 int n=x.size()-1;
816 Gecode::IntVarArgs m(2*n);
817 for (int i=0; i<n; i++)
818 m[2*i+0]=m[2*i+1]=x[i];
819 Gecode::argmax(home, m, x[n], tiebreak);
820 }
821 };
822
824 class ArgMin : public Test {
825 protected:
830 public:
832 ArgMin(int n, int o, bool tb)
833 : Test("Arithmetic::ArgMin::"+str(o)+"::"+str(tb)+"::"+str(n),
834 n+1,0,n+1,
835 false,tb ? Gecode::IPL_DEF : Gecode::IPL_DOM),
836 offset(o), tiebreak(tb) {}
837
838 virtual bool solution(const Assignment& x) const {
839 int n=x.size()-1;
840 if ((x[n] < offset) || (x[n] >= n + offset))
841 return false;
842 int m=x[0]; int p=0;
843 for (int i=1; i<n; i++)
844 if (x[i] < m) {
845 p=i; m=x[i];
846 }
847 return tiebreak ? (p+offset == x[n]) : (m == x[x[n]-offset]);
848 }
849
850 virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
851 int n=x.size()-1;
853 for (int i=0; i<n; i++)
854 m[i]=x[i];
855 Gecode::argmin(home, m, offset, x[n], tiebreak);
856 }
857 };
858
860 class ArgMinShared : public Test {
861 protected:
864 public:
866 ArgMinShared(int n, bool tb)
867 : Test("Arithmetic::ArgMin::Shared::"+str(tb)+"::"+str(n),n+1,0,n+1,
868 false),
869 tiebreak(tb) {
870 testfix=false;
871 }
872
873 virtual bool solution(const Assignment& x) const {
874 int n=x.size()-1;
875 if ((x[n] < 0) || (x[n] >= 2*n))
876 return false;
877 Gecode::IntArgs y(2*n);
878 for (int i=0; i<n; i++)
879 y[2*i+0]=y[2*i+1]=x[i];
880 int m=y[0]; int p=0;
881 for (int i=1; i<2*n; i++)
882 if (y[i] < m) {
883 p=i; m=y[i];
884 }
885 return tiebreak ? (p == x[n]) : (m == y[x[n]]);
886 }
887
888 virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
889 int n=x.size()-1;
890 Gecode::IntVarArgs m(2*n);
891 for (int i=0; i<n; i++)
892 m[2*i+0]=m[2*i+1]=x[i];
893 Gecode::argmin(home, m, x[n], tiebreak);
894 }
895 };
896
898 class ArgMaxBool : public Test {
899 protected:
904 public:
906 ArgMaxBool(int n, int o, bool tb)
907 : Test("Arithmetic::ArgMaxBool::"+str(o)+"::"+str(tb)+"::"+str(n),
908 n+1,0,n+1,
909 false,tb ? Gecode::IPL_DEF : Gecode::IPL_DOM),
910 offset(o), tiebreak(tb) {}
911
912 virtual bool solution(const Assignment& x) const {
913 int n=x.size()-1;
914 if ((x[n] < offset) || (x[n] >= n + offset))
915 return false;
916 int m=x[0]; int p=0;
917 if (x[0] > 1)
918 return false;
919 for (int i=1; i<n; i++) {
920 if (x[i] > 1)
921 return false;
922 if (x[i] > m) {
923 p=i; m=x[i];
924 }
925 }
926 return tiebreak ? (p + offset == x[n]) : (m == x[x[n]-offset]);
927 }
928
929 virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
930 int n=x.size()-1;
932 for (int i=0; i<n; i++)
933 m[i]=channel(home,x[i]);
934 Gecode::argmax(home, m, offset, x[n], tiebreak);
935 }
936 };
937
939 class ArgMaxBoolShared : public Test {
940 protected:
943 public:
945 ArgMaxBoolShared(int n, bool tb)
946 : Test("Arithmetic::ArgMaxBool::Shared::"+str(tb)+"::"+str(n),n+1,0,n+1,
947 false),
948 tiebreak(tb) {
949 testfix=false;
950 }
951
952 virtual bool solution(const Assignment& x) const {
953 int n=x.size()-1;
954 if ((x[n] < 0) || (x[n] >= 2*n))
955 return false;
956 Gecode::IntArgs y(2*n);
957 for (int i=0; i<n; i++)
958 y[2*i+0]=y[2*i+1]=x[i];
959 int m=y[0]; int p=0;
960 if (y[0] > 1)
961 return false;
962 for (int i=1; i<2*n; i++) {
963 if (y[i] > 1)
964 return false;
965 if (y[i] > m) {
966 p=i; m=y[i];
967 }
968 }
969 return tiebreak ? (p == x[n]) : (m == y[x[n]]);
970 }
971
972 virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
973 int n=x.size()-1;
974 Gecode::BoolVarArgs m(2*n);
975 for (int i=0; i<n; i++)
976 m[2*i+0]=m[2*i+1]=channel(home,x[i]);
977 Gecode::argmax(home, m, x[n], tiebreak);
978 }
979 };
980
982 class ArgMinBool : public Test {
983 protected:
988 public:
990 ArgMinBool(int n, int o, bool tb)
991 : Test("Arithmetic::ArgMinBool::"+str(o)+"::"+str(tb)+"::"+str(n),
992 n+1,0,n+1,
993 false,tb ? Gecode::IPL_DEF : Gecode::IPL_DOM),
994 offset(o), tiebreak(tb) {}
995
996 virtual bool solution(const Assignment& x) const {
997 int n=x.size()-1;
998 if ((x[n] < offset) || (x[n] >= n + offset))
999 return false;
1000 int m=x[0]; int p=0;
1001 if (x[0] < 0 || x[0] > 1)
1002 return false;
1003 for (int i=1; i<n; i++) {
1004 if (x[i] < 0 || x[i] > 1)
1005 return false;
1006 if (x[i] < m) {
1007 p=i; m=x[i];
1008 }
1009 }
1010 return tiebreak ? (p+offset == x[n]) : (m == x[x[n]-offset]);
1011 }
1012
1013 virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
1014 int n=x.size()-1;
1016 for (int i=0; i<n; i++)
1017 m[i]=channel(home,x[i]);
1018 Gecode::argmin(home, m, offset, x[n], tiebreak);
1019 }
1020 };
1021
1023 class ArgMinBoolShared : public Test {
1024 protected:
1027 public:
1029 ArgMinBoolShared(int n, bool tb)
1030 : Test("Arithmetic::ArgMinBool::Shared::"+str(tb)+"::"+str(n),n+1,0,n+1,
1031 false),
1032 tiebreak(tb) {
1033 testfix=false;
1034 }
1035
1036 virtual bool solution(const Assignment& x) const {
1037 int n=x.size()-1;
1038 if ((x[n] < 0) || (x[n] >= 2*n))
1039 return false;
1040 Gecode::IntArgs y(2*n);
1041 for (int i=0; i<n; i++)
1042 y[2*i+0]=y[2*i+1]=x[i];
1043 int m=y[0]; int p=0;
1044 if (y[0] > 1)
1045 return false;
1046 for (int i=1; i<2*n; i++) {
1047 if (y[i] > 1)
1048 return false;
1049 if (y[i] < m) {
1050 p=i; m=y[i];
1051 }
1052 }
1053 return tiebreak ? (p == x[n]) : (m == y[x[n]]);
1054 }
1055
1056 virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
1057 int n=x.size()-1;
1058 Gecode::BoolVarArgs m(2*n);
1059 for (int i=0; i<n; i++)
1060 m[2*i+0]=m[2*i+1]=channel(home,x[i]);
1061 Gecode::argmin(home, m, x[n], tiebreak);
1062 }
1063 };
1064
1066 class Create {
1067 public:
1069 Create(void) {
1070
1071 const int va[7] = {
1073 -1,0,1,
1075 };
1076 const int vb[9] = {
1077 static_cast<int>(-sqrt(static_cast<double>
1079 -4,-2,-1,0,1,2,4,
1080 static_cast<int>(sqrt(static_cast<double>
1082 };
1083
1084 Gecode::IntSet a(va,7);
1085 Gecode::IntSet b(vb,9);
1086 Gecode::IntSet c(-8,8);
1087 Gecode::IntSet d(-70,70);
1088
1089 (void) new DivMod("A",a);
1090 (void) new DivMod("B",b);
1091 (void) new DivMod("C",c);
1092
1093 (void) new Div("A",a);
1094 (void) new Div("B",b);
1095 (void) new Div("C",c);
1096
1097 (void) new Mod("A",a);
1098 (void) new Mod("B",b);
1099 (void) new Mod("C",c);
1100
1101
1102 for (IntPropLevels ipls; ipls(); ++ipls) {
1103 (void) new AbsXY("A",a,ipls.ipl());
1104 (void) new AbsXY("B",b,ipls.ipl());
1105 (void) new AbsXY("C",c,ipls.ipl());
1106
1107 (void) new AbsXX("A",a,ipls.ipl());
1108 (void) new AbsXX("B",b,ipls.ipl());
1109 (void) new AbsXX("C",c,ipls.ipl());
1110 if (ipls.ipl() != Gecode::IPL_VAL) {
1111 (void) new MultXYZ("A",a,ipls.ipl());
1112 (void) new MultXYZ("B",b,ipls.ipl());
1113 (void) new MultXYZ("C",c,ipls.ipl());
1114
1115 (void) new MultXXY("A",a,ipls.ipl());
1116 (void) new MultXXY("B",b,ipls.ipl());
1117 (void) new MultXXY("C",c,ipls.ipl());
1118
1119 (void) new MultXYX("A",a,ipls.ipl());
1120 (void) new MultXYX("B",b,ipls.ipl());
1121 (void) new MultXYX("C",c,ipls.ipl());
1122
1123 (void) new MultXYY("A",a,ipls.ipl());
1124 (void) new MultXYY("B",b,ipls.ipl());
1125 (void) new MultXYY("C",c,ipls.ipl());
1126
1127 (void) new MultXXX("A",a,ipls.ipl());
1128 (void) new MultXXX("B",b,ipls.ipl());
1129 (void) new MultXXX("C",c,ipls.ipl());
1130
1131 (void) new SqrXY("A",a,ipls.ipl());
1132 (void) new SqrXY("B",b,ipls.ipl());
1133 (void) new SqrXY("C",c,ipls.ipl());
1134
1135 (void) new SqrXX("A",a,ipls.ipl());
1136 (void) new SqrXX("B",b,ipls.ipl());
1137 (void) new SqrXX("C",c,ipls.ipl());
1138
1139 for (int n=0; n<=6; n++) {
1140 (void) new PowXY("A",n,a,ipls.ipl());
1141 (void) new PowXY("B",n,b,ipls.ipl());
1142 (void) new PowXY("C",n,c,ipls.ipl());
1143 (void) new PowXY("D",n,d,ipls.ipl());
1144
1145 (void) new PowXX("A",n,a,ipls.ipl());
1146 (void) new PowXX("B",n,b,ipls.ipl());
1147 (void) new PowXX("C",n,c,ipls.ipl());
1148 (void) new PowXX("D",n,d,ipls.ipl());
1149 }
1150
1151 for (int n=1; n<=6; n++) {
1152 (void) new NrootXY("A",n,a,ipls.ipl());
1153 (void) new NrootXY("B",n,b,ipls.ipl());
1154 (void) new NrootXY("C",n,c,ipls.ipl());
1155 (void) new NrootXY("D",n,d,ipls.ipl());
1156
1157 (void) new NrootXX("A",n,a,ipls.ipl());
1158 (void) new NrootXX("B",n,b,ipls.ipl());
1159 (void) new NrootXX("C",n,c,ipls.ipl());
1160 (void) new NrootXX("D",n,d,ipls.ipl());
1161 }
1162
1163 for (int n=30; n<=34; n++) {
1164 (void) new PowXY("C",n,c,ipls.ipl());
1165 (void) new PowXX("C",n,c,ipls.ipl());
1166 (void) new NrootXY("C",n,c,ipls.ipl());
1167 (void) new NrootXX("C",n,c,ipls.ipl());
1168 }
1169
1170 (void) new SqrtXY("A",a,ipls.ipl());
1171 (void) new SqrtXY("B",b,ipls.ipl());
1172 (void) new SqrtXY("C",c,ipls.ipl());
1173
1174 (void) new SqrtXX("A",a,ipls.ipl());
1175 (void) new SqrtXX("B",b,ipls.ipl());
1176 (void) new SqrtXX("C",c,ipls.ipl());
1177
1178 (void) new MinXYZ("A",a,ipls.ipl());
1179 (void) new MinXYZ("B",b,ipls.ipl());
1180 (void) new MinXYZ("C",c,ipls.ipl());
1181
1182 (void) new MinXXY("A",a,ipls.ipl());
1183 (void) new MinXXY("B",b,ipls.ipl());
1184 (void) new MinXXY("C",c,ipls.ipl());
1185
1186 (void) new MinXYX("A",a,ipls.ipl());
1187 (void) new MinXYX("B",b,ipls.ipl());
1188 (void) new MinXYX("C",c,ipls.ipl());
1189
1190 (void) new MinXYY("A",a,ipls.ipl());
1191 (void) new MinXYY("B",b,ipls.ipl());
1192 (void) new MinXYY("C",c,ipls.ipl());
1193
1194 (void) new MinXXX("A",a,ipls.ipl());
1195 (void) new MinXXX("B",b,ipls.ipl());
1196 (void) new MinXXX("C",c,ipls.ipl());
1197
1198 (void) new MaxXYZ("A",a,ipls.ipl());
1199 (void) new MaxXYZ("B",b,ipls.ipl());
1200 (void) new MaxXYZ("C",c,ipls.ipl());
1201
1202 (void) new MaxXXY("A",a,ipls.ipl());
1203 (void) new MaxXXY("B",b,ipls.ipl());
1204 (void) new MaxXXY("C",c,ipls.ipl());
1205
1206 (void) new MaxXYX("A",a,ipls.ipl());
1207 (void) new MaxXYX("B",b,ipls.ipl());
1208 (void) new MaxXYX("C",c,ipls.ipl());
1209
1210 (void) new MaxXYY("A",a,ipls.ipl());
1211 (void) new MaxXYY("B",b,ipls.ipl());
1212 (void) new MaxXYY("C",c,ipls.ipl());
1213
1214 (void) new MaxXXX("A",a,ipls.ipl());
1215 (void) new MaxXXX("B",b,ipls.ipl());
1216 (void) new MaxXXX("C",c,ipls.ipl());
1217
1218 (void) new MinNary(ipls.ipl());
1219 (void) new MinNaryShared(ipls.ipl());
1220 (void) new MaxNary(ipls.ipl());
1221 (void) new MaxNaryShared(ipls.ipl());
1222 }
1223 }
1224
1225 for (int i=1; i<5; i++) {
1226 (void) new ArgMax(i,0,true);
1227 (void) new ArgMax(i,1,true);
1228 (void) new ArgMaxShared(i,true);
1229 (void) new ArgMin(i,0,true);
1230 (void) new ArgMin(i,1,true);
1231 (void) new ArgMinShared(i,true);
1232 (void) new ArgMax(i,0,false);
1233 (void) new ArgMax(i,1,false);
1234 (void) new ArgMaxShared(i,false);
1235 (void) new ArgMin(i,0,false);
1236 (void) new ArgMin(i,1,false);
1237 (void) new ArgMinShared(i,false);
1238
1239 (void) new ArgMaxBool(i,0,true);
1240 (void) new ArgMaxBool(i,1,true);
1241 (void) new ArgMaxBoolShared(i,true);
1242 (void) new ArgMinBool(i,0,true);
1243 (void) new ArgMinBool(i,1,true);
1244 (void) new ArgMinBoolShared(i,true);
1245 (void) new ArgMaxBool(i,0,false);
1246 (void) new ArgMaxBool(i,1,false);
1247 (void) new ArgMaxBoolShared(i,false);
1248 (void) new ArgMinBool(i,0,false);
1249 (void) new ArgMinBool(i,1,false);
1250 (void) new ArgMinBoolShared(i,false);
1251 }
1252 }
1253 };
1254
1257
1258 }
1259}}
1260
1261// STATISTICS: test-int
Passing Boolean variables.
Definition int.hh:721
Passing integer arguments.
Definition int.hh:634
Integer sets.
Definition int.hh:174
Passing integer variables.
Definition int.hh:662
Integer variable array.
Definition int.hh:772
Computation spaces.
Definition core.hpp:1744
Test for absolute value constraint with shared variables
virtual bool solution(const Assignment &x) const
Test whether x is solution
AbsXX(const std::string &s, const Gecode::IntSet &d, Gecode::IntPropLevel ipl)
Create and register test.
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
Test for absolute value constraint
virtual bool solution(const Assignment &x) const
Test whether x is solution
AbsXY(const std::string &s, const Gecode::IntSet &d, Gecode::IntPropLevel ipl)
Create and register test.
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
Test for argument maximum constraint with shared variables
virtual bool solution(const Assignment &x) const
Test whether x is solution
ArgMaxBoolShared(int n, bool tb)
Create and register test.
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
bool tiebreak
Whether to use tie-breaking.
Test for Boolean argument maximum constraint
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
bool tiebreak
Whether to use tie-breaking.
virtual bool solution(const Assignment &x) const
Test whether x is solution
ArgMaxBool(int n, int o, bool tb)
Create and register test.
Test for argument maximum constraint with shared variables
ArgMaxShared(int n, bool tb)
Create and register test.
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
virtual bool solution(const Assignment &x) const
Test whether x is solution
bool tiebreak
Whether to use tie-breaking.
Test for argument maximum constraint
virtual bool solution(const Assignment &x) const
Test whether x is solution
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
int offset
Offset to be used.
bool tiebreak
Whether to use tie-breaking.
ArgMax(int n, int o, bool tb)
Create and register test.
Test for argument minimum constraint with shared variables
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
bool tiebreak
Whether to use tie-breaking.
ArgMinBoolShared(int n, bool tb)
Create and register test.
virtual bool solution(const Assignment &x) const
Test whether x is solution
Test for argument minimum constraint
int offset
Which offset to use.
bool tiebreak
Whether to use tie-breaking.
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
ArgMinBool(int n, int o, bool tb)
Create and register test.
virtual bool solution(const Assignment &x) const
Test whether x is solution
Test for argument minimum constraint with shared variables
bool tiebreak
Whether to use tie-breaking.
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
ArgMinShared(int n, bool tb)
Create and register test.
virtual bool solution(const Assignment &x) const
Test whether x is solution
Test for argument minimum constraint
virtual bool solution(const Assignment &x) const
Test whether x is solution
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
ArgMin(int n, int o, bool tb)
Create and register test.
bool tiebreak
Whether to use tie-breaking.
int offset
Which offset to use.
Help class to create and register tests.
Create(void)
Perform creation and registration.
Test for division/modulo constraint
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
DivMod(const std::string &s, const Gecode::IntSet &d)
Create and register test.
virtual bool solution(const Assignment &x) const
Test whether x is solution
Test for division constraint
virtual bool solution(const Assignment &x) const
Test whether x is solution
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
Div(const std::string &s, const Gecode::IntSet &d)
Create and register test.
Test for n-ary maximum constraint with shared variables
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
MaxNaryShared(Gecode::IntPropLevel ipl)
Create and register test.
virtual bool solution(const Assignment &x) const
Test whether x is solution
Test for n-ary maximum constraint
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
virtual bool solution(const Assignment &x) const
Test whether x is solution
MaxNary(Gecode::IntPropLevel ipl)
Create and register test.
Test for binary maximum constraint with shared variables
MaxXXX(const std::string &s, const Gecode::IntSet &d, Gecode::IntPropLevel ipl)
Create and register test.
virtual bool solution(const Assignment &x) const
Test whether x is solution
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
Test for binary maximum constraint with shared variables
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
MaxXXY(const std::string &s, const Gecode::IntSet &d, Gecode::IntPropLevel ipl)
Create and register test.
virtual bool solution(const Assignment &x) const
Test whether x is solution
Test for binary maximum constraint with shared variables
virtual bool solution(const Assignment &x) const
Test whether x is solution
MaxXYX(const std::string &s, const Gecode::IntSet &d, Gecode::IntPropLevel ipl)
Create and register test.
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
Test for binary maximum constraint with shared variables
virtual bool solution(const Assignment &x) const
Test whether x is solution
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
MaxXYY(const std::string &s, const Gecode::IntSet &d, Gecode::IntPropLevel ipl)
Create and register test.
Test for binary maximum constraint
virtual bool solution(const Assignment &x) const
Test whether x is solution
MaxXYZ(const std::string &s, const Gecode::IntSet &d, Gecode::IntPropLevel ipl)
Create and register test.
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
Test for n-ary minimmum constraint with shared variables
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
virtual bool solution(const Assignment &x) const
Test whether x is solution
MinNaryShared(Gecode::IntPropLevel ipl)
Create and register test.
Test for n-ary minimmum constraint
virtual bool solution(const Assignment &x) const
Test whether x is solution
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
MinNary(Gecode::IntPropLevel ipl)
Create and register test.
Test for binary minimum constraint with shared variables
MinXXX(const std::string &s, const Gecode::IntSet &d, Gecode::IntPropLevel ipl)
Create and register test.
virtual bool solution(const Assignment &x) const
Test whether x is solution
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
Test for binary minimum constraint with shared variables
virtual bool solution(const Assignment &x) const
Test whether x is solution
MinXXY(const std::string &s, const Gecode::IntSet &d, Gecode::IntPropLevel ipl)
Create and register test.
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
Test for binary minimum constraint with shared variables
virtual bool solution(const Assignment &x) const
Test whether x is solution
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
MinXYX(const std::string &s, const Gecode::IntSet &d, Gecode::IntPropLevel ipl)
Create and register test.
Test for binary minimum constraint with shared variables
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
virtual bool solution(const Assignment &x) const
Test whether x is solution
MinXYY(const std::string &s, const Gecode::IntSet &d, Gecode::IntPropLevel ipl)
Create and register test.
Test for binary minimum constraint
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
virtual bool solution(const Assignment &x) const
Test whether x is solution
MinXYZ(const std::string &s, const Gecode::IntSet &d, Gecode::IntPropLevel ipl)
Create and register test.
Test for modulo constraint
Mod(const std::string &s, const Gecode::IntSet &d)
Create and register test.
virtual bool solution(const Assignment &x) const
Test whether x is solution
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
Test for multiplication constraint with shared variables
virtual bool solution(const Assignment &x) const
Test whether x is solution
MultXXX(const std::string &s, const Gecode::IntSet &d, Gecode::IntPropLevel ipl)
Create and register test.
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
Test for multiplication constraint with shared variables
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
virtual bool solution(const Assignment &x) const
Test whether x is solution
MultXXY(const std::string &s, const Gecode::IntSet &d, Gecode::IntPropLevel ipl)
Create and register test.
Test for multiplication constraint with shared variables
MultXYX(const std::string &s, const Gecode::IntSet &d, Gecode::IntPropLevel ipl)
Create and register test.
virtual bool solution(const Assignment &x) const
Test whether x is solution
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
Test for multiplication constraint with shared variables
virtual bool solution(const Assignment &x) const
Test whether x is solution
MultXYY(const std::string &s, const Gecode::IntSet &d, Gecode::IntPropLevel ipl)
Create and register test.
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
Test for multiplication constraint
virtual bool solution(const Assignment &x) const
Test whether x is solution
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
MultXYZ(const std::string &s, const Gecode::IntSet &d, Gecode::IntPropLevel ipl)
Create and register test.
Test for nroot constraint with shared variables
virtual bool solution(const Assignment &x) const
Test whether x is solution
NrootXX(const std::string &s, int n0, const Gecode::IntSet &d, Gecode::IntPropLevel ipl)
Create and register test.
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
Test for nroot constraint
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
NrootXY(const std::string &s, int n0, const Gecode::IntSet &d, Gecode::IntPropLevel ipl)
Floor.
virtual bool solution(const Assignment &x) const
Test whether x is solution
Test for power constraint with shared variables
virtual bool solution(const Assignment &x) const
Test whether x is solution
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
PowXX(const std::string &s, int n0, const Gecode::IntSet &d, Gecode::IntPropLevel ipl)
Create and register test.
Test for power constraint
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
PowXY(const std::string &s, int n0, const Gecode::IntSet &d, Gecode::IntPropLevel ipl)
Create and register test.
virtual bool solution(const Assignment &x) const
Test whether x is solution
Test for squaring constraint with shared variables
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
virtual bool solution(const Assignment &x) const
Test whether x is solution
SqrXX(const std::string &s, const Gecode::IntSet &d, Gecode::IntPropLevel ipl)
Create and register test.
Test for squaring constraint
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
SqrXY(const std::string &s, const Gecode::IntSet &d, Gecode::IntPropLevel ipl)
Create and register test.
virtual bool solution(const Assignment &x) const
Test whether x is solution
Test for square root constraint with shared variables
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
virtual bool solution(const Assignment &x) const
Test whether x is solution
SqrtXX(const std::string &s, const Gecode::IntSet &d, Gecode::IntPropLevel ipl)
Create and register test.
Test for square root constraint
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
virtual bool solution(const Assignment &x) const
Test whether x is solution
SqrtXY(const std::string &s, const Gecode::IntSet &d, Gecode::IntPropLevel ipl)
Create and register test.
Base class for assignments
Definition int.hh:59
Iterator for simple integer propagation levels.
Definition int.hh:332
bool testfix
Whether to perform fixpoint test.
Definition int.hh:240
Gecode::IntPropLevel ipl
Propagation level.
Definition int.hh:234
static std::string str(Gecode::IntPropLevel ipl)
Map integer propagation level to string.
Definition int.hpp:209
ConTestLevel contest
Whether to test for certain consistency.
Definition int.hh:236
void rel(Home home, FloatVar x0, FloatRelType frt, FloatVar x1)
Post propagator for .
Definition rel.cpp:68
IntPropLevel
Propagation levels for integer propagators.
Definition int.hh:989
@ IRT_EQ
Equality ( )
Definition int.hh:941
@ IPL_DOM
Domain propagation Options: basic versus advanced propagation.
Definition int.hh:994
@ IPL_VAL
Value propagation.
Definition int.hh:992
@ IPL_DEF
Simple propagation levels.
Definition int.hh:991
const int min
Smallest allowed integer value.
Definition int.hh:118
const int max
Largest allowed integer value.
Definition int.hh:116
Gecode toplevel namespace
void channel(Home home, FloatVar x0, IntVar x1)
Post propagator for channeling a float and an integer variable .
Definition channel.cpp:41
void mod(Home home, IntVar x0, IntVar x1, IntVar x2, IntPropLevel ipl=IPL_DEF)
Post propagator for .
void sqr(Home home, FloatVar x0, FloatVar x1)
Post propagator for .
IntVar expr(Home home, const LinIntExpr &e, const IntPropLevels &ipls=IntPropLevels::def)
Post linear expression and return its value.
Definition int-expr.cpp:915
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 argmax(Home home, const IntVarArgs &x, IntVar y, bool tiebreak=true, IntPropLevel ipl=IPL_DEF)
Post propagator for .
void mult(Home home, FloatVar x0, FloatVar x1, FloatVar x2)
Post propagator for .
void divmod(Home home, IntVar x0, IntVar x1, IntVar x2, IntVar x3, IntPropLevel ipl=IPL_DEF)
Post propagator for .
void sqrt(Home home, FloatVar x0, FloatVar x1)
Post propagator for .
Post propagator for SetVar SetOpType SetVar y
Definition set.hh:773
void max(Home home, FloatVar x0, FloatVar x1, FloatVar x2)
Post propagator for .
void argmin(Home home, const IntVarArgs &x, IntVar y, bool tiebreak=true, IntPropLevel ipl=IPL_DEF)
Post propagator for .
void pow(Home home, FloatVar x0, int n, FloatVar x1)
Post propagator for for $n\geq 0$.
Post propagator for SetVar x
Definition set.hh:773
void nroot(Home home, FloatVar x0, int n, FloatVar x1)
Post propagator for for $n\geq 0$.
Tests for arithmetic constraints
bool powgr(int n, long long int r, int x)
int cnroot(int n, int x)
int fnroot(int n, int x)
bool powle(int n, long long int r, int x)
Testing finite domain integers.
Definition int.cpp:40
@ CTL_BOUNDS_Z
Test for bounds(z)-consistency.
Definition int.hh:143
General test support.
Definition afc.cpp:39
Region r
Definition region.cpp:65