Generated on Sat May 25 2013 18:00:33 for Gecode by doxygen 1.8.3.1
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  * Vincent Barichard <Vincent.Barichard@univ-angers.fr>
6  *
7  * Copyright:
8  * Christian Schulte, 2005
9  * Vincent Barichard, 2012
10  *
11  * Last modified:
12  * $Date: 2013-02-04 22:41:43 +0100 (Mon, 04 Feb 2013) $ by $Author: schulte $
13  * $Revision: 13264 $
14  *
15  * This file is part of Gecode, the generic constraint
16  * development environment:
17  * http://www.gecode.org
18  *
19  * Permission is hereby granted, free of charge, to any person obtaining
20  * a copy of this software and associated documentation files (the
21  * "Software"), to deal in the Software without restriction, including
22  * without limitation the rights to use, copy, modify, merge, publish,
23  * distribute, sublicense, and/or sell copies of the Software, and to
24  * permit persons to whom the Software is furnished to do so, subject to
25  * the following conditions:
26  *
27  * The above copyright notice and this permission notice shall be
28  * included in all copies or substantial portions of the Software.
29  *
30  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
31  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
32  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
33  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
34  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
35  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
36  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
37  *
38  */
39 
40 #include "test/float.hh"
41 
42 #include <gecode/minimodel.hh>
43 
44 #include <cmath>
45 #include <algorithm>
46 
47 namespace Test { namespace Float {
48 
50  namespace Arithmetic {
51 
57 
58  class MultXYZ : public Test {
59  public:
61  MultXYZ(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st)
62  : Test("Arithmetic::Mult::XYZ::"+s,3,d,st,CPLT_ASSIGNMENT,false) {}
64  virtual MaybeType solution(const Assignment& x) const {
65  return eq(x[0] * x[1], x[2]);
66  }
68  virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
69  if (flip())
70  Gecode::mult(home, x[0], x[1], x[2]);
71  else
72  Gecode::rel(home, x[0] * x[1] == x[2]);
73  }
74  };
75 
77  class MultXYZSol : public Test {
78  public:
80  MultXYZSol(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st)
81  : Test("Arithmetic::Mult::XYZ::Sol::"+s,3,d,st,EXTEND_ASSIGNMENT,false) {}
83  virtual MaybeType solution(const Assignment& x) const {
84  return eq(x[0] * x[1], x[2]);
85  }
87  virtual bool extendAssignement(Assignment& x) const {
88  Gecode::FloatVal d = x[0]*x[1];
89  if (Gecode::Float::subset(d, dom)) {
90  x.set(2, d);
91  return true;
92  } else {
93  return false;
94  }
95  }
97  virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
98  Gecode::mult(home, x[0], x[1], x[2]);
99  }
100  };
101 
103  class MultXXY : public Test {
104  public:
106  MultXXY(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st)
107  : Test("Arithmetic::Mult::XXY::"+s,2,d,st,CPLT_ASSIGNMENT,false) {}
109  virtual MaybeType solution(const Assignment& x) const {
110  return eq(x[0] * x[0], x[1]);
111  }
113  virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
114  Gecode::mult(home, x[0], x[0], x[1]);
115  }
116  };
117 
119  class MultXXYSol : public Test {
120  public:
122  MultXXYSol(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st)
123  : Test("Arithmetic::Mult::XXY::Sol::"+s,2,d,st,EXTEND_ASSIGNMENT,false) {}
125  virtual MaybeType solution(const Assignment& x) const {
126  return eq(x[0] * x[0], x[1]);
127  }
129  virtual bool extendAssignement(Assignment& x) const {
130  Gecode::FloatVal d = x[0]*x[0];
131  if (Gecode::Float::subset(d, dom)) {
132  x.set(1, d);
133  return true;
134  } else {
135  return false;
136  }
137  }
139  virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
140  Gecode::mult(home, x[0], x[0], x[1]);
141  }
142  };
143 
145  class MultXYX : public Test {
146  public:
148  MultXYX(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st)
149  : Test("Arithmetic::Mult::XYX::"+s,2,d,st,CPLT_ASSIGNMENT,false) {}
151  virtual MaybeType solution(const Assignment& x) const {
152  return eq(x[0] * x[1], x[0]);
153  }
155  virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
156  Gecode::mult(home, x[0], x[1], x[0]);
157  }
158  };
159 
161  class MultXYY : public Test {
162  public:
164  MultXYY(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st)
165  : Test("Arithmetic::Mult::XYY::"+s,2,d,st,CPLT_ASSIGNMENT,false) {}
167  virtual MaybeType solution(const Assignment& x) const {
168  return eq(x[0] * x[1], x[1]);
169  }
171  virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
172  Gecode::mult(home, x[0], x[1], x[1]);
173  }
174  };
175 
177  class MultXXX : public Test {
178  public:
180  MultXXX(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st)
181  : Test("Arithmetic::Mult::XXX::"+s,1,d,st,CPLT_ASSIGNMENT,false) {}
183  virtual MaybeType solution(const Assignment& x) const {
184  return eq(x[0] * x[0], x[0]);
185  }
187  virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
188  Gecode::mult(home, x[0], x[0], x[0]);
189  }
190  };
191 
193  class Div : public Test {
194  public:
196  Div(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st)
197  : Test("Arithmetic::Div::"+s,3,d,st,CPLT_ASSIGNMENT,false) {}
199  virtual MaybeType solution(const Assignment& x) const {
200  return eq(x[0] / x[1], x[2]);
201  }
203  virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
204  if (flip())
205  Gecode::div(home, x[0], x[1], x[2]);
206  else
207  Gecode::rel(home, x[0] / x[1] == x[2]);
208  }
209  };
210 
212  class DivSol : public Test {
213  public:
215  DivSol(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st)
216  : Test("Arithmetic::Div::Sol::"+s,3,d,st,EXTEND_ASSIGNMENT,false) {}
218  virtual MaybeType solution(const Assignment& x) const {
219  return eq(x[0] / x[1], x[2]);
220  }
222  virtual bool extendAssignement(Assignment& x) const {
223  Gecode::FloatVal d = x[0]/x[1];
224  if (Gecode::Float::subset(d, dom)) {
225  x.set(2, d);
226  return true;
227  } else {
228  return false;
229  }
230  }
232  virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
233  Gecode::div(home, x[0], x[1], x[2]);
234  }
235  };
236 
238  class SqrXY : public Test {
239  public:
241  SqrXY(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st)
242  : Test("Arithmetic::Sqr::XY::"+s,2,d,st,CPLT_ASSIGNMENT,false) {}
244  virtual MaybeType solution(const Assignment& x) const {
245  return eq(x[0] * x[0], x[1]);
246  }
248  virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
249  if (flip())
250  Gecode::sqr(home, x[0], x[1]);
251  else
252  Gecode::rel(home, sqr(x[0]) == x[1]);
253  }
254  };
255 
257  class SqrXYSol : public Test {
258  public:
260  SqrXYSol(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st)
261  : Test("Arithmetic::Sqr::XY::Sol::"+s,2,d,st,EXTEND_ASSIGNMENT,false) {}
263  virtual MaybeType solution(const Assignment& x) const {
264  return eq(x[0] * x[0], x[1]);
265  }
267  virtual bool extendAssignement(Assignment& x) const {
268  Gecode::FloatVal d = sqr(x[0]);
269  if (Gecode::Float::subset(d, dom)) {
270  x.set(1, d);
271  return true;
272  } else {
273  return false;
274  }
275  }
277  virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
278  Gecode::sqr(home, x[0], x[1]);
279  }
280  };
281 
283  class SqrXX : public Test {
284  public:
286  SqrXX(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st)
287  : Test("Arithmetic::Sqr::XX::"+s,1,d,st,CPLT_ASSIGNMENT,false) {}
289  virtual MaybeType solution(const Assignment& x) const {
290  return eq(x[0] * x[0], x[0]);
291  }
293  virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
294  Gecode::sqr(home, x[0], x[0]);
295  }
296  };
297 
299  class SqrtXY : public Test {
300  public:
302  SqrtXY(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st)
303  : Test("Arithmetic::Sqrt::XY::"+s,2,d,st,CPLT_ASSIGNMENT,false) {}
305  virtual MaybeType solution(const Assignment& x) const {
306  switch (cmp(x[0], Gecode::FRT_GQ, 0.0)) {
307  case MT_FALSE: return MT_FALSE;
308  case MT_MAYBE: return MT_MAYBE;
309  default:
310  return eq(sqrt(x[0]), x[1]);
311  }
312  }
314  virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
315  if (flip())
316  Gecode::sqrt(home, x[0], x[1]);
317  else
318  Gecode::rel(home, sqrt(x[0]) == x[1]);
319  }
320  };
321 
323  class SqrtXYSol : public Test {
324  public:
326  SqrtXYSol(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st)
327  : Test("Arithmetic::Sqrt::XY::Sol::"+s,2,d,st,EXTEND_ASSIGNMENT,false) {}
329  virtual MaybeType solution(const Assignment& x) const {
330  switch (cmp(x[0], Gecode::FRT_GQ, 0.0)) {
331  case MT_FALSE: return MT_FALSE;
332  case MT_MAYBE: return MT_MAYBE;
333  default:
334  return eq(sqrt(x[0]), x[1]);
335  }
336  }
338  virtual bool extendAssignement(Assignment& x) const {
339  Gecode::FloatVal d = sqrt(abs(x[0]));
340  if (Gecode::Float::subset(d, dom)) {
341  x.set(1, d);
342  return true;
343  } else {
344  return false;
345  }
346  }
348  virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
349  Gecode::sqrt(home, x[0], x[1]);
350  }
351  };
352 
354  class SqrtXX : public Test {
355  public:
357  SqrtXX(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st)
358  : Test("Arithmetic::Sqrt::XX::"+s,1,d,st,CPLT_ASSIGNMENT,false) {}
360  virtual MaybeType solution(const Assignment& x) const {
361  switch (cmp(x[0], Gecode::FRT_GQ, 0.0)) {
362  case MT_FALSE: return MT_FALSE;
363  case MT_MAYBE: return MT_MAYBE;
364  default:
365  return eq(sqrt(x[0]), x[0]);
366  }
367  }
369  virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
370  Gecode::sqrt(home, x[0], x[0]);
371  }
372  };
373 
375  class PowXY : public Test {
376  unsigned int n;
377  public:
379  PowXY(const std::string& s, const Gecode::FloatVal& d, unsigned int _n, Gecode::FloatNum st)
380  : Test("Arithmetic::Pow::N::"+str(_n)+"::XY::"+s,2,d,st,CPLT_ASSIGNMENT,false), n(_n) {}
382  virtual MaybeType solution(const Assignment& x) const {
383  return eq(pow(x[0],n), x[1]);
384  }
386  virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
387  if (flip())
388  Gecode::pow(home, x[0], n, x[1]);
389  else
390  Gecode::rel(home, pow(x[0],n) == x[1]);
391  }
392  };
393 
395  class PowXYSol : public Test {
396  unsigned int n;
397  public:
399  PowXYSol(const std::string& s, const Gecode::FloatVal& d, unsigned int _n, Gecode::FloatNum st)
400  : Test("Arithmetic::Pow::N::"+str(_n)+"::XY::Sol::"+s,2,d,st,EXTEND_ASSIGNMENT,false), n(_n) {}
402  virtual MaybeType solution(const Assignment& x) const {
403  return eq(pow(x[0],n), x[1]);
404  }
406  virtual bool extendAssignement(Assignment& x) const {
407  Gecode::FloatVal d = pow(x[0],n);
408  if (Gecode::Float::subset(d, dom)) {
409  x.set(1, d);
410  return true;
411  } else {
412  return false;
413  }
414  }
416  virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
417  Gecode::pow(home, x[0], n, x[1]);
418  }
419  };
420 
422  class PowXX : public Test {
423  unsigned int n;
424  public:
426  PowXX(const std::string& s, const Gecode::FloatVal& d, unsigned int _n, Gecode::FloatNum st)
427  : Test("Arithmetic::Pow::N::"+str(_n)+"::XX::"+s,1,d,st,CPLT_ASSIGNMENT,false) {}
429  virtual MaybeType solution(const Assignment& x) const {
430  return eq(pow(x[0],n), x[0]);
431  }
433  virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
434  Gecode::pow(home, x[0], n, x[0]);
435  }
436  };
437 
439  class NRootXY : public Test {
440  unsigned int n;
441  public:
443  NRootXY(const std::string& s, const Gecode::FloatVal& d, unsigned int _n, Gecode::FloatNum st)
444  : Test("Arithmetic::NRoot::N::"+str(_n)+"::XY::"+s,2,d,st,CPLT_ASSIGNMENT,false), n(_n) {}
446  virtual MaybeType solution(const Assignment& x) const {
447  if ((n == 0) || (x[0].max() < 0.0))
448  return MT_FALSE;
449  return eq(nroot(x[0],n), x[1]);
450  }
452  virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
453  if (flip())
454  Gecode::nroot(home, x[0], n, x[1]);
455  else
456  Gecode::rel(home, nroot(x[0],n) == x[1]);
457  }
458  };
459 
461  class NRootXYSol : public Test {
462  unsigned int n;
463  public:
465  NRootXYSol(const std::string& s, const Gecode::FloatVal& d, unsigned int _n, Gecode::FloatNum st)
466  : Test("Arithmetic::NRoot::N::"+str(_n)+"::XY::Sol::"+s,2,d,st,EXTEND_ASSIGNMENT,false), n(_n) {}
468  virtual MaybeType solution(const Assignment& x) const {
469  if ((n == 0) || (x[0].max() < 0.0))
470  return MT_FALSE;
471  return eq(nroot(x[0],n), x[1]);
472  }
474  virtual bool extendAssignement(Assignment& x) const {
475  if ((n == 0) || (x[0].max() < 0))
476  return false;
477  Gecode::FloatVal d = nroot(x[0],n);
478  if (Gecode::Float::subset(d, dom)) {
479  x.set(1, d);
480  return true;
481  } else {
482  return false;
483  }
484  }
486  virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
487  Gecode::nroot(home, x[0], n, x[1]);
488  }
489  };
490 
492  class NRootXX : public Test {
493  unsigned int n;
494  public:
496  NRootXX(const std::string& s, const Gecode::FloatVal& d, unsigned int _n, Gecode::FloatNum st)
497  : Test("Arithmetic::NRoot::N::"+str(_n)+"::XX::"+s,1,d,st,CPLT_ASSIGNMENT,false) {}
499  virtual MaybeType solution(const Assignment& x) const {
500  if ((n == 0) || (x[0].max() < 0))
501  return MT_FALSE;
502  return eq(nroot(x[0],n), x[0]);
503  }
505  virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
506  Gecode::nroot(home, x[0], n, x[0]);
507  }
508  };
509 
511  class AbsXY : public Test {
512  public:
514  AbsXY(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st)
515  : Test("Arithmetic::Abs::XY::"+s,2,d,st,CPLT_ASSIGNMENT,false) {}
517  virtual MaybeType solution(const Assignment& x) const {
518  return eq(abs(x[0]), x[1]);
519  }
521  virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
522  if (flip())
523  Gecode::abs(home, x[0], x[1]);
524  else
525  Gecode::rel(home, abs(x[0]) == x[1]);
526  }
527  };
528 
530  class AbsXX : public Test {
531  public:
533  AbsXX(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st)
534  : Test("Arithmetic::Abs::XX::"+s,1,d,st,CPLT_ASSIGNMENT,false) {}
536  virtual MaybeType solution(const Assignment& x) const {
537  return eq(abs(x[0]), x[0]);
538  }
540  virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
541  Gecode::abs(home, x[0], x[0]);
542  }
543  };
544 
546  class MinXYZ : public Test {
547  public:
549  MinXYZ(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st)
550  : Test("Arithmetic::Min::Bin::XYZ::"+s,3,d,st,CPLT_ASSIGNMENT,false) {}
552  virtual MaybeType solution(const Assignment& x) const {
553  return eq(min(x[0],x[1]), x[2]);
554  }
556  virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
557  if (flip())
558  Gecode::min(home, x[0], x[1], x[2]);
559  else
560  Gecode::rel(home, min(x[0],x[1]) == x[2]);
561  }
562  };
563 
565  class MinXXY : public Test {
566  public:
568  MinXXY(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st)
569  : Test("Arithmetic::Min::Bin::XXY::"+s,2,d,st,CPLT_ASSIGNMENT,false) {}
571  virtual MaybeType solution(const Assignment& x) const {
572  return eq(min(x[0],x[0]), x[1]);
573  }
575  virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
576  Gecode::min(home, x[0], x[0], x[1]);
577  }
578  };
579 
581  class MinXYX : public Test {
582  public:
584  MinXYX(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st)
585  : Test("Arithmetic::Min::Bin::XYX::"+s,2,d,st,CPLT_ASSIGNMENT,false) {}
587  virtual MaybeType solution(const Assignment& x) const {
588  return eq(min(x[0],x[1]), x[0]);
589  }
591  virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
592  Gecode::min(home, x[0], x[1], x[0]);
593  }
594  };
595 
597  class MinXYY : public Test {
598  public:
600  MinXYY(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st)
601  : Test("Arithmetic::Min::Bin::XYY::"+s,2,d,st,CPLT_ASSIGNMENT,false) {}
603  virtual MaybeType solution(const Assignment& x) const {
604  return eq(min(x[0],x[1]), x[1]);
605  }
607  virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
608  Gecode::min(home, x[0], x[1], x[1]);
609  }
610  };
611 
613  class MinXXX : public Test {
614  public:
616  MinXXX(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st)
617  : Test("Arithmetic::Min::Bin::XXX::"+s,1,d,st,CPLT_ASSIGNMENT,false) {}
619  virtual MaybeType solution(const Assignment& x) const {
620  return eq(min(x[0],x[0]), x[0]);
621  }
623  virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
624  Gecode::min(home, x[0], x[0], x[0]);
625  }
626  };
627 
629  class MaxXYZ : public Test {
630  public:
632  MaxXYZ(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st)
633  : Test("Arithmetic::Max::Bin::XYZ::"+s,3,d,st,CPLT_ASSIGNMENT,false) {}
635  virtual MaybeType solution(const Assignment& x) const {
636  return eq(max(x[0],x[1]), x[2]);
637  }
639  virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
640  if (flip())
641  Gecode::max(home, x[0], x[1], x[2]);
642  else
643  Gecode::rel(home, max(x[0], x[1]) == x[2]);
644  }
645  };
646 
648  class MaxXXY : public Test {
649  public:
651  MaxXXY(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st)
652  : Test("Arithmetic::Max::Bin::XXY::"+s,2,d,st,CPLT_ASSIGNMENT,false) {}
654  virtual MaybeType solution(const Assignment& x) const {
655  return eq(max(x[0],x[0]), x[1]);
656  }
658  virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
659  Gecode::max(home, x[0], x[0], x[1]);
660  }
661  };
662 
664  class MaxXYX : public Test {
665  public:
667  MaxXYX(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st)
668  : Test("Arithmetic::Max::Bin::XYX::"+s,2,d,st,CPLT_ASSIGNMENT,false) {}
670  virtual MaybeType solution(const Assignment& x) const {
671  return eq(max(x[0],x[1]), x[0]);
672  }
674  virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
675  Gecode::max(home, x[0], x[1], x[0]);
676  }
677  };
678 
680  class MaxXYY : public Test {
681  public:
683  MaxXYY(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st)
684  : Test("Arithmetic::Max::Bin::XYY::"+s,2,d,st,CPLT_ASSIGNMENT,false) {}
686  virtual MaybeType solution(const Assignment& x) const {
687  return eq(max(x[0],x[1]), x[1]);
688  }
690  virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
691  Gecode::max(home, x[0], x[1], x[1]);
692  }
693  };
694 
696  class MaxXXX : public Test {
697  public:
699  MaxXXX(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st)
700  : Test("Arithmetic::Max::Bin::XXX::"+s,1,d,st,CPLT_ASSIGNMENT,false) {}
702  virtual MaybeType solution(const Assignment& x) const {
703  return eq(max(x[0],x[0]), x[0]);
704  }
706  virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
707  Gecode::max(home, x[0], x[0], x[0]);
708  }
709  };
710 
712  class MinNary : public Test {
713  public:
715  MinNary(void)
716  : Test("Arithmetic::Min::Nary",4,-4,4,0.5,CPLT_ASSIGNMENT,false) {}
718  virtual MaybeType solution(const Assignment& x) const {
719  return eq(min(min(x[0],x[1]),x[2]), x[3]);
720  }
722  virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
724  m[0]=x[0]; m[1]=x[1]; m[2]=x[2];
725  if (flip())
726  Gecode::min(home, m, x[3]);
727  else
728  Gecode::rel(home, min(m) == x[3]);
729  }
730  };
731 
733  class MinNaryShared : public Test {
734  public:
737  : Test("Arithmetic::Min::Nary::Shared",3,-4,4,0.5,CPLT_ASSIGNMENT,false) {}
739  virtual MaybeType solution(const Assignment& x) const {
740  return eq(min(min(x[0],x[1]),x[2]), x[1]);
741  }
743  virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
745  m[0]=x[0]; m[1]=x[1]; m[2]=x[2];
746  Gecode::min(home, m, x[1]);
747  }
748  };
749 
751  class MaxNary : public Test {
752  public:
754  MaxNary(void)
755  : Test("Arithmetic::Max::Nary",4,-4,4,0.5,CPLT_ASSIGNMENT,false) {}
757  virtual MaybeType solution(const Assignment& x) const {
758  return eq(max(max(x[0],x[1]),x[2]), x[3]);
759  }
761  virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
763  m[0]=x[0]; m[1]=x[1]; m[2]=x[2];
764  if (flip())
765  Gecode::max(home, m, x[3]);
766  else
767  Gecode::rel(home, max(m) == x[3]);
768  }
769  };
770 
772  class MaxNaryShared : public Test {
773  public:
776  : Test("Arithmetic::Max::Nary::Shared",3,-4,4,0.5,CPLT_ASSIGNMENT,false) {}
778  virtual MaybeType solution(const Assignment& x) const {
779  return eq(max(max(x[0],x[1]),x[2]), x[1]);
780  }
782  virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
784  m[0]=x[0]; m[1]=x[1]; m[2]=x[2];
785  Gecode::max(home, m, x[1]);
786  }
787  };
788 
789  const Gecode::FloatNum step = 0.15;
791  Gecode::FloatVal a(-8,5);
792  Gecode::FloatVal b(9,12);
793  Gecode::FloatVal c(-8,8);
794 
795  MultXXY mult_xxy_a("A",a,step);
796  MultXXY mult_xxy_b("B",b,step);
797  MultXXY mult_xxy_c("C",c,step);
798 
802 
803  MultXYX mult_xyx_a("A",a,step);
804  MultXYX mult_xyx_b("B",b,step);
805  MultXYX mult_xyx_c("C",c,step);
806 
807  MultXYY mult_xyy_a("A",a,step);
808  MultXYY mult_xyy_b("B",b,step);
809  MultXYY mult_xyy_c("C",c,step);
810 
811  MultXXX mult_xxx_a("A",a,step);
812  MultXXX mult_xxx_b("B",b,step);
813  MultXXX mult_xxx_c("C",c,step);
814 
815  MultXYZ mult_xyz_a("A",a,step);
816  MultXYZ mult_xyz_b("B",b,step);
817  MultXYZ mult_xyz_c("C",c,step);
818 
822 
823  Div div_a("A",a,step);
824  Div div_b("B",b,step);
825  Div div_c("C",c,step);
826 
827  DivSol div_sol_a("A",a,step);
828  DivSol div_sol_b("B",b,step);
829  DivSol div_sol_c("C",c,step);
830 
831  SqrXY sqr_xy_a("A",a,step);
832  SqrXY sqr_xy_b("B",b,step);
833  SqrXY sqr_xy_c("C",c,step);
834 
838 
839  SqrXX sqr_xx_a("A",a,step);
840  SqrXX sqr_xx_b("B",b,step);
841  SqrXX sqr_xx_c("C",c,step);
842 
843  SqrtXY sqrt_xy_a("A",a,step);
844  SqrtXY sqrt_xy_b("B",b,step);
845  SqrtXY sqrt_xy_c("C",c,step);
846 
850 
851  SqrtXX sqrt_xx_a("A",a,step);
852  SqrtXX sqrt_xx_b("B",b,step);
853  SqrtXX sqrt_xx_c("C",c,step);
854 
855  PowXY pow_xy_a_1("A",a,2,step);
856  PowXY pow_xy_b_1("B",b,2,step);
857  PowXY pow_xy_c_1("C",c,2,step);
858 
859  PowXYSol pow_xy_sol_a_1("A",a,2,step);
860  PowXYSol pow_xy_sol_b_1("B",b,2,step);
861  PowXYSol pow_xy_sol_c_1("C",c,2,step);
862 
863  PowXX pow_xx_a_1("A",a,2,step);
864  PowXX pow_xx_b_1("B",b,2,step);
865  PowXX pow_xx_c_1("C",c,2,step);
866 
867  PowXY pow_xy_a_2("A",a,3,step);
868  PowXY pow_xy_b_2("B",b,3,step);
869  PowXY pow_xy_c_2("C",c,3,step);
870 
871  PowXYSol pow_xy_sol_a_2("A",a,3,step);
872  PowXYSol pow_xy_sol_b_2("B",b,3,step);
873  PowXYSol pow_xy_sol_c_2("C",c,3,step);
874 
875  PowXX pow_xx_a_2("A",a,3,step);
876  PowXX pow_xx_b_2("B",b,3,step);
877  PowXX pow_xx_c_2("C",c,3,step);
878 
879  PowXY pow_xy_a_3("A",a,0,step);
880  PowXY pow_xy_b_3("B",b,0,step);
881  PowXY pow_xy_c_3("C",c,0,step);
882 
883  PowXYSol pow_xy_sol_a_3("A",a,0,step);
884  PowXYSol pow_xy_sol_b_3("B",b,0,step);
885  PowXYSol pow_xy_sol_c_3("C",c,0,step);
886 
887  PowXX pow_xx_a_3("A",a,0,step);
888  PowXX pow_xx_b_3("B",b,0,step);
889  PowXX pow_xx_c_3("C",c,0,step);
890 
891  NRootXY nroot_xy_a_1("A",a,2,step);
892  NRootXY nroot_xy_b_1("B",b,2,step);
893  NRootXY nroot_xy_c_1("C",c,2,step);
894 
898 
899  NRootXX nroot_xx_a_1("A",a,2,step);
900  NRootXX nroot_xx_b_1("B",b,2,step);
901  NRootXX nroot_xx_c_1("C",c,2,step);
902 
903  NRootXY nroot_xy_a_2("A",a,3,step);
904  NRootXY nroot_xy_b_2("B",b,3,step);
905  NRootXY nroot_xy_c_2("C",c,3,step);
906 
910 
911  NRootXX nroot_xx_a_2("A",a,3,step);
912  NRootXX nroot_xx_b_2("B",b,3,step);
913  NRootXX nroot_xx_c_2("C",c,3,step);
914 
915  NRootXY nroot_xy_a_3("A",a,0,step);
916  NRootXY nroot_xy_b_3("B",b,0,step);
917  NRootXY nroot_xy_c_3("C",c,0,step);
918 
922 
923  NRootXX nroot_xx_a_3("A",a,0,step);
924  NRootXX nroot_xx_b_3("B",b,0,step);
925  NRootXX nroot_xx_c_3("C",c,0,step);
926 
927  AbsXY abs_xy_a("A",a,step);
928  AbsXY abs_xy_b("B",b,step);
929  AbsXY abs_xy_c("C",c,step);
930 
931  AbsXX abs_xx_a("A",a,step);
932  AbsXX abs_xx_b("B",b,step);
933  AbsXX abs_xx_c("C",c,step);
934 
935  MinXYZ min_xyz_a("A",a,step);
936  MinXYZ min_xyz_b("B",b,step);
937  MinXYZ min_xyz_c("C",c,step);
938 
939  MinXXY min_xxy_a("A",a,step);
940  MinXXY min_xxy_b("B",b,step);
941  MinXXY min_xxy_c("C",c,step);
942 
943  MinXYX min_xyx_a("A",a,step);
944  MinXYX min_xyx_b("B",b,step);
945  MinXYX min_xyx_c("C",c,step);
946 
947  MinXYY min_xyy_a("A",a,step);
948  MinXYY min_xyy_b("B",b,step);
949  MinXYY min_xyy_c("C",c,step);
950 
951  MinXXX min_xxx_a("A",a,step);
952  MinXXX min_xxx_b("B",b,step);
953  MinXXX min_xxx_c("C",c,step);
954 
955  MaxXYZ max_xyz_a("A",a,step);
956  MaxXYZ max_xyz_b("B",b,step);
957  MaxXYZ max_xyz_c("C",c,step);
958 
959  MaxXXY max_xxy_a("A",a,step);
960  MaxXXY max_xxy_b("B",b,step);
961  MaxXXY max_xxy_c("C",c,step);
962 
963  MaxXYX max_xyx_a("A",a,step);
964  MaxXYX max_xyx_b("B",b,step);
965  MaxXYX max_xyx_c("C",c,step);
966 
967  MaxXYY max_xyy_a("A",a,step);
968  MaxXYY max_xyy_b("B",b,step);
969  MaxXYY max_xyy_c("C",c,step);
970 
971  MaxXXX max_xxx_a("A",a,step);
972  MaxXXX max_xxx_b("B",b,step);
973  MaxXXX max_xxx_c("C",c,step);
974 
980 
981  }
982 }}
983 
984 // STATISTICS: test-float