Generated on Fri Mar 20 15:55:56 2015 for Gecode by doxygen 1.6.3

arithmetic.cpp

Go to the documentation of this file.
00001 /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
00002 /*
00003  *  Main authors:
00004  *     Christian Schulte <schulte@gecode.org>
00005  *     Vincent Barichard <Vincent.Barichard@univ-angers.fr>
00006  *
00007  *  Copyright:
00008  *     Christian Schulte, 2005
00009  *     Vincent Barichard, 2012
00010  *
00011  *  Last modified:
00012  *     $Date: 2013-02-04 22:41:43 +0100 (Mon, 04 Feb 2013) $ by $Author: schulte $
00013  *     $Revision: 13264 $
00014  *
00015  *  This file is part of Gecode, the generic constraint
00016  *  development environment:
00017  *     http://www.gecode.org
00018  *
00019  *  Permission is hereby granted, free of charge, to any person obtaining
00020  *  a copy of this software and associated documentation files (the
00021  *  "Software"), to deal in the Software without restriction, including
00022  *  without limitation the rights to use, copy, modify, merge, publish,
00023  *  distribute, sublicense, and/or sell copies of the Software, and to
00024  *  permit persons to whom the Software is furnished to do so, subject to
00025  *  the following conditions:
00026  *
00027  *  The above copyright notice and this permission notice shall be
00028  *  included in all copies or substantial portions of the Software.
00029  *
00030  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00031  *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00032  *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00033  *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
00034  *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
00035  *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00036  *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00037  *
00038  */
00039 
00040 #include "test/float.hh"
00041 
00042 #include <gecode/minimodel.hh>
00043 
00044 #include <cmath>
00045 #include <algorithm>
00046 
00047 namespace Test { namespace Float {
00048 
00050    namespace Arithmetic {
00051 
00057 
00058      class MultXYZ : public Test {
00059      public:
00061        MultXYZ(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st)
00062          : Test("Arithmetic::Mult::XYZ::"+s,3,d,st,CPLT_ASSIGNMENT,false) {}
00064        virtual MaybeType solution(const Assignment& x) const {
00065          return eq(x[0] * x[1], x[2]);
00066        }
00068        virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
00069          if (flip())
00070            Gecode::mult(home, x[0], x[1], x[2]);
00071          else
00072            Gecode::rel(home, x[0] * x[1] == x[2]);
00073        }
00074      };
00075 
00077      class MultXYZSol : public Test {
00078      public:
00080        MultXYZSol(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st)
00081          : Test("Arithmetic::Mult::XYZ::Sol::"+s,3,d,st,EXTEND_ASSIGNMENT,false) {}
00083        virtual MaybeType solution(const Assignment& x) const {
00084          return eq(x[0] * x[1], x[2]);
00085        }
00087        virtual bool extendAssignement(Assignment& x) const {
00088          Gecode::FloatVal d = x[0]*x[1];
00089          if (Gecode::Float::subset(d, dom)) {
00090            x.set(2, d);
00091            return true;
00092          } else {
00093            return false;
00094          }
00095        }
00097        virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
00098          Gecode::mult(home, x[0], x[1], x[2]);
00099        }
00100      };
00101      
00103      class MultXXY : public Test {
00104      public:
00106        MultXXY(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st)
00107          : Test("Arithmetic::Mult::XXY::"+s,2,d,st,CPLT_ASSIGNMENT,false) {}
00109        virtual MaybeType solution(const Assignment& x) const {
00110          return eq(x[0] * x[0], x[1]);
00111        }
00113        virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
00114          Gecode::mult(home, x[0], x[0], x[1]);
00115        }
00116      };
00117 
00119      class MultXXYSol : public Test {
00120      public:
00122        MultXXYSol(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st)
00123        : Test("Arithmetic::Mult::XXY::Sol::"+s,2,d,st,EXTEND_ASSIGNMENT,false) {}
00125        virtual MaybeType solution(const Assignment& x) const {
00126          return eq(x[0] * x[0], x[1]);
00127        }
00129        virtual bool extendAssignement(Assignment& x) const {
00130          Gecode::FloatVal d = x[0]*x[0];
00131          if (Gecode::Float::subset(d, dom)) {
00132            x.set(1, d);
00133            return true;
00134          } else {
00135            return false;
00136          }
00137        }
00139        virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
00140          Gecode::mult(home, x[0], x[0], x[1]);
00141        }
00142      };
00143      
00145      class MultXYX : public Test {
00146      public:
00148        MultXYX(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st)
00149          : Test("Arithmetic::Mult::XYX::"+s,2,d,st,CPLT_ASSIGNMENT,false) {}
00151        virtual MaybeType solution(const Assignment& x) const {
00152          return eq(x[0] * x[1], x[0]);
00153        }
00155        virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
00156          Gecode::mult(home, x[0], x[1], x[0]);
00157        }
00158      };
00159 
00161      class MultXYY : public Test {
00162      public:
00164        MultXYY(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st)
00165          : Test("Arithmetic::Mult::XYY::"+s,2,d,st,CPLT_ASSIGNMENT,false) {}
00167        virtual MaybeType solution(const Assignment& x) const {
00168          return eq(x[0] * x[1], x[1]);
00169        }
00171        virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
00172          Gecode::mult(home, x[0], x[1], x[1]);
00173        }
00174      };
00175 
00177      class MultXXX : public Test {
00178      public:
00180        MultXXX(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st)
00181          : Test("Arithmetic::Mult::XXX::"+s,1,d,st,CPLT_ASSIGNMENT,false) {}
00183        virtual MaybeType solution(const Assignment& x) const {
00184          return eq(x[0] * x[0], x[0]);
00185        }
00187        virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
00188          Gecode::mult(home, x[0], x[0], x[0]);
00189        }
00190      };
00191      
00193      class Div : public Test {
00194      public:
00196        Div(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st)
00197        : Test("Arithmetic::Div::"+s,3,d,st,CPLT_ASSIGNMENT,false) {}
00199        virtual MaybeType solution(const Assignment& x) const {
00200          return eq(x[0] / x[1], x[2]);
00201        }
00203        virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
00204          if (flip())
00205            Gecode::div(home, x[0], x[1], x[2]);
00206          else
00207            Gecode::rel(home, x[0] / x[1] == x[2]);
00208        }
00209      };
00210      
00212      class DivSol : public Test {
00213      public:
00215        DivSol(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st)
00216        : Test("Arithmetic::Div::Sol::"+s,3,d,st,EXTEND_ASSIGNMENT,false) {}
00218        virtual MaybeType solution(const Assignment& x) const {
00219          return eq(x[0] / x[1], x[2]);
00220        }
00222        virtual bool extendAssignement(Assignment& x) const {
00223          Gecode::FloatVal d = x[0]/x[1];
00224          if (Gecode::Float::subset(d, dom)) {
00225            x.set(2, d);
00226            return true;
00227          } else {
00228            return false;
00229          }
00230        }
00232        virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
00233          Gecode::div(home, x[0], x[1], x[2]);
00234        }
00235      };
00236      
00238      class SqrXY : public Test {
00239      public:
00241        SqrXY(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st)
00242          : Test("Arithmetic::Sqr::XY::"+s,2,d,st,CPLT_ASSIGNMENT,false) {}
00244        virtual MaybeType solution(const Assignment& x) const {
00245          return eq(x[0] * x[0], x[1]);
00246        }
00248        virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
00249          if (flip())
00250            Gecode::sqr(home, x[0], x[1]);
00251          else
00252            Gecode::rel(home, sqr(x[0]) == x[1]);
00253        }
00254      };
00255 
00257      class SqrXYSol : public Test {
00258      public:
00260        SqrXYSol(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st)
00261        : Test("Arithmetic::Sqr::XY::Sol::"+s,2,d,st,EXTEND_ASSIGNMENT,false) {}
00263        virtual MaybeType solution(const Assignment& x) const {
00264          return eq(x[0] * x[0], x[1]);
00265        }
00267        virtual bool extendAssignement(Assignment& x) const {
00268          Gecode::FloatVal d = sqr(x[0]);
00269          if (Gecode::Float::subset(d, dom)) {
00270            x.set(1, d);
00271            return true;
00272          } else {
00273            return false;
00274          }
00275        }
00277        virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
00278          Gecode::sqr(home, x[0], x[1]);
00279        }
00280      };
00281      
00283      class SqrXX : public Test {
00284      public:
00286        SqrXX(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st)
00287          : Test("Arithmetic::Sqr::XX::"+s,1,d,st,CPLT_ASSIGNMENT,false) {}
00289        virtual MaybeType solution(const Assignment& x) const {
00290          return eq(x[0] * x[0], x[0]);
00291        }
00293        virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
00294          Gecode::sqr(home, x[0], x[0]);
00295        }
00296      };
00297 
00299      class SqrtXY : public Test {
00300      public:
00302        SqrtXY(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st)
00303          : Test("Arithmetic::Sqrt::XY::"+s,2,d,st,CPLT_ASSIGNMENT,false) {}
00305        virtual MaybeType solution(const Assignment& x) const {
00306          switch (cmp(x[0], Gecode::FRT_GQ, 0.0)) {
00307          case MT_FALSE: return MT_FALSE;
00308          case MT_MAYBE: return MT_MAYBE;
00309          default:
00310            return eq(sqrt(x[0]), x[1]);
00311          }
00312        }
00314        virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
00315          if (flip())
00316            Gecode::sqrt(home, x[0], x[1]);
00317          else
00318            Gecode::rel(home, sqrt(x[0]) == x[1]);
00319        }
00320      };
00321 
00323      class SqrtXYSol : public Test {
00324      public:
00326        SqrtXYSol(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st)
00327        : Test("Arithmetic::Sqrt::XY::Sol::"+s,2,d,st,EXTEND_ASSIGNMENT,false) {}
00329        virtual MaybeType solution(const Assignment& x) const {
00330          switch (cmp(x[0], Gecode::FRT_GQ, 0.0)) {
00331          case MT_FALSE: return MT_FALSE;
00332          case MT_MAYBE: return MT_MAYBE;
00333          default:
00334            return eq(sqrt(x[0]), x[1]);
00335          }
00336        }
00338        virtual bool extendAssignement(Assignment& x) const {
00339          Gecode::FloatVal d = sqrt(abs(x[0]));
00340          if (Gecode::Float::subset(d, dom)) {
00341            x.set(1, d);
00342            return true;
00343          } else {
00344            return false;
00345          }
00346        }
00348        virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
00349          Gecode::sqrt(home, x[0], x[1]);
00350        }
00351      };
00352      
00354      class SqrtXX : public Test {
00355      public:
00357        SqrtXX(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st)
00358          : Test("Arithmetic::Sqrt::XX::"+s,1,d,st,CPLT_ASSIGNMENT,false) {}
00360        virtual MaybeType solution(const Assignment& x) const {
00361          switch (cmp(x[0], Gecode::FRT_GQ, 0.0)) {
00362          case MT_FALSE: return MT_FALSE;
00363          case MT_MAYBE: return MT_MAYBE;
00364          default:
00365            return eq(sqrt(x[0]), x[0]);
00366          }
00367        }
00369        virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
00370          Gecode::sqrt(home, x[0], x[0]);
00371        }
00372      };
00373 
00375      class PowXY : public Test {
00376        unsigned int n;
00377      public:
00379        PowXY(const std::string& s, const Gecode::FloatVal& d, unsigned int _n, Gecode::FloatNum st)
00380        : Test("Arithmetic::Pow::N::"+str(_n)+"::XY::"+s,2,d,st,CPLT_ASSIGNMENT,false), n(_n) {}
00382        virtual MaybeType solution(const Assignment& x) const {
00383          return eq(pow(x[0],n), x[1]);
00384        }
00386        virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
00387          if (flip())
00388            Gecode::pow(home, x[0], n, x[1]);
00389          else
00390            Gecode::rel(home, pow(x[0],n) == x[1]);
00391        }
00392      };
00393      
00395      class PowXYSol : public Test {
00396        unsigned int n;
00397      public:
00399        PowXYSol(const std::string& s, const Gecode::FloatVal& d, unsigned int _n, Gecode::FloatNum st)
00400        : Test("Arithmetic::Pow::N::"+str(_n)+"::XY::Sol::"+s,2,d,st,EXTEND_ASSIGNMENT,false), n(_n) {}
00402        virtual MaybeType solution(const Assignment& x) const {
00403          return eq(pow(x[0],n), x[1]);
00404        }
00406        virtual bool extendAssignement(Assignment& x) const {
00407          Gecode::FloatVal d = pow(x[0],n);
00408          if (Gecode::Float::subset(d, dom)) {
00409            x.set(1, d);
00410            return true;
00411          } else {
00412            return false;
00413          }
00414        }
00416        virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
00417          Gecode::pow(home, x[0], n, x[1]);
00418        }
00419      };
00420      
00422      class PowXX : public Test {
00423        unsigned int n;
00424      public:
00426        PowXX(const std::string& s, const Gecode::FloatVal& d, unsigned int _n, Gecode::FloatNum st)
00427        : Test("Arithmetic::Pow::N::"+str(_n)+"::XX::"+s,1,d,st,CPLT_ASSIGNMENT,false) {}
00429        virtual MaybeType solution(const Assignment& x) const {
00430          return eq(pow(x[0],n), x[0]);
00431        }
00433        virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
00434          Gecode::pow(home, x[0], n, x[0]);
00435        }
00436      };
00437      
00439      class NRootXY : public Test {
00440        unsigned int n;
00441      public:
00443        NRootXY(const std::string& s, const Gecode::FloatVal& d, unsigned int _n, Gecode::FloatNum st)
00444        : Test("Arithmetic::NRoot::N::"+str(_n)+"::XY::"+s,2,d,st,CPLT_ASSIGNMENT,false), n(_n) {}
00446        virtual MaybeType solution(const Assignment& x) const {
00447          if ((n == 0) || (x[0].max() < 0.0))
00448            return MT_FALSE;
00449          return eq(nroot(x[0],n), x[1]);
00450        }
00452        virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
00453          if (flip())
00454            Gecode::nroot(home, x[0], n, x[1]);
00455          else
00456            Gecode::rel(home, nroot(x[0],n) == x[1]);
00457        }
00458      };
00459      
00461      class NRootXYSol : public Test {
00462        unsigned int n;
00463      public:
00465        NRootXYSol(const std::string& s, const Gecode::FloatVal& d, unsigned int _n, Gecode::FloatNum st)
00466        : Test("Arithmetic::NRoot::N::"+str(_n)+"::XY::Sol::"+s,2,d,st,EXTEND_ASSIGNMENT,false), n(_n) {}
00468        virtual MaybeType solution(const Assignment& x) const {
00469          if ((n == 0) || (x[0].max() < 0.0))
00470            return MT_FALSE;
00471          return eq(nroot(x[0],n), x[1]);
00472        }
00474        virtual bool extendAssignement(Assignment& x) const {
00475          if ((n == 0) || (x[0].max() < 0)) 
00476            return false;
00477          Gecode::FloatVal d = nroot(x[0],n);
00478          if (Gecode::Float::subset(d, dom)) {
00479            x.set(1, d);
00480            return true;
00481          } else {
00482            return false;
00483          }
00484        }
00486        virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
00487          Gecode::nroot(home, x[0], n, x[1]);
00488        }
00489      };
00490      
00492      class NRootXX : public Test {
00493        unsigned int n;
00494      public:
00496        NRootXX(const std::string& s, const Gecode::FloatVal& d, unsigned int _n, Gecode::FloatNum st)
00497        : Test("Arithmetic::NRoot::N::"+str(_n)+"::XX::"+s,1,d,st,CPLT_ASSIGNMENT,false) {}
00499        virtual MaybeType solution(const Assignment& x) const {
00500          if ((n == 0) || (x[0].max() < 0)) 
00501            return MT_FALSE;
00502          return eq(nroot(x[0],n), x[0]);
00503        }
00505        virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
00506          Gecode::nroot(home, x[0], n, x[0]);
00507        }
00508      };
00509      
00511      class AbsXY : public Test {
00512      public:
00514        AbsXY(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st)
00515          : Test("Arithmetic::Abs::XY::"+s,2,d,st,CPLT_ASSIGNMENT,false) {}
00517        virtual MaybeType solution(const Assignment& x) const {
00518          return eq(abs(x[0]), x[1]);
00519        }
00521        virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
00522          if (flip())
00523            Gecode::abs(home, x[0], x[1]);
00524          else
00525            Gecode::rel(home, abs(x[0]) == x[1]);
00526        }
00527      };
00528 
00530      class AbsXX : public Test {
00531      public:
00533        AbsXX(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st)
00534          : Test("Arithmetic::Abs::XX::"+s,1,d,st,CPLT_ASSIGNMENT,false) {}
00536        virtual MaybeType solution(const Assignment& x) const {
00537          return eq(abs(x[0]), x[0]);
00538        }
00540        virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
00541          Gecode::abs(home, x[0], x[0]);
00542        }
00543      };
00544 
00546      class MinXYZ : public Test {
00547      public:
00549        MinXYZ(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st)
00550          : Test("Arithmetic::Min::Bin::XYZ::"+s,3,d,st,CPLT_ASSIGNMENT,false) {}
00552        virtual MaybeType solution(const Assignment& x) const {
00553          return eq(min(x[0],x[1]), x[2]);
00554        }
00556        virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
00557          if (flip())
00558            Gecode::min(home, x[0], x[1], x[2]);
00559          else
00560            Gecode::rel(home, min(x[0],x[1]) == x[2]);
00561        }
00562      };
00563 
00565      class MinXXY : public Test {
00566      public:
00568        MinXXY(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st)
00569        : Test("Arithmetic::Min::Bin::XXY::"+s,2,d,st,CPLT_ASSIGNMENT,false) {}
00571        virtual MaybeType solution(const Assignment& x) const {
00572          return eq(min(x[0],x[0]), x[1]);
00573        }
00575        virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
00576          Gecode::min(home, x[0], x[0], x[1]);
00577        }
00578      };
00579 
00581      class MinXYX : public Test {
00582      public:
00584        MinXYX(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st)
00585        : Test("Arithmetic::Min::Bin::XYX::"+s,2,d,st,CPLT_ASSIGNMENT,false) {}
00587        virtual MaybeType solution(const Assignment& x) const {
00588          return eq(min(x[0],x[1]), x[0]);
00589        }
00591        virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
00592          Gecode::min(home, x[0], x[1], x[0]);
00593        }
00594      };
00595 
00597      class MinXYY : public Test {
00598      public:
00600        MinXYY(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st)
00601        : Test("Arithmetic::Min::Bin::XYY::"+s,2,d,st,CPLT_ASSIGNMENT,false) {}
00603        virtual MaybeType solution(const Assignment& x) const {
00604          return eq(min(x[0],x[1]), x[1]);
00605        }
00607        virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
00608          Gecode::min(home, x[0], x[1], x[1]);
00609        }
00610      };
00611 
00613      class MinXXX : public Test {
00614      public:
00616        MinXXX(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st)
00617        : Test("Arithmetic::Min::Bin::XXX::"+s,1,d,st,CPLT_ASSIGNMENT,false) {}
00619        virtual MaybeType solution(const Assignment& x) const {
00620          return eq(min(x[0],x[0]), x[0]);
00621        }
00623        virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
00624          Gecode::min(home, x[0], x[0], x[0]);
00625        }
00626      };
00627 
00629      class MaxXYZ : public Test {
00630      public:
00632        MaxXYZ(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st)
00633          : Test("Arithmetic::Max::Bin::XYZ::"+s,3,d,st,CPLT_ASSIGNMENT,false) {}
00635        virtual MaybeType solution(const Assignment& x) const {
00636          return eq(max(x[0],x[1]), x[2]);
00637        }
00639        virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
00640          if (flip())
00641            Gecode::max(home, x[0], x[1], x[2]);
00642          else
00643            Gecode::rel(home, max(x[0], x[1]) == x[2]);
00644        }
00645      };
00646 
00648      class MaxXXY : public Test {
00649      public:
00651        MaxXXY(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st)
00652        : Test("Arithmetic::Max::Bin::XXY::"+s,2,d,st,CPLT_ASSIGNMENT,false) {}
00654        virtual MaybeType solution(const Assignment& x) const {
00655          return eq(max(x[0],x[0]), x[1]);
00656        }
00658        virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
00659          Gecode::max(home, x[0], x[0], x[1]);
00660        }
00661      };
00662 
00664      class MaxXYX : public Test {
00665      public:
00667        MaxXYX(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st)
00668        : Test("Arithmetic::Max::Bin::XYX::"+s,2,d,st,CPLT_ASSIGNMENT,false) {}
00670        virtual MaybeType solution(const Assignment& x) const {
00671          return eq(max(x[0],x[1]), x[0]);
00672        }
00674        virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
00675          Gecode::max(home, x[0], x[1], x[0]);
00676        }
00677      };
00678 
00680      class MaxXYY : public Test {
00681      public:
00683        MaxXYY(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st)
00684        : Test("Arithmetic::Max::Bin::XYY::"+s,2,d,st,CPLT_ASSIGNMENT,false) {}
00686        virtual MaybeType solution(const Assignment& x) const {
00687          return eq(max(x[0],x[1]), x[1]);
00688        }
00690        virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
00691          Gecode::max(home, x[0], x[1], x[1]);
00692        }
00693      };
00694 
00696      class MaxXXX : public Test {
00697      public:
00699        MaxXXX(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st)
00700        : Test("Arithmetic::Max::Bin::XXX::"+s,1,d,st,CPLT_ASSIGNMENT,false) {}
00702        virtual MaybeType solution(const Assignment& x) const {
00703          return eq(max(x[0],x[0]), x[0]);
00704        }
00706        virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
00707          Gecode::max(home, x[0], x[0], x[0]);
00708        }
00709      };
00710 
00712      class MinNary : public Test {
00713      public:
00715        MinNary(void)
00716          : Test("Arithmetic::Min::Nary",4,-4,4,0.5,CPLT_ASSIGNMENT,false) {}
00718        virtual MaybeType solution(const Assignment& x) const {
00719          return eq(min(min(x[0],x[1]),x[2]), x[3]);
00720        }
00722        virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
00723          Gecode::FloatVarArgs m(3);
00724          m[0]=x[0]; m[1]=x[1]; m[2]=x[2];
00725          if (flip())
00726            Gecode::min(home, m, x[3]);
00727          else
00728            Gecode::rel(home, min(m) == x[3]);
00729        }
00730      };
00731 
00733      class MinNaryShared : public Test {
00734      public:
00736        MinNaryShared(void)
00737           : Test("Arithmetic::Min::Nary::Shared",3,-4,4,0.5,CPLT_ASSIGNMENT,false) {}
00739        virtual MaybeType solution(const Assignment& x) const {
00740          return eq(min(min(x[0],x[1]),x[2]), x[1]);
00741        }
00743        virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
00744          Gecode::FloatVarArgs m(3);
00745          m[0]=x[0]; m[1]=x[1]; m[2]=x[2];
00746          Gecode::min(home, m, x[1]);
00747        }
00748      };
00749 
00751      class MaxNary : public Test {
00752      public:
00754        MaxNary(void)
00755           : Test("Arithmetic::Max::Nary",4,-4,4,0.5,CPLT_ASSIGNMENT,false) {}
00757        virtual MaybeType solution(const Assignment& x) const {
00758          return eq(max(max(x[0],x[1]),x[2]), x[3]);
00759        }
00761        virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
00762          Gecode::FloatVarArgs m(3);
00763          m[0]=x[0]; m[1]=x[1]; m[2]=x[2];
00764          if (flip())
00765            Gecode::max(home, m, x[3]);
00766          else
00767            Gecode::rel(home, max(m) == x[3]);
00768        }
00769      };
00770 
00772      class MaxNaryShared : public Test {
00773      public:
00775        MaxNaryShared(void)
00776           : Test("Arithmetic::Max::Nary::Shared",3,-4,4,0.5,CPLT_ASSIGNMENT,false) {}
00778        virtual MaybeType solution(const Assignment& x) const {
00779          return eq(max(max(x[0],x[1]),x[2]), x[1]);
00780        }
00782        virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
00783          Gecode::FloatVarArgs m(3);
00784          m[0]=x[0]; m[1]=x[1]; m[2]=x[2];
00785          Gecode::max(home, m, x[1]);
00786        }
00787      };
00788 
00789      const Gecode::FloatNum step = 0.15;
00790      const Gecode::FloatNum step2 = 2*step;
00791      Gecode::FloatVal a(-8,5);
00792      Gecode::FloatVal b(9,12);
00793      Gecode::FloatVal c(-8,8);
00794 
00795      MultXXY mult_xxy_a("A",a,step);
00796      MultXXY mult_xxy_b("B",b,step);
00797      MultXXY mult_xxy_c("C",c,step);
00798 
00799      MultXXYSol mult_xxy_sol_a("A",a,step);
00800      MultXXYSol mult_xxy_sol_b("B",b,step);
00801      MultXXYSol mult_xxy_sol_c("C",c,step);
00802      
00803      MultXYX mult_xyx_a("A",a,step);
00804      MultXYX mult_xyx_b("B",b,step);
00805      MultXYX mult_xyx_c("C",c,step);
00806 
00807      MultXYY mult_xyy_a("A",a,step);
00808      MultXYY mult_xyy_b("B",b,step);
00809      MultXYY mult_xyy_c("C",c,step);
00810 
00811      MultXXX mult_xxx_a("A",a,step);
00812      MultXXX mult_xxx_b("B",b,step);
00813      MultXXX mult_xxx_c("C",c,step);
00814 
00815      MultXYZ mult_xyz_a("A",a,step);
00816      MultXYZ mult_xyz_b("B",b,step);
00817      MultXYZ mult_xyz_c("C",c,step);
00818 
00819      MultXYZSol mult_xyz_sol_a("A",a,step);
00820      MultXYZSol mult_xyz_sol_b("B",b,step);
00821      MultXYZSol mult_xyz_sol_c("C",c,step);
00822      
00823      Div div_a("A",a,step);
00824      Div div_b("B",b,step);
00825      Div div_c("C",c,step);
00826      
00827      DivSol div_sol_a("A",a,step);
00828      DivSol div_sol_b("B",b,step);
00829      DivSol div_sol_c("C",c,step);
00830      
00831      SqrXY sqr_xy_a("A",a,step);
00832      SqrXY sqr_xy_b("B",b,step);
00833      SqrXY sqr_xy_c("C",c,step);
00834 
00835      SqrXYSol sqr_xy_sol_a("A",a,step);
00836      SqrXYSol sqr_xy_sol_b("B",b,step);
00837      SqrXYSol sqr_xy_sol_c("C",c,step);
00838      
00839      SqrXX sqr_xx_a("A",a,step);
00840      SqrXX sqr_xx_b("B",b,step);
00841      SqrXX sqr_xx_c("C",c,step);
00842 
00843      SqrtXY sqrt_xy_a("A",a,step);
00844      SqrtXY sqrt_xy_b("B",b,step);
00845      SqrtXY sqrt_xy_c("C",c,step);
00846 
00847      SqrtXYSol sqrt_xy_sol_a("A",a,step);
00848      SqrtXYSol sqrt_xy_sol_b("B",b,step);
00849      SqrtXYSol sqrt_xy_sol_c("C",c,step);
00850      
00851      SqrtXX sqrt_xx_a("A",a,step);
00852      SqrtXX sqrt_xx_b("B",b,step);
00853      SqrtXX sqrt_xx_c("C",c,step);
00854 
00855      PowXY pow_xy_a_1("A",a,2,step);
00856      PowXY pow_xy_b_1("B",b,2,step);
00857      PowXY pow_xy_c_1("C",c,2,step);
00858      
00859      PowXYSol pow_xy_sol_a_1("A",a,2,step);
00860      PowXYSol pow_xy_sol_b_1("B",b,2,step);
00861      PowXYSol pow_xy_sol_c_1("C",c,2,step);
00862      
00863      PowXX pow_xx_a_1("A",a,2,step);
00864      PowXX pow_xx_b_1("B",b,2,step);
00865      PowXX pow_xx_c_1("C",c,2,step);
00866      
00867      PowXY pow_xy_a_2("A",a,3,step);
00868      PowXY pow_xy_b_2("B",b,3,step);
00869      PowXY pow_xy_c_2("C",c,3,step);
00870      
00871      PowXYSol pow_xy_sol_a_2("A",a,3,step);
00872      PowXYSol pow_xy_sol_b_2("B",b,3,step);
00873      PowXYSol pow_xy_sol_c_2("C",c,3,step);
00874      
00875      PowXX pow_xx_a_2("A",a,3,step);
00876      PowXX pow_xx_b_2("B",b,3,step);
00877      PowXX pow_xx_c_2("C",c,3,step);
00878      
00879      PowXY pow_xy_a_3("A",a,0,step);
00880      PowXY pow_xy_b_3("B",b,0,step);
00881      PowXY pow_xy_c_3("C",c,0,step);
00882      
00883      PowXYSol pow_xy_sol_a_3("A",a,0,step);
00884      PowXYSol pow_xy_sol_b_3("B",b,0,step);
00885      PowXYSol pow_xy_sol_c_3("C",c,0,step);
00886      
00887      PowXX pow_xx_a_3("A",a,0,step);
00888      PowXX pow_xx_b_3("B",b,0,step);
00889      PowXX pow_xx_c_3("C",c,0,step);
00890      
00891      NRootXY nroot_xy_a_1("A",a,2,step);
00892      NRootXY nroot_xy_b_1("B",b,2,step);
00893      NRootXY nroot_xy_c_1("C",c,2,step);
00894      
00895      NRootXYSol nroot_xy_sol_a_1("A",a,2,step);
00896      NRootXYSol nroot_xy_sol_b_1("B",b,2,step);
00897      NRootXYSol nroot_xy_sol_c_1("C",c,2,step);
00898      
00899      NRootXX nroot_xx_a_1("A",a,2,step);
00900      NRootXX nroot_xx_b_1("B",b,2,step);
00901      NRootXX nroot_xx_c_1("C",c,2,step);
00902      
00903      NRootXY nroot_xy_a_2("A",a,3,step);
00904      NRootXY nroot_xy_b_2("B",b,3,step);
00905      NRootXY nroot_xy_c_2("C",c,3,step);
00906      
00907      NRootXYSol nroot_xy_sol_a_2("A",a,3,step);
00908      NRootXYSol nroot_xy_sol_b_2("B",b,3,step);
00909      NRootXYSol nroot_xy_sol_c_2("C",c,3,step);
00910      
00911      NRootXX nroot_xx_a_2("A",a,3,step);
00912      NRootXX nroot_xx_b_2("B",b,3,step);
00913      NRootXX nroot_xx_c_2("C",c,3,step);
00914      
00915      NRootXY nroot_xy_a_3("A",a,0,step);
00916      NRootXY nroot_xy_b_3("B",b,0,step);
00917      NRootXY nroot_xy_c_3("C",c,0,step);
00918      
00919      NRootXYSol nroot_xy_sol_a_3("A",a,0,step);
00920      NRootXYSol nroot_xy_sol_b_3("B",b,0,step);
00921      NRootXYSol nroot_xy_sol_c_3("C",c,0,step);
00922      
00923      NRootXX nroot_xx_a_3("A",a,0,step);
00924      NRootXX nroot_xx_b_3("B",b,0,step);
00925      NRootXX nroot_xx_c_3("C",c,0,step);
00926      
00927      AbsXY abs_xy_a("A",a,step);
00928      AbsXY abs_xy_b("B",b,step);
00929      AbsXY abs_xy_c("C",c,step);
00930 
00931      AbsXX abs_xx_a("A",a,step);
00932      AbsXX abs_xx_b("B",b,step);
00933      AbsXX abs_xx_c("C",c,step);
00934 
00935      MinXYZ min_xyz_a("A",a,step);
00936      MinXYZ min_xyz_b("B",b,step);
00937      MinXYZ min_xyz_c("C",c,step);
00938 
00939      MinXXY min_xxy_a("A",a,step);
00940      MinXXY min_xxy_b("B",b,step);
00941      MinXXY min_xxy_c("C",c,step);
00942 
00943      MinXYX min_xyx_a("A",a,step);
00944      MinXYX min_xyx_b("B",b,step);
00945      MinXYX min_xyx_c("C",c,step);
00946 
00947      MinXYY min_xyy_a("A",a,step);
00948      MinXYY min_xyy_b("B",b,step);
00949      MinXYY min_xyy_c("C",c,step);
00950 
00951      MinXXX min_xxx_a("A",a,step);
00952      MinXXX min_xxx_b("B",b,step);
00953      MinXXX min_xxx_c("C",c,step);
00954 
00955      MaxXYZ max_xyz_a("A",a,step);
00956      MaxXYZ max_xyz_b("B",b,step);
00957      MaxXYZ max_xyz_c("C",c,step);
00958 
00959      MaxXXY max_xxy_a("A",a,step);
00960      MaxXXY max_xxy_b("B",b,step);
00961      MaxXXY max_xxy_c("C",c,step);
00962 
00963      MaxXYX max_xyx_a("A",a,step);
00964      MaxXYX max_xyx_b("B",b,step);
00965      MaxXYX max_xyx_c("C",c,step);
00966 
00967      MaxXYY max_xyy_a("A",a,step);
00968      MaxXYY max_xyy_b("B",b,step);
00969      MaxXYY max_xyy_c("C",c,step);
00970 
00971      MaxXXX max_xxx_a("A",a,step);
00972      MaxXXX max_xxx_b("B",b,step);
00973      MaxXXX max_xxx_c("C",c,step);
00974 
00975      MinNary       min_nary;
00976      MinNaryShared min_s_nary;
00977      MaxNary       max_nary;
00978      MaxNaryShared max_s_nary;
00980 
00981    }
00982 }}
00983 
00984 // STATISTICS: test-float