Generated on Mon Feb 8 2021 00:00:00 for Gecode by doxygen 1.8.20
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 
41 namespace Test { namespace Int {
42 
44  namespace Arithmetic {
45 
51  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) {}
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  }
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) {}
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  }
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) {}
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  }
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) {}
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  }
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) {}
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  }
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) {}
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  }
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) {}
178  virtual bool solution(const Assignment& x) const {
179  double d0 = static_cast<double>(x[0]);
180  return d0*d0 == d0;
181  }
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) {}
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  }
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) {}
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  }
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) {}
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  }
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) {}
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  }
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) {}
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  }
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) {}
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  }
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) {}
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  }
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) {}
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  }
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) {}
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  }
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) {}
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  }
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) {}
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  }
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) {}
513  virtual bool solution(const Assignment& x) const {
514  return std::min(x[0],x[1]) == x[2];
515  }
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) {}
530  virtual bool solution(const Assignment& x) const {
531  return std::min(x[0],x[0]) == x[1];
532  }
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) {}
547  virtual bool solution(const Assignment& x) const {
548  return std::min(x[0],x[1]) == x[0];
549  }
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) {}
564  virtual bool solution(const Assignment& x) const {
565  return std::min(x[0],x[1]) == x[1];
566  }
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) {}
581  virtual bool solution(const Assignment& x) const {
582  return std::min(x[0],x[0]) == x[0];
583  }
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  }
600  virtual bool solution(const Assignment& x) const {
601  return std::max(x[0],x[1]) == x[2];
602  }
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) {}
617  virtual bool solution(const Assignment& x) const {
618  return std::max(x[0],x[0]) == x[1];
619  }
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) {}
634  virtual bool solution(const Assignment& x) const {
635  return std::max(x[0],x[1]) == x[0];
636  }
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) {}
651  virtual bool solution(const Assignment& x) const {
652  return std::max(x[0],x[1]) == x[1];
653  }
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) {}
668  virtual bool solution(const Assignment& x) const {
669  return std::max(x[0],x[0]) == x[0];
670  }
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) {}
684  virtual bool solution(const Assignment& x) const {
685  return std::min(std::min(x[0],x[1]), x[2]) == x[3];
686  }
688  virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
689  Gecode::IntVarArgs m(3);
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) {}
702  virtual bool solution(const Assignment& x) const {
703  return std::min(std::min(x[0],x[1]), x[2]) == x[1];
704  }
706  virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
707  Gecode::IntVarArgs m(3);
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) {}
720  virtual bool solution(const Assignment& x) const {
721  return std::max(std::max(x[0],x[1]), x[2]) == x[3];
722  }
724  virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
725  Gecode::IntVarArgs m(3);
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) {}
738  virtual bool solution(const Assignment& x) const {
739  return std::max(std::max(x[0],x[1]), x[2]) == x[1];
740  }
742  virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
743  Gecode::IntVarArgs m(3);
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:
753  int offset;
755  bool tiebreak;
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) {}
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  }
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:
789  bool tiebreak;
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  }
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  }
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:
827  int offset;
829  bool tiebreak;
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) {}
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  }
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:
863  bool tiebreak;
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  }
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  }
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:
901  int offset;
903  bool tiebreak;
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) {}
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  }
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:
942  bool tiebreak;
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  }
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  }
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:
985  int offset;
987  bool tiebreak;
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) {}
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  }
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:
1026  bool tiebreak;
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  }
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  }
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
MinXXY(const std::string &s, const Gecode::IntSet &d, Gecode::IntPropLevel ipl)
Create and register test.
Definition: arithmetic.cpp:526
SqrtXY(const std::string &s, const Gecode::IntSet &d, Gecode::IntPropLevel ipl)
Create and register test.
Definition: arithmetic.cpp:192
Test for argument minimum constraint
Definition: arithmetic.cpp:982
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
Definition: arithmetic.cpp:393
Test for n-ary minimmum constraint
Definition: arithmetic.cpp:678
Test for argument maximum constraint with shared variables
Definition: arithmetic.cpp:939
void pow(Home home, FloatVar x0, int n, FloatVar x1)
Post propagator for for $n\geq 0$.
Definition: arithmetic.cpp:109
bool tiebreak
Whether to use tie-breaking.
Definition: arithmetic.cpp:863
Test for multiplication constraint with shared variables
Definition: arithmetic.cpp:72
bool powle(int n, long long int r, int x)
Definition: arithmetic.cpp:312
Region r
Definition: region.cpp:65
PowXY(const std::string &s, int n0, const Gecode::IntSet &d, Gecode::IntPropLevel ipl)
Create and register test.
Definition: arithmetic.cpp:232
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
Definition: arithmetic.cpp:183
Post propagator for SetVar SetOpType SetVar y
Definition: set.hh:767
Test for division constraint
Definition: arithmetic.cpp:422
ConTestLevel contest
Whether to test for certain consistency.
Definition: int.hh:236
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
Definition: arithmetic.cpp:202
MaxXYZ(const std::string &s, const Gecode::IntSet &d, Gecode::IntPropLevel ipl)
Create and register test.
Definition: arithmetic.cpp:594
MaxXYY(const std::string &s, const Gecode::IntSet &d, Gecode::IntPropLevel ipl)
Create and register test.
Definition: arithmetic.cpp:647
void min(Home home, const IntVarArgs &x, IntVar y, IntPropLevel ipl)
Post propagator for .
Definition: arithmetic.cpp:91
Test for argument maximum constraint
Definition: arithmetic.cpp:750
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
Definition: arithmetic.cpp:814
DivMod(const std::string &s, const Gecode::IntSet &d)
Create and register test.
Definition: arithmetic.cpp:407
Test for binary minimum constraint with shared variables
Definition: arithmetic.cpp:523
virtual bool solution(const Assignment &x) const
Test whether x is solution
Definition: arithmetic.cpp:838
void max(Home home, FloatVar x0, FloatVar x1, FloatVar x2)
Post propagator for .
Definition: arithmetic.cpp:49
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
Definition: arithmetic.cpp:672
virtual bool solution(const Assignment &x) const
Test whether x is solution
Definition: arithmetic.cpp:952
int offset
Offset to be used.
Definition: arithmetic.cpp:901
Test for argument minimum constraint with shared variables
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
Definition: arithmetic.cpp:888
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
Definition: arithmetic.cpp:280
Gecode::IntPropLevel ipl
Propagation level.
Definition: int.hh:234
virtual bool solution(const Assignment &x) const
Test whether x is solution
Definition: arithmetic.cpp:99
virtual bool solution(const Assignment &x) const
Test whether x is solution
Definition: arithmetic.cpp:651
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
Definition: arithmetic.cpp:534
int cnroot(int n, int x)
Definition: arithmetic.cpp:325
Test for absolute value constraint with shared variables
Definition: arithmetic.cpp:487
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
Definition: arithmetic.cpp:146
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
Definition: arithmetic.cpp:106
Test for squaring constraint with shared variables
Definition: arithmetic.cpp:171
virtual bool solution(const Assignment &x) const
Test whether x is solution
Definition: arithmetic.cpp:428
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
Definition: arithmetic.cpp:551
Passing integer variables.
Definition: int.hh:656
void pow(Home home, IntVar x0, int n, IntVar x1, IntPropLevel ipl)
Post propagator for .
Definition: arithmetic.cpp:397
void sqr(Home home, FloatVar x0, FloatVar x1)
Post propagator for .
Definition: arithmetic.cpp:95
int n
The root index.
Definition: arithmetic.cpp:375
virtual bool solution(const Assignment &x) const
Test whether x is solution
Definition: arithmetic.cpp:668
@ CTL_BOUNDS_Z
Test for bounds(z)-consistency.
Definition: int.hh:143
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
Definition: arithmetic.cpp:604
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
Definition: arithmetic.cpp:568
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
Definition: arithmetic.cpp:66
Test for binary maximum constraint with shared variables
Definition: arithmetic.cpp:644
Test for binary maximum constraint with shared variables
Definition: arithmetic.cpp:661
@ IPL_VAL
Value propagation.
Definition: int.hh:977
virtual bool solution(const Assignment &x) const
Test whether x is solution
Definition: arithmetic.cpp:799
bool tiebreak
Whether to use tie-breaking.
Definition: arithmetic.cpp:987
NrootXX(const std::string &s, int n0, const Gecode::IntSet &d, Gecode::IntPropLevel ipl)
Create and register test.
Definition: arithmetic.cpp:378
Test for multiplication constraint with shared variables
Definition: arithmetic.cpp:132
virtual bool solution(const Assignment &x) const
Test whether x is solution
Definition: arithmetic.cpp:139
IntPropLevel
Propagation levels for integer propagators.
Definition: int.hh:974
Computation spaces.
Definition: core.hpp:1742
virtual bool solution(const Assignment &x) const
Test whether x is solution
Definition: arithmetic.cpp:475
MinXYY(const std::string &s, const Gecode::IntSet &d, Gecode::IntPropLevel ipl)
Create and register test.
Definition: arithmetic.cpp:560
Gecode::FloatVal a(-8, 5)
Help class to create and register tests.
Test for nroot constraint
Definition: arithmetic.cpp:341
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
Definition: arithmetic.cpp:972
SqrtXX(const std::string &s, const Gecode::IntSet &d, Gecode::IntPropLevel ipl)
Create and register test.
Definition: arithmetic.cpp:211
void argmin(Home home, const IntVarArgs &x, IntVar y, bool tiebreak, IntPropLevel)
Post propagator for .
Definition: arithmetic.cpp:163
virtual bool solution(const Assignment &x) const
Test whether x is solution
Definition: arithmetic.cpp:383
virtual bool solution(const Assignment &x) const
Test whether x is solution
Definition: arithmetic.cpp:720
Integer variable array.
Definition: int.hh:763
Test for Boolean argument maximum constraint
Definition: arithmetic.cpp:898
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
Definition: arithmetic.cpp:481
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
Definition: arithmetic.cpp:706
int n
The exponent.
Definition: arithmetic.cpp:229
MaxNary(Gecode::IntPropLevel ipl)
Create and register test.
Definition: arithmetic.cpp:717
bool tiebreak
Whether to use tie-breaking.
Definition: arithmetic.cpp:755
MinXXX(const std::string &s, const Gecode::IntSet &d, Gecode::IntPropLevel ipl)
Create and register test.
Definition: arithmetic.cpp:577
Test for argument maximum constraint with shared variables
Definition: arithmetic.cpp:786
ArgMin(int n, int o, bool tb)
Create and register test.
Definition: arithmetic.cpp:832
void div(Home home, FloatVar x0, FloatVar x1, FloatVar x2)
Post propagator for .
Definition: arithmetic.cpp:127
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
Definition: arithmetic.cpp:724
Gecode toplevel namespace
PowXX(const std::string &s, int n0, const Gecode::IntSet &d, Gecode::IntPropLevel ipl)
Create and register test.
Definition: arithmetic.cpp:264
Create(void)
Perform creation and registration.
Test for modulo constraint
Definition: arithmetic.cpp:445
Test for binary minimum constraint with shared variables
Definition: arithmetic.cpp:540
AbsXY(const std::string &s, const Gecode::IntSet &d, Gecode::IntPropLevel ipl)
Create and register test.
Definition: arithmetic.cpp:471
bool testfix
Whether to perform fixpoint test.
Definition: int.hh:240
union Gecode::@602::NNF::@65 u
Union depending on nodetype t.
virtual bool solution(const Assignment &x) const
Test whether x is solution
Definition: arithmetic.cpp:269
virtual bool solution(const Assignment &x) const
Test whether x is solution
Definition: arithmetic.cpp:196
virtual bool solution(const Assignment &x) const
Test whether x is solution
Definition: arithmetic.cpp:702
virtual bool solution(const Assignment &x) const
Test whether x is solution
Definition: arithmetic.cpp:600
Integer sets.
Definition: int.hh:174
virtual bool solution(const Assignment &x) const
Test whether x is solution
Definition: arithmetic.cpp:451
ArgMinShared(int n, bool tb)
Create and register test.
Definition: arithmetic.cpp:866
int offset
Which offset to use.
Definition: arithmetic.cpp:985
virtual bool solution(const Assignment &x) const
Test whether x is solution
MaxNaryShared(Gecode::IntPropLevel ipl)
Create and register test.
Definition: arithmetic.cpp:735
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
Definition: arithmetic.cpp:500
Test for argument minimum constraint with shared variables
Definition: arithmetic.cpp:860
virtual bool solution(const Assignment &x) const
Test whether x is solution
Definition: arithmetic.cpp:159
int offset
Offset to be used.
Definition: arithmetic.cpp:753
Node * x
Pointer to corresponding Boolean expression node.
Definition: bool-expr.cpp:249
Test for binary maximum constraint
Definition: arithmetic.cpp:591
BoolVar expr(Home home, const BoolExpr &e, const IntPropLevels &ipls)
Post Boolean expression and return its value.
Definition: bool-expr.cpp:629
Passing Boolean variables.
Definition: int.hh:712
void nroot(Home home, FloatVar x0, int n, FloatVar x1)
Post propagator for for $n\geq 0$.
Definition: arithmetic.cpp:118
Test for n-ary maximum constraint with shared variables
Definition: arithmetic.cpp:732
Test for multiplication constraint
Definition: arithmetic.cpp:52
virtual bool solution(const Assignment &x) const
Test whether x is solution
Definition: arithmetic.cpp:684
Test for absolute value constraint
Definition: arithmetic.cpp:468
ArgMaxBool(int n, int o, bool tb)
Create and register test.
Definition: arithmetic.cpp:906
Test for n-ary maximum constraint
Definition: arithmetic.cpp:714
ArgMinBool(int n, int o, bool tb)
Create and register test.
Definition: arithmetic.cpp:990
virtual bool solution(const Assignment &x) const
Test whether x is solution
Definition: arithmetic.cpp:617
MultXYX(const std::string &s, const Gecode::IntSet &d, Gecode::IntPropLevel ipl)
Create and register test.
Definition: arithmetic.cpp:95
Test for squaring constraint
Definition: arithmetic.cpp:152
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
Definition: arithmetic.cpp:621
void argmax(Home home, const IntVarArgs &x, IntVar y, bool tiebreak, IntPropLevel)
Post propagator for .
Definition: arithmetic.cpp:110
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
Definition: arithmetic.cpp:585
virtual bool solution(const Assignment &x) const
Test whether x is solution
Definition: arithmetic.cpp:634
void sqrt(Home home, FloatVar x0, FloatVar x1)
Post propagator for .
Definition: arithmetic.cpp:102
@ IPL_DOM
Domain propagation Options: basic versus advanced propagation.
Definition: int.hh:979
Test for n-ary minimmum constraint with shared variables
Definition: arithmetic.cpp:696
virtual bool solution(const Assignment &x) const
Test whether x is solution
Definition: arithmetic.cpp:494
bool tiebreak
Whether to use tie-breaking.
Definition: arithmetic.cpp:942
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
Definition: arithmetic.cpp:688
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
Definition: arithmetic.cpp:439
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
Definition: arithmetic.cpp:165
virtual bool solution(const Assignment &x) const
Test whether x is solution
Definition: arithmetic.cpp:530
virtual bool solution(const Assignment &x) const
Test whether x is solution
Definition: arithmetic.cpp:178
const int max
Largest allowed integer value.
Definition: int.hh:116
MaxXXY(const std::string &s, const Gecode::IntSet &d, Gecode::IntPropLevel ipl)
Create and register test.
Definition: arithmetic.cpp:613
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
Definition: arithmetic.cpp:517
Create c
void mult(Home home, FloatVar x0, FloatVar x1, FloatVar x2)
Post propagator for .
Definition: arithmetic.cpp:88
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
MultXXY(const std::string &s, const Gecode::IntSet &d, Gecode::IntPropLevel ipl)
Create and register test.
Definition: arithmetic.cpp:75
Test for binary maximum constraint with shared variables
Definition: arithmetic.cpp:610
virtual bool solution(const Assignment &x) const
Test whether x is solution
Definition: arithmetic.cpp:912
virtual bool solution(const Assignment &x) const
Test whether x is solution
Definition: arithmetic.cpp:996
Iterator for simple integer propagation levels.
Definition: int.hh:332
Test for power constraint with shared variables
Definition: arithmetic.cpp:258
virtual bool solution(const Assignment &x) const
Test whether x is solution
Definition: arithmetic.cpp:738
virtual bool solution(const Assignment &x) const
Test whether x is solution
Definition: arithmetic.cpp:873
Gecode::FloatVal b(9, 12)
NrootXY(const std::string &s, int n0, const Gecode::IntSet &d, Gecode::IntPropLevel ipl)
Floor.
Definition: arithmetic.cpp:348
MinXYZ(const std::string &s, const Gecode::IntSet &d, Gecode::IntPropLevel ipl)
Create and register test.
Definition: arithmetic.cpp:509
ArgMax(int n, int o, bool tb)
Create and register test.
Definition: arithmetic.cpp:758
Test for square root constraint with shared variables
Definition: arithmetic.cpp:208
Gecode::IntSet d1(v1, 7)
virtual bool solution(const Assignment &x) const
Test whether x is solution
Definition: arithmetic.cpp:547
void abs(Home home, FloatVar x0, FloatVar x1)
Post propagator for .
Definition: arithmetic.cpp:41
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
Definition: arithmetic.cpp:742
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
Definition: arithmetic.cpp:126
Div(const std::string &s, const Gecode::IntSet &d)
Create and register test.
Definition: arithmetic.cpp:425
Base class for assignments
Definition: int.hh:59
Test for multiplication constraint with shared variables
Definition: arithmetic.cpp:112
void divmod(Home home, IntVar x0, IntVar x1, IntVar x2, IntVar x3, IntPropLevel)
Post propagator for .
Definition: arithmetic.cpp:327
MultXXX(const std::string &s, const Gecode::IntSet &d, Gecode::IntPropLevel ipl)
Create and register test.
Definition: arithmetic.cpp:135
int n
The root index.
Definition: arithmetic.cpp:344
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
Definition: arithmetic.cpp:655
void rel(Home home, FloatVar x0, FloatRelType frt, FloatVal n)
Propagates .
Definition: rel.cpp:43
NNF * l
Left subtree.
Definition: bool-expr.cpp:240
void abs(Home home, IntVar x0, IntVar x1, IntPropLevel ipl)
Post propagator for .
Definition: arithmetic.cpp:39
MinNaryShared(Gecode::IntPropLevel ipl)
Create and register test.
Definition: arithmetic.cpp:699
Gecode::IntSet d2(v2, 9)
ArgMaxBoolShared(int n, bool tb)
Create and register test.
Definition: arithmetic.cpp:945
SqrXY(const std::string &s, const Gecode::IntSet &d, Gecode::IntPropLevel ipl)
Create and register test.
Definition: arithmetic.cpp:155
@ IPL_DEF
Simple propagation levels.
Definition: int.hh:976
void mod(Home home, IntVar x0, IntVar x1, IntVar x2, IntPropLevel ipl)
Post propagator for .
Definition: arithmetic.cpp:360
virtual bool solution(const Assignment &x) const
Test whether x is solution
Definition: arithmetic.cpp:353
virtual bool solution(const Assignment &x) const
Test whether x is solution
Definition: arithmetic.cpp:237
Test for binary minimum constraint with shared variables
Definition: arithmetic.cpp:557
void nroot(Home home, IntVar x0, int n, IntVar x1, IntPropLevel ipl)
Post propagator for .
Definition: arithmetic.cpp:416
Test for binary minimum constraint with shared variables
Definition: arithmetic.cpp:574
Gecode::IntSet d(v, 7)
virtual bool solution(const Assignment &x) const
Test whether x is solution
Definition: arithmetic.cpp:59
void channel(Home home, FloatVar x0, IntVar x1)
Post propagator for channeling a float and an integer variable .
Definition: channel.cpp:41
virtual bool solution(const Assignment &x) const
Test whether x is solution
Definition: arithmetic.cpp:79
bool tiebreak
Whether to use tie-breaking.
Definition: arithmetic.cpp:903
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
Definition: arithmetic.cpp:86
MinXYX(const std::string &s, const Gecode::IntSet &d, Gecode::IntPropLevel ipl)
Create and register test.
Definition: arithmetic.cpp:543
bool powgr(int n, long long int r, int x)
Definition: arithmetic.cpp:285
virtual bool solution(const Assignment &x) const
Test whether x is solution
Definition: arithmetic.cpp:215
MaxXYX(const std::string &s, const Gecode::IntSet &d, Gecode::IntPropLevel ipl)
Create and register test.
Definition: arithmetic.cpp:630
AbsXX(const std::string &s, const Gecode::IntSet &d, Gecode::IntPropLevel ipl)
Create and register test.
Definition: arithmetic.cpp:490
int fnroot(int n, int x)
Definition: arithmetic.cpp:297
MultXYZ(const std::string &s, const Gecode::IntSet &d, Gecode::IntPropLevel ipl)
Create and register test.
Definition: arithmetic.cpp:55
virtual bool solution(const Assignment &x) const
Test whether x is solution
Definition: arithmetic.cpp:581
int offset
Which offset to use.
Definition: arithmetic.cpp:827
void max(Home home, const IntVarArgs &x, IntVar y, IntPropLevel ipl)
Post propagator for .
Definition: arithmetic.cpp:63
Test for argument minimum constraint
Definition: arithmetic.cpp:824
virtual bool solution(const Assignment &x) const
Test whether x is solution
Definition: arithmetic.cpp:564
General test support.
Definition: afc.cpp:39
bool tiebreak
Whether to use tie-breaking.
Definition: arithmetic.cpp:789
MaxXXX(const std::string &s, const Gecode::IntSet &d, Gecode::IntPropLevel ipl)
Create and register test.
Definition: arithmetic.cpp:664
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
const int min
Smallest allowed integer value.
Definition: int.hh:118
ArgMaxShared(int n, bool tb)
Create and register test.
Definition: arithmetic.cpp:792
Test for division/modulo constraint
Definition: arithmetic.cpp:399
@ IRT_EQ
Equality ( )
Definition: int.hh:926
Test for square root constraint
Definition: arithmetic.cpp:189
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
Definition: arithmetic.cpp:248
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
Definition: arithmetic.cpp:929
virtual bool solution(const Assignment &x) const
Test whether x is solution
Definition: arithmetic.cpp:119
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
Definition: arithmetic.cpp:362
void min(Home home, FloatVar x0, FloatVar x1, FloatVar x2)
Post propagator for .
Definition: arithmetic.cpp:67
Test for binary maximum constraint with shared variables
Definition: arithmetic.cpp:627
MinNary(Gecode::IntPropLevel ipl)
Create and register test.
Definition: arithmetic.cpp:681
int n
The exponent.
Definition: arithmetic.cpp:261
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
Definition: arithmetic.cpp:416
virtual bool solution(const Assignment &x) const
Test whether x is solution
Definition: arithmetic.cpp:513
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
Definition: arithmetic.cpp:638
Test for multiplication constraint with shared variables
Definition: arithmetic.cpp:92
virtual bool solution(const Assignment &x) const
Test whether x is solution
Definition: arithmetic.cpp:764
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
Definition: arithmetic.cpp:220
LDSB< TieBreak > tiebreak("TieBreak")
bool tiebreak
Whether to use tie-breaking.
Definition: arithmetic.cpp:829
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
Definition: arithmetic.cpp:776
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
Definition: arithmetic.cpp:462
SqrXX(const std::string &s, const Gecode::IntSet &d, Gecode::IntPropLevel ipl)
Create and register test.
Definition: arithmetic.cpp:174
Test for nroot constraint with shared variables
Definition: arithmetic.cpp:372
Passing integer arguments.
Definition: int.hh:628
Gecode::IntArgs i({1, 2, 3, 4})
virtual bool solution(const Assignment &x) const
Test whether x is solution
Definition: arithmetic.cpp:410
bool tiebreak
Whether to use tie-breaking.
MultXYY(const std::string &s, const Gecode::IntSet &d, Gecode::IntPropLevel ipl)
Create and register test.
Definition: arithmetic.cpp:115
int p
Number of positive literals for node type.
Definition: bool-expr.cpp:232
Test for binary minimum constraint
Definition: arithmetic.cpp:506
Mod(const std::string &s, const Gecode::IntSet &d)
Create and register test.
Definition: arithmetic.cpp:448
Test for power constraint
Definition: arithmetic.cpp:226
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
Definition: arithmetic.cpp:850
ArgMinBoolShared(int n, bool tb)
Create and register test.
void sqrt(Home home, IntVar x0, IntVar x1, IntPropLevel ipl)
Post propagator for .
Definition: arithmetic.cpp:383
static std::string str(Gecode::IntPropLevel ipl)
Map integer propagation level to string.
Definition: int.hpp:209