Generated on Thu Apr 11 13:58:55 2019 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  *  This file is part of Gecode, the generic constraint
00012  *  development environment:
00013  *     http://www.gecode.org
00014  *
00015  *  Permission is hereby granted, free of charge, to any person obtaining
00016  *  a copy of this software and associated documentation files (the
00017  *  "Software"), to deal in the Software without restriction, including
00018  *  without limitation the rights to use, copy, modify, merge, publish,
00019  *  distribute, sublicense, and/or sell copies of the Software, and to
00020  *  permit persons to whom the Software is furnished to do so, subject to
00021  *  the following conditions:
00022  *
00023  *  The above copyright notice and this permission notice shall be
00024  *  included in all copies or substantial portions of the Software.
00025  *
00026  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00027  *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00028  *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00029  *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
00030  *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
00031  *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00032  *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00033  *
00034  */
00035 
00036 #include "test/float.hh"
00037 
00038 #include <gecode/minimodel.hh>
00039 
00040 #include <cmath>
00041 #include <algorithm>
00042 
00043 namespace Test { namespace Float {
00044 
00046    namespace Arithmetic {
00047 
00053 
00054      class MultXYZ : public Test {
00055      public:
00057        MultXYZ(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st)
00058          : Test("Arithmetic::Mult::XYZ::"+s,3,d,st,CPLT_ASSIGNMENT,false) {}
00060        virtual MaybeType solution(const Assignment& x) const {
00061          return eq(x[0] * x[1], x[2]);
00062        }
00064        virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
00065          if (flip())
00066            Gecode::mult(home, x[0], x[1], x[2]);
00067          else
00068            Gecode::rel(home, x[0] * x[1] == x[2]);
00069        }
00070      };
00071 
00073      class MultXYZSol : public Test {
00074      public:
00076        MultXYZSol(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st)
00077          : Test("Arithmetic::Mult::XYZ::Sol::"+s,3,d,st,EXTEND_ASSIGNMENT,false) {}
00079        virtual MaybeType solution(const Assignment& x) const {
00080          return eq(x[0] * x[1], x[2]);
00081        }
00083        virtual bool extendAssignement(Assignment& x) const {
00084          Gecode::FloatVal d = x[0]*x[1];
00085          if (Gecode::Float::subset(d, dom)) {
00086            x.set(2, d);
00087            return true;
00088          } else {
00089            return false;
00090          }
00091        }
00093        virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
00094          Gecode::mult(home, x[0], x[1], x[2]);
00095        }
00096      };
00097 
00099      class MultXXY : public Test {
00100      public:
00102        MultXXY(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st)
00103          : Test("Arithmetic::Mult::XXY::"+s,2,d,st,CPLT_ASSIGNMENT,false) {}
00105        virtual MaybeType solution(const Assignment& x) const {
00106          return eq(x[0] * x[0], x[1]);
00107        }
00109        virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
00110          Gecode::mult(home, x[0], x[0], x[1]);
00111        }
00112      };
00113 
00115      class MultXXYSol : public Test {
00116      public:
00118        MultXXYSol(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st)
00119        : Test("Arithmetic::Mult::XXY::Sol::"+s,2,d,st,EXTEND_ASSIGNMENT,false) {}
00121        virtual MaybeType solution(const Assignment& x) const {
00122          return eq(x[0] * x[0], x[1]);
00123        }
00125        virtual bool extendAssignement(Assignment& x) const {
00126          Gecode::FloatVal d = x[0]*x[0];
00127          if (Gecode::Float::subset(d, dom)) {
00128            x.set(1, d);
00129            return true;
00130          } else {
00131            return false;
00132          }
00133        }
00135        virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
00136          Gecode::mult(home, x[0], x[0], x[1]);
00137        }
00138      };
00139 
00141      class MultXYX : public Test {
00142      public:
00144        MultXYX(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st)
00145          : Test("Arithmetic::Mult::XYX::"+s,2,d,st,CPLT_ASSIGNMENT,false) {}
00147        virtual MaybeType solution(const Assignment& x) const {
00148          return eq(x[0] * x[1], x[0]);
00149        }
00151        virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
00152          Gecode::mult(home, x[0], x[1], x[0]);
00153        }
00154      };
00155 
00157      class MultXYY : public Test {
00158      public:
00160        MultXYY(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st)
00161          : Test("Arithmetic::Mult::XYY::"+s,2,d,st,CPLT_ASSIGNMENT,false) {}
00163        virtual MaybeType solution(const Assignment& x) const {
00164          return eq(x[0] * x[1], x[1]);
00165        }
00167        virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
00168          Gecode::mult(home, x[0], x[1], x[1]);
00169        }
00170      };
00171 
00173      class MultXXX : public Test {
00174      public:
00176        MultXXX(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st)
00177          : Test("Arithmetic::Mult::XXX::"+s,1,d,st,CPLT_ASSIGNMENT,false) {}
00179        virtual MaybeType solution(const Assignment& x) const {
00180          return eq(x[0] * x[0], x[0]);
00181        }
00183        virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
00184          Gecode::mult(home, x[0], x[0], x[0]);
00185        }
00186      };
00187 
00189      class Div : public Test {
00190      public:
00192        Div(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st)
00193        : Test("Arithmetic::Div::"+s,3,d,st,CPLT_ASSIGNMENT,false) {}
00195        virtual MaybeType solution(const Assignment& x) const {
00196          return eq(x[0] / x[1], x[2]);
00197        }
00199        virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
00200          if (flip())
00201            Gecode::div(home, x[0], x[1], x[2]);
00202          else
00203            Gecode::rel(home, x[0] / x[1] == x[2]);
00204        }
00205      };
00206 
00208      class DivSol : public Test {
00209      public:
00211        DivSol(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st)
00212        : Test("Arithmetic::Div::Sol::"+s,3,d,st,EXTEND_ASSIGNMENT,false) {}
00214        virtual MaybeType solution(const Assignment& x) const {
00215          return eq(x[0] / x[1], x[2]);
00216        }
00218        virtual bool extendAssignement(Assignment& x) const {
00219          Gecode::FloatVal d = x[0]/x[1];
00220          if (Gecode::Float::subset(d, dom)) {
00221            x.set(2, d);
00222            return true;
00223          } else {
00224            return false;
00225          }
00226        }
00228        virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
00229          Gecode::div(home, x[0], x[1], x[2]);
00230        }
00231      };
00232 
00234      class SqrXY : public Test {
00235      public:
00237        SqrXY(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st)
00238          : Test("Arithmetic::Sqr::XY::"+s,2,d,st,CPLT_ASSIGNMENT,false) {}
00240        virtual MaybeType solution(const Assignment& x) const {
00241          return eq(x[0] * x[0], x[1]);
00242        }
00244        virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
00245          if (flip())
00246            Gecode::sqr(home, x[0], x[1]);
00247          else
00248            Gecode::rel(home, sqr(x[0]) == x[1]);
00249        }
00250      };
00251 
00253      class SqrXYSol : public Test {
00254      public:
00256        SqrXYSol(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st)
00257        : Test("Arithmetic::Sqr::XY::Sol::"+s,2,d,st,EXTEND_ASSIGNMENT,false) {}
00259        virtual MaybeType solution(const Assignment& x) const {
00260          return eq(x[0] * x[0], x[1]);
00261        }
00263        virtual bool extendAssignement(Assignment& x) const {
00264          Gecode::FloatVal d = sqr(x[0]);
00265          if (Gecode::Float::subset(d, dom)) {
00266            x.set(1, d);
00267            return true;
00268          } else {
00269            return false;
00270          }
00271        }
00273        virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
00274          Gecode::sqr(home, x[0], x[1]);
00275        }
00276      };
00277 
00279      class SqrXX : public Test {
00280      public:
00282        SqrXX(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st)
00283          : Test("Arithmetic::Sqr::XX::"+s,1,d,st,CPLT_ASSIGNMENT,false) {}
00285        virtual MaybeType solution(const Assignment& x) const {
00286          return eq(x[0] * x[0], x[0]);
00287        }
00289        virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
00290          Gecode::sqr(home, x[0], x[0]);
00291        }
00292      };
00293 
00295      class SqrtXY : public Test {
00296      public:
00298        SqrtXY(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st)
00299          : Test("Arithmetic::Sqrt::XY::"+s,2,d,st,CPLT_ASSIGNMENT,false) {}
00301        virtual MaybeType solution(const Assignment& x) const {
00302          switch (cmp(x[0], Gecode::FRT_GQ, 0.0)) {
00303          case MT_FALSE: return MT_FALSE;
00304          case MT_MAYBE: return MT_MAYBE;
00305          default:
00306            return eq(sqrt(x[0]), x[1]);
00307          }
00308        }
00310        virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
00311          if (flip())
00312            Gecode::sqrt(home, x[0], x[1]);
00313          else
00314            Gecode::rel(home, sqrt(x[0]) == x[1]);
00315        }
00316      };
00317 
00319      class SqrtXYSol : public Test {
00320      public:
00322        SqrtXYSol(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st)
00323        : Test("Arithmetic::Sqrt::XY::Sol::"+s,2,d,st,EXTEND_ASSIGNMENT,false) {}
00325        virtual MaybeType solution(const Assignment& x) const {
00326          switch (cmp(x[0], Gecode::FRT_GQ, 0.0)) {
00327          case MT_FALSE: return MT_FALSE;
00328          case MT_MAYBE: return MT_MAYBE;
00329          default:
00330            return eq(sqrt(x[0]), x[1]);
00331          }
00332        }
00334        virtual bool extendAssignement(Assignment& x) const {
00335          Gecode::FloatVal d = sqrt(abs(x[0]));
00336          if (Gecode::Float::subset(d, dom)) {
00337            x.set(1, d);
00338            return true;
00339          } else {
00340            return false;
00341          }
00342        }
00344        virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
00345          Gecode::sqrt(home, x[0], x[1]);
00346        }
00347      };
00348 
00350      class SqrtXX : public Test {
00351      public:
00353        SqrtXX(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st)
00354          : Test("Arithmetic::Sqrt::XX::"+s,1,d,st,CPLT_ASSIGNMENT,false) {}
00356        virtual MaybeType solution(const Assignment& x) const {
00357          switch (cmp(x[0], Gecode::FRT_GQ, 0.0)) {
00358          case MT_FALSE: return MT_FALSE;
00359          case MT_MAYBE: return MT_MAYBE;
00360          default:
00361            return eq(sqrt(x[0]), x[0]);
00362          }
00363        }
00365        virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
00366          Gecode::sqrt(home, x[0], x[0]);
00367        }
00368      };
00369 
00371      class PowXY : public Test {
00372        unsigned int n;
00373      public:
00375        PowXY(const std::string& s, const Gecode::FloatVal& d, unsigned int _n, Gecode::FloatNum st)
00376        : Test("Arithmetic::Pow::N::"+str(_n)+"::XY::"+s,2,d,st,CPLT_ASSIGNMENT,false), n(_n) {}
00378        virtual MaybeType solution(const Assignment& x) const {
00379          return eq(pow(x[0],n), x[1]);
00380        }
00382        virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
00383          if (flip())
00384            Gecode::pow(home, x[0], n, x[1]);
00385          else
00386            Gecode::rel(home, pow(x[0],n) == x[1]);
00387        }
00388      };
00389 
00391      class PowXYSol : public Test {
00392        unsigned int n;
00393      public:
00395        PowXYSol(const std::string& s, const Gecode::FloatVal& d, unsigned int _n, Gecode::FloatNum st)
00396        : Test("Arithmetic::Pow::N::"+str(_n)+"::XY::Sol::"+s,2,d,st,EXTEND_ASSIGNMENT,false), n(_n) {}
00398        virtual MaybeType solution(const Assignment& x) const {
00399          return eq(pow(x[0],n), x[1]);
00400        }
00402        virtual bool extendAssignement(Assignment& x) const {
00403          Gecode::FloatVal d = pow(x[0],n);
00404          if (Gecode::Float::subset(d, dom)) {
00405            x.set(1, d);
00406            return true;
00407          } else {
00408            return false;
00409          }
00410        }
00412        virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
00413          Gecode::pow(home, x[0], n, x[1]);
00414        }
00415      };
00416 
00418      class PowXX : public Test {
00419        unsigned int n;
00420      public:
00422        PowXX(const std::string& s, const Gecode::FloatVal& d, unsigned int _n, Gecode::FloatNum st)
00423        : Test("Arithmetic::Pow::N::"+str(_n)+"::XX::"+s,1,d,st,CPLT_ASSIGNMENT,false) {}
00425        virtual MaybeType solution(const Assignment& x) const {
00426          return eq(pow(x[0],n), x[0]);
00427        }
00429        virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
00430          Gecode::pow(home, x[0], n, x[0]);
00431        }
00432      };
00433 
00435      class NRootXY : public Test {
00436        unsigned int n;
00437      public:
00439        NRootXY(const std::string& s, const Gecode::FloatVal& d, unsigned int _n, Gecode::FloatNum st)
00440        : Test("Arithmetic::NRoot::N::"+str(_n)+"::XY::"+s,2,d,st,CPLT_ASSIGNMENT,false), n(_n) {}
00442        virtual MaybeType solution(const Assignment& x) const {
00443          if ((n == 0) || (x[0].max() < 0.0))
00444            return MT_FALSE;
00445          return eq(nroot(x[0],n), x[1]);
00446        }
00448        virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
00449          if (flip())
00450            Gecode::nroot(home, x[0], n, x[1]);
00451          else
00452            Gecode::rel(home, nroot(x[0],n) == x[1]);
00453        }
00454      };
00455 
00457      class NRootXYSol : public Test {
00458        unsigned int n;
00459      public:
00461        NRootXYSol(const std::string& s, const Gecode::FloatVal& d, unsigned int _n, Gecode::FloatNum st)
00462        : Test("Arithmetic::NRoot::N::"+str(_n)+"::XY::Sol::"+s,2,d,st,EXTEND_ASSIGNMENT,false), n(_n) {}
00464        virtual MaybeType solution(const Assignment& x) const {
00465          if ((n == 0) || (x[0].max() < 0.0))
00466            return MT_FALSE;
00467          return eq(nroot(x[0],n), x[1]);
00468        }
00470        virtual bool extendAssignement(Assignment& x) const {
00471          if ((n == 0) || (x[0].max() < 0))
00472            return false;
00473          Gecode::FloatVal d = nroot(x[0],n);
00474          if (Gecode::Float::subset(d, dom)) {
00475            x.set(1, d);
00476            return true;
00477          } else {
00478            return false;
00479          }
00480        }
00482        virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
00483          Gecode::nroot(home, x[0], n, x[1]);
00484        }
00485      };
00486 
00488      class NRootXX : public Test {
00489        unsigned int n;
00490      public:
00492        NRootXX(const std::string& s, const Gecode::FloatVal& d, unsigned int _n, Gecode::FloatNum st)
00493        : Test("Arithmetic::NRoot::N::"+str(_n)+"::XX::"+s,1,d,st,CPLT_ASSIGNMENT,false) {}
00495        virtual MaybeType solution(const Assignment& x) const {
00496          if ((n == 0) || (x[0].max() < 0))
00497            return MT_FALSE;
00498          return eq(nroot(x[0],n), x[0]);
00499        }
00501        virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
00502          Gecode::nroot(home, x[0], n, x[0]);
00503        }
00504      };
00505 
00507      class AbsXY : public Test {
00508      public:
00510        AbsXY(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st)
00511          : Test("Arithmetic::Abs::XY::"+s,2,d,st,CPLT_ASSIGNMENT,false) {}
00513        virtual MaybeType solution(const Assignment& x) const {
00514          return eq(abs(x[0]), x[1]);
00515        }
00517        virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
00518          if (flip())
00519            Gecode::abs(home, x[0], x[1]);
00520          else
00521            Gecode::rel(home, abs(x[0]) == x[1]);
00522        }
00523      };
00524 
00526      class AbsXX : public Test {
00527      public:
00529        AbsXX(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st)
00530          : Test("Arithmetic::Abs::XX::"+s,1,d,st,CPLT_ASSIGNMENT,false) {}
00532        virtual MaybeType solution(const Assignment& x) const {
00533          return eq(abs(x[0]), x[0]);
00534        }
00536        virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
00537          Gecode::abs(home, x[0], x[0]);
00538        }
00539      };
00540 
00542      class MinXYZ : public Test {
00543      public:
00545        MinXYZ(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st)
00546          : Test("Arithmetic::Min::Bin::XYZ::"+s,3,d,st,CPLT_ASSIGNMENT,false) {}
00548        virtual MaybeType solution(const Assignment& x) const {
00549          return eq(min(x[0],x[1]), x[2]);
00550        }
00552        virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
00553          if (flip())
00554            Gecode::min(home, x[0], x[1], x[2]);
00555          else
00556            Gecode::rel(home, min(x[0],x[1]) == x[2]);
00557        }
00558      };
00559 
00561      class MinXXY : public Test {
00562      public:
00564        MinXXY(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st)
00565        : Test("Arithmetic::Min::Bin::XXY::"+s,2,d,st,CPLT_ASSIGNMENT,false) {}
00567        virtual MaybeType solution(const Assignment& x) const {
00568          return eq(min(x[0],x[0]), x[1]);
00569        }
00571        virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
00572          Gecode::min(home, x[0], x[0], x[1]);
00573        }
00574      };
00575 
00577      class MinXYX : public Test {
00578      public:
00580        MinXYX(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st)
00581        : Test("Arithmetic::Min::Bin::XYX::"+s,2,d,st,CPLT_ASSIGNMENT,false) {}
00583        virtual MaybeType solution(const Assignment& x) const {
00584          return eq(min(x[0],x[1]), x[0]);
00585        }
00587        virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
00588          Gecode::min(home, x[0], x[1], x[0]);
00589        }
00590      };
00591 
00593      class MinXYY : public Test {
00594      public:
00596        MinXYY(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st)
00597        : Test("Arithmetic::Min::Bin::XYY::"+s,2,d,st,CPLT_ASSIGNMENT,false) {}
00599        virtual MaybeType solution(const Assignment& x) const {
00600          return eq(min(x[0],x[1]), x[1]);
00601        }
00603        virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
00604          Gecode::min(home, x[0], x[1], x[1]);
00605        }
00606      };
00607 
00609      class MinXXX : public Test {
00610      public:
00612        MinXXX(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st)
00613        : Test("Arithmetic::Min::Bin::XXX::"+s,1,d,st,CPLT_ASSIGNMENT,false) {}
00615        virtual MaybeType solution(const Assignment& x) const {
00616          return eq(min(x[0],x[0]), x[0]);
00617        }
00619        virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
00620          Gecode::min(home, x[0], x[0], x[0]);
00621        }
00622      };
00623 
00625      class MaxXYZ : public Test {
00626      public:
00628        MaxXYZ(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st)
00629          : Test("Arithmetic::Max::Bin::XYZ::"+s,3,d,st,CPLT_ASSIGNMENT,false) {}
00631        virtual MaybeType solution(const Assignment& x) const {
00632          return eq(max(x[0],x[1]), x[2]);
00633        }
00635        virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
00636          if (flip())
00637            Gecode::max(home, x[0], x[1], x[2]);
00638          else
00639            Gecode::rel(home, max(x[0], x[1]) == x[2]);
00640        }
00641      };
00642 
00644      class MaxXXY : public Test {
00645      public:
00647        MaxXXY(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st)
00648        : Test("Arithmetic::Max::Bin::XXY::"+s,2,d,st,CPLT_ASSIGNMENT,false) {}
00650        virtual MaybeType solution(const Assignment& x) const {
00651          return eq(max(x[0],x[0]), x[1]);
00652        }
00654        virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
00655          Gecode::max(home, x[0], x[0], x[1]);
00656        }
00657      };
00658 
00660      class MaxXYX : public Test {
00661      public:
00663        MaxXYX(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st)
00664        : Test("Arithmetic::Max::Bin::XYX::"+s,2,d,st,CPLT_ASSIGNMENT,false) {}
00666        virtual MaybeType solution(const Assignment& x) const {
00667          return eq(max(x[0],x[1]), x[0]);
00668        }
00670        virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
00671          Gecode::max(home, x[0], x[1], x[0]);
00672        }
00673      };
00674 
00676      class MaxXYY : public Test {
00677      public:
00679        MaxXYY(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st)
00680        : Test("Arithmetic::Max::Bin::XYY::"+s,2,d,st,CPLT_ASSIGNMENT,false) {}
00682        virtual MaybeType solution(const Assignment& x) const {
00683          return eq(max(x[0],x[1]), x[1]);
00684        }
00686        virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
00687          Gecode::max(home, x[0], x[1], x[1]);
00688        }
00689      };
00690 
00692      class MaxXXX : public Test {
00693      public:
00695        MaxXXX(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st)
00696        : Test("Arithmetic::Max::Bin::XXX::"+s,1,d,st,CPLT_ASSIGNMENT,false) {}
00698        virtual MaybeType solution(const Assignment& x) const {
00699          return eq(max(x[0],x[0]), x[0]);
00700        }
00702        virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
00703          Gecode::max(home, x[0], x[0], x[0]);
00704        }
00705      };
00706 
00708      class MinNary : public Test {
00709      public:
00711        MinNary(void)
00712          : Test("Arithmetic::Min::Nary",4,-4,4,0.5,CPLT_ASSIGNMENT,false) {}
00714        virtual MaybeType solution(const Assignment& x) const {
00715          return eq(min(min(x[0],x[1]),x[2]), x[3]);
00716        }
00718        virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
00719          Gecode::FloatVarArgs m(3);
00720          m[0]=x[0]; m[1]=x[1]; m[2]=x[2];
00721          if (flip())
00722            Gecode::min(home, m, x[3]);
00723          else
00724            Gecode::rel(home, min(m) == x[3]);
00725        }
00726      };
00727 
00729      class MinNaryShared : public Test {
00730      public:
00732        MinNaryShared(void)
00733           : Test("Arithmetic::Min::Nary::Shared",3,-4,4,0.5,CPLT_ASSIGNMENT,false) {}
00735        virtual MaybeType solution(const Assignment& x) const {
00736          return eq(min(min(x[0],x[1]),x[2]), x[1]);
00737        }
00739        virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
00740          Gecode::FloatVarArgs m(3);
00741          m[0]=x[0]; m[1]=x[1]; m[2]=x[2];
00742          Gecode::min(home, m, x[1]);
00743        }
00744      };
00745 
00747      class MaxNary : public Test {
00748      public:
00750        MaxNary(void)
00751           : Test("Arithmetic::Max::Nary",4,-4,4,0.5,CPLT_ASSIGNMENT,false) {}
00753        virtual MaybeType solution(const Assignment& x) const {
00754          return eq(max(max(x[0],x[1]),x[2]), x[3]);
00755        }
00757        virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
00758          Gecode::FloatVarArgs m(3);
00759          m[0]=x[0]; m[1]=x[1]; m[2]=x[2];
00760          if (flip())
00761            Gecode::max(home, m, x[3]);
00762          else
00763            Gecode::rel(home, max(m) == x[3]);
00764        }
00765      };
00766 
00768      class MaxNaryShared : public Test {
00769      public:
00771        MaxNaryShared(void)
00772           : Test("Arithmetic::Max::Nary::Shared",3,-4,4,0.5,CPLT_ASSIGNMENT,false) {}
00774        virtual MaybeType solution(const Assignment& x) const {
00775          return eq(max(max(x[0],x[1]),x[2]), x[1]);
00776        }
00778        virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
00779          Gecode::FloatVarArgs m(3);
00780          m[0]=x[0]; m[1]=x[1]; m[2]=x[2];
00781          Gecode::max(home, m, x[1]);
00782        }
00783      };
00784 
00785      const Gecode::FloatNum step = 0.15;
00786      Gecode::FloatVal a(-8,5);
00787      Gecode::FloatVal b(9,12);
00788      Gecode::FloatVal c(-8,8);
00789 
00790      MultXXY mult_xxy_a("A",a,step);
00791      MultXXY mult_xxy_b("B",b,step);
00792      MultXXY mult_xxy_c("C",c,step);
00793 
00794      MultXXYSol mult_xxy_sol_a("A",a,step);
00795      MultXXYSol mult_xxy_sol_b("B",b,step);
00796      MultXXYSol mult_xxy_sol_c("C",c,step);
00797 
00798      MultXYX mult_xyx_a("A",a,step);
00799      MultXYX mult_xyx_b("B",b,step);
00800      MultXYX mult_xyx_c("C",c,step);
00801 
00802      MultXYY mult_xyy_a("A",a,step);
00803      MultXYY mult_xyy_b("B",b,step);
00804      MultXYY mult_xyy_c("C",c,step);
00805 
00806      MultXXX mult_xxx_a("A",a,step);
00807      MultXXX mult_xxx_b("B",b,step);
00808      MultXXX mult_xxx_c("C",c,step);
00809 
00810      MultXYZ mult_xyz_a("A",a,step);
00811      MultXYZ mult_xyz_b("B",b,step);
00812      MultXYZ mult_xyz_c("C",c,step);
00813 
00814      MultXYZSol mult_xyz_sol_a("A",a,step);
00815      MultXYZSol mult_xyz_sol_b("B",b,step);
00816      MultXYZSol mult_xyz_sol_c("C",c,step);
00817 
00818      Div div_a("A",a,step);
00819      Div div_b("B",b,step);
00820      Div div_c("C",c,step);
00821 
00822      DivSol div_sol_a("A",a,step);
00823      DivSol div_sol_b("B",b,step);
00824      DivSol div_sol_c("C",c,step);
00825 
00826      SqrXY sqr_xy_a("A",a,step);
00827      SqrXY sqr_xy_b("B",b,step);
00828      SqrXY sqr_xy_c("C",c,step);
00829 
00830      SqrXYSol sqr_xy_sol_a("A",a,step);
00831      SqrXYSol sqr_xy_sol_b("B",b,step);
00832      SqrXYSol sqr_xy_sol_c("C",c,step);
00833 
00834      SqrXX sqr_xx_a("A",a,step);
00835      SqrXX sqr_xx_b("B",b,step);
00836      SqrXX sqr_xx_c("C",c,step);
00837 
00838      SqrtXY sqrt_xy_a("A",a,step);
00839      SqrtXY sqrt_xy_b("B",b,step);
00840      SqrtXY sqrt_xy_c("C",c,step);
00841 
00842      SqrtXYSol sqrt_xy_sol_a("A",a,step);
00843      SqrtXYSol sqrt_xy_sol_b("B",b,step);
00844      SqrtXYSol sqrt_xy_sol_c("C",c,step);
00845 
00846      SqrtXX sqrt_xx_a("A",a,step);
00847      SqrtXX sqrt_xx_b("B",b,step);
00848      SqrtXX sqrt_xx_c("C",c,step);
00849 
00850      PowXY pow_xy_a_1("A",a,2,step);
00851      PowXY pow_xy_b_1("B",b,2,step);
00852      PowXY pow_xy_c_1("C",c,2,step);
00853 
00854      PowXYSol pow_xy_sol_a_1("A",a,2,step);
00855      PowXYSol pow_xy_sol_b_1("B",b,2,step);
00856      PowXYSol pow_xy_sol_c_1("C",c,2,step);
00857 
00858      PowXX pow_xx_a_1("A",a,2,step);
00859      PowXX pow_xx_b_1("B",b,2,step);
00860      PowXX pow_xx_c_1("C",c,2,step);
00861 
00862      PowXY pow_xy_a_2("A",a,3,step);
00863      PowXY pow_xy_b_2("B",b,3,step);
00864      PowXY pow_xy_c_2("C",c,3,step);
00865 
00866      PowXYSol pow_xy_sol_a_2("A",a,3,step);
00867      PowXYSol pow_xy_sol_b_2("B",b,3,step);
00868      PowXYSol pow_xy_sol_c_2("C",c,3,step);
00869 
00870      PowXX pow_xx_a_2("A",a,3,step);
00871      PowXX pow_xx_b_2("B",b,3,step);
00872      PowXX pow_xx_c_2("C",c,3,step);
00873 
00874      PowXY pow_xy_a_3("A",a,0,step);
00875      PowXY pow_xy_b_3("B",b,0,step);
00876      PowXY pow_xy_c_3("C",c,0,step);
00877 
00878      PowXYSol pow_xy_sol_a_3("A",a,0,step);
00879      PowXYSol pow_xy_sol_b_3("B",b,0,step);
00880      PowXYSol pow_xy_sol_c_3("C",c,0,step);
00881 
00882      PowXX pow_xx_a_3("A",a,0,step);
00883      PowXX pow_xx_b_3("B",b,0,step);
00884      PowXX pow_xx_c_3("C",c,0,step);
00885 
00886      NRootXY nroot_xy_a_1("A",a,2,step);
00887      NRootXY nroot_xy_b_1("B",b,2,step);
00888      NRootXY nroot_xy_c_1("C",c,2,step);
00889 
00890      NRootXYSol nroot_xy_sol_a_1("A",a,2,step);
00891      NRootXYSol nroot_xy_sol_b_1("B",b,2,step);
00892      NRootXYSol nroot_xy_sol_c_1("C",c,2,step);
00893 
00894      NRootXX nroot_xx_a_1("A",a,2,step);
00895      NRootXX nroot_xx_b_1("B",b,2,step);
00896      NRootXX nroot_xx_c_1("C",c,2,step);
00897 
00898      NRootXY nroot_xy_a_2("A",a,3,step);
00899      NRootXY nroot_xy_b_2("B",b,3,step);
00900      NRootXY nroot_xy_c_2("C",c,3,step);
00901 
00902      NRootXYSol nroot_xy_sol_a_2("A",a,3,step);
00903      NRootXYSol nroot_xy_sol_b_2("B",b,3,step);
00904      NRootXYSol nroot_xy_sol_c_2("C",c,3,step);
00905 
00906      NRootXX nroot_xx_a_2("A",a,3,step);
00907      NRootXX nroot_xx_b_2("B",b,3,step);
00908      NRootXX nroot_xx_c_2("C",c,3,step);
00909 
00910      NRootXY nroot_xy_a_3("A",a,0,step);
00911      NRootXY nroot_xy_b_3("B",b,0,step);
00912      NRootXY nroot_xy_c_3("C",c,0,step);
00913 
00914      NRootXYSol nroot_xy_sol_a_3("A",a,0,step);
00915      NRootXYSol nroot_xy_sol_b_3("B",b,0,step);
00916      NRootXYSol nroot_xy_sol_c_3("C",c,0,step);
00917 
00918      NRootXX nroot_xx_a_3("A",a,0,step);
00919      NRootXX nroot_xx_b_3("B",b,0,step);
00920      NRootXX nroot_xx_c_3("C",c,0,step);
00921 
00922      AbsXY abs_xy_a("A",a,step);
00923      AbsXY abs_xy_b("B",b,step);
00924      AbsXY abs_xy_c("C",c,step);
00925 
00926      AbsXX abs_xx_a("A",a,step);
00927      AbsXX abs_xx_b("B",b,step);
00928      AbsXX abs_xx_c("C",c,step);
00929 
00930      MinXYZ min_xyz_a("A",a,step);
00931      MinXYZ min_xyz_b("B",b,step);
00932      MinXYZ min_xyz_c("C",c,step);
00933 
00934      MinXXY min_xxy_a("A",a,step);
00935      MinXXY min_xxy_b("B",b,step);
00936      MinXXY min_xxy_c("C",c,step);
00937 
00938      MinXYX min_xyx_a("A",a,step);
00939      MinXYX min_xyx_b("B",b,step);
00940      MinXYX min_xyx_c("C",c,step);
00941 
00942      MinXYY min_xyy_a("A",a,step);
00943      MinXYY min_xyy_b("B",b,step);
00944      MinXYY min_xyy_c("C",c,step);
00945 
00946      MinXXX min_xxx_a("A",a,step);
00947      MinXXX min_xxx_b("B",b,step);
00948      MinXXX min_xxx_c("C",c,step);
00949 
00950      MaxXYZ max_xyz_a("A",a,step);
00951      MaxXYZ max_xyz_b("B",b,step);
00952      MaxXYZ max_xyz_c("C",c,step);
00953 
00954      MaxXXY max_xxy_a("A",a,step);
00955      MaxXXY max_xxy_b("B",b,step);
00956      MaxXXY max_xxy_c("C",c,step);
00957 
00958      MaxXYX max_xyx_a("A",a,step);
00959      MaxXYX max_xyx_b("B",b,step);
00960      MaxXYX max_xyx_c("C",c,step);
00961 
00962      MaxXYY max_xyy_a("A",a,step);
00963      MaxXYY max_xyy_b("B",b,step);
00964      MaxXYY max_xyy_c("C",c,step);
00965 
00966      MaxXXX max_xxx_a("A",a,step);
00967      MaxXXX max_xxx_b("B",b,step);
00968      MaxXXX max_xxx_c("C",c,step);
00969 
00970      MinNary       min_nary;
00971      MinNaryShared min_s_nary;
00972      MaxNary       max_nary;
00973      MaxNaryShared max_s_nary;
00975 
00976    }
00977 }}
00978 
00979 // STATISTICS: test-float