Something went wrong. Try again.
This repository has no description
Something went wrong. Try again.
18 kB · 515 lines
C++
at develop
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- *//* * Main authors: * Christian Schulte <schulte@gecode.org> * Vincent Barichard <Vincent.Barichard@univ-angers.fr> * * Copyright: * Christian Schulte, 2005 * Vincent Barichard, 2012 * * This file is part of Gecode, the generic constraint * development environment: * http://www.gecode.org * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the * "Software"), to deal in the Software without restriction, including * without limitation the rights to use, copy, modify, merge, publish, * distribute, sublicense, and/or sell copies of the Software, and to * permit persons to whom the Software is furnished to do so, subject to * the following conditions: * * The above copyright notice and this permission notice shall be * included in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * */
#include "test/float.hh"#include <gecode/minimodel.hh>
#ifdef GECODE_HAS_MPFR
#include <cmath>#include <algorithm>
namespace Test { namespace Float {
/// %Tests for trigonometric constraints namespace Trigonometric {
/// %Test for sinus constraint class SinXY : public Test { public: /// Create and register test SinXY(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st) : Test("Trigonometric::Sin::XY::"+s,2,d,st,CPLT_ASSIGNMENT,false) {} /// %Test whether \a x is solution virtual MaybeType solution(const Assignment& x) const { return eq(sin(x[0]), x[1]); } /// Post constraint on \a x virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) { if (flip()) Gecode::sin(home, x[0], x[1]); else Gecode::rel(home, sin(x[0]) == x[1]); } };
/// %Test for sinus constraint where solution is ensured class SinXYSol : public Test { public: /// Create and register test SinXYSol(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st) : Test("Trigonometric::Sin::XY::Sol::"+s,2,d,st,EXTEND_ASSIGNMENT,false) {} /// %Test whether \a x is solution virtual MaybeType solution(const Assignment& x) const { return eq(sin(x[0]), x[1]); } /// Extend assignment \a x virtual bool extendAssignement(Assignment& x) const { Gecode::FloatVal d = sin(x[0]); if (Gecode::Float::subset(d, dom)) { x.set(1, d); return true; } else { return false; } } /// Post constraint on \a x virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) { Gecode::sin(home, x[0], x[1]); } };
/// %Test for sinus constraint with shared variables class SinXX : public Test { public: /// Create and register test SinXX(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st) : Test("Trigonometric::Sin::XX::"+s,1,d,st,CPLT_ASSIGNMENT,false) {} /// %Test whether \a x is solution virtual MaybeType solution(const Assignment& x) const { return eq(sin(x[0]), x[0]); } /// Post constraint on \a x virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) { Gecode::sin(home, x[0], x[0]); } };
/// %Test for cosinus constraint class CosXY : public Test { public: /// Create and register test CosXY(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st) : Test("Trigonometric::Cos::XY::"+s,2,d,st,CPLT_ASSIGNMENT,false) {} /// %Test whether \a x is solution virtual MaybeType solution(const Assignment& x) const { return eq(cos(x[0]), x[1]); } /// Post constraint on \a x virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) { if (flip()) Gecode::cos(home, x[0], x[1]); else Gecode::rel(home, cos(x[0]) == x[1]); } };
/// %Test for cosinus constraint where solution is ensured class CosXYSol : public Test { public: /// Create and register test CosXYSol(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st) : Test("Trigonometric::Cos::XY::Sol::"+s,2,d,st,EXTEND_ASSIGNMENT,false) {} /// %Test whether \a x is solution virtual MaybeType solution(const Assignment& x) const { return eq(cos(x[0]), x[1]); } /// Extend assignment \a x virtual bool extendAssignement(Assignment& x) const { Gecode::FloatVal d = cos(x[0]); if (Gecode::Float::subset(d, dom)) { x.set(1, d); return true; } else { return false; } } /// Post constraint on \a x virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) { Gecode::cos(home, x[0], x[1]); } };
/// %Test for cosinus constraint with shared variables class CosXX : public Test { public: /// Create and register test CosXX(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st) : Test("Trigonometric::Cos::XX::"+s,1,d,st,CPLT_ASSIGNMENT,false) {} /// %Test whether \a x is solution virtual MaybeType solution(const Assignment& x) const { return eq(cos(x[0]), x[0]); } /// Post constraint on \a x virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) { Gecode::cos(home, x[0], x[0]); } };
/// %Test for tangent constraint class TanXY : public Test { public: /// Create and register test TanXY(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st) : Test("Trigonometric::Tan::XY::"+s,2,d,st,CPLT_ASSIGNMENT,false) {} /// %Test whether \a x is solution virtual MaybeType solution(const Assignment& x) const { return eq(tan(x[0]), x[1]); } /// Post constraint on \a x virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) { if (flip()) Gecode::tan(home, x[0], x[1]); else Gecode::rel(home, tan(x[0]) == x[1]); } };
/// %Test for tangent constraint where solution is ensured class TanXYSol : public Test { public: /// Create and register test TanXYSol(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st) : Test("Trigonometric::Tan::XY::Sol::"+s,2,d,st,EXTEND_ASSIGNMENT,false) {} /// %Test whether \a x is solution virtual MaybeType solution(const Assignment& x) const { return eq(tan(x[0]), x[1]); } /// Extend assignment \a x virtual bool extendAssignement(Assignment& x) const { Gecode::FloatVal d = tan(x[0]); if (Gecode::Float::subset(d, dom)) { x.set(1, d); return true; } else { return false; } } /// Post constraint on \a x virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) { Gecode::tan(home, x[0], x[1]); } };
/// %Test for tangent constraint with shared variables class TanXX : public Test { public: /// Create and register test TanXX(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st) : Test("Trigonometric::Tan::XX::"+s,1,d,st,CPLT_ASSIGNMENT,false) {} /// %Test whether \a x is solution virtual MaybeType solution(const Assignment& x) const { return eq(tan(x[0]), x[0]); } /// Post constraint on \a x virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) { Gecode::tan(home, x[0], x[0]); } };
/// %Test for asinus constraint class ASinXY : public Test { public: /// Create and register test ASinXY(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st) : Test("Trigonometric::ASin::XY::"+s,2,d,st,CPLT_ASSIGNMENT,false) {} /// %Test whether \a x is solution virtual MaybeType solution(const Assignment& x) const { if ((x[0].min() > 1.0) || (x[0].max() < -1.0)) return MT_FALSE; return eq(asin(x[0]), x[1]); } /// Post constraint on \a x virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) { if (flip()) Gecode::asin(home, x[0], x[1]); else Gecode::rel(home, asin(x[0]) == x[1]); } };
/// %Test for asinus constraint where solution is ensured class ASinXYSol : public Test { public: /// Create and register test ASinXYSol(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st) : Test("Trigonometric::ASin::XY::Sol::"+s,2,d,st,EXTEND_ASSIGNMENT,false) {} /// %Test whether \a x is solution virtual MaybeType solution(const Assignment& x) const { if ((x[0].min() > 1.0) || (x[0].max() < -1.0)) return MT_FALSE; return eq(asin(x[0]), x[1]); } /// Extend assignment \a x virtual bool extendAssignement(Assignment& x) const { if ((x[0].min() > 1.0) || (x[0].max() < -1.0)) return false; Gecode::FloatVal d = asin(x[0]); if (Gecode::Float::subset(d, dom)) { x.set(1, d); return true; } else { return false; } } /// Post constraint on \a x virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) { Gecode::asin(home, x[0], x[1]); } };
/// %Test for asinus constraint with shared variables class ASinXX : public Test { public: /// Create and register test ASinXX(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st) : Test("Trigonometric::ASin::XX::"+s,1,d,st,CPLT_ASSIGNMENT,false) {} /// %Test whether \a x is solution virtual MaybeType solution(const Assignment& x) const { if ((x[0].min() > 1.0) || (x[0].max() < -1.0)) return MT_FALSE; return eq(asin(x[0]), x[0]); } /// Post constraint on \a x virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) { Gecode::asin(home, x[0], x[0]); } };
/// %Test for acosinus constraint class ACosXY : public Test { public: /// Create and register test ACosXY(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st) : Test("Trigonometric::ACos::XY::"+s,2,d,st,CPLT_ASSIGNMENT,false) {} /// %Test whether \a x is solution virtual MaybeType solution(const Assignment& x) const { if ((x[0].min() > 1.0) || (x[0].max() < -1.0)) return MT_FALSE; return eq(acos(x[0]), x[1]); } /// Post constraint on \a x virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) { if (flip()) Gecode::acos(home, x[0], x[1]); else Gecode::rel(home, acos(x[0]) == x[1]); } };
/// %Test for acosinus constraint where solution is ensured class ACosXYSol : public Test { public: /// Create and register test ACosXYSol(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st) : Test("Trigonometric::ACos::XY::Sol::"+s,2,d,st,EXTEND_ASSIGNMENT,false) {} /// %Test whether \a x is solution virtual MaybeType solution(const Assignment& x) const { if ((x[0].min() > 1.0) || (x[0].max() < -1.0)) return MT_FALSE; return eq(acos(x[0]), x[1]); } /// Extend assignment \a x virtual bool extendAssignement(Assignment& x) const { if ((x[0].min() > 1.0) || (x[0].max() < -1.0)) return false; Gecode::FloatVal d = acos(x[0]); if (Gecode::Float::subset(d, dom)) { x.set(1, d); return true; } else { return false; } } /// Post constraint on \a x virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) { Gecode::acos(home, x[0], x[1]); } };
/// %Test for acosinus constraint with shared variables class ACosXX : public Test { public: /// Create and register test ACosXX(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st) : Test("Trigonometric::ACos::XX::"+s,1,d,st,CPLT_ASSIGNMENT,false) {} /// %Test whether \a x is solution virtual MaybeType solution(const Assignment& x) const { if ((x[0].min() > 1.0) || (x[0].max() < -1.0)) return MT_FALSE; return eq(acos(x[0]), x[0]); } /// Post constraint on \a x virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) { Gecode::acos(home, x[0], x[0]); } };
/// %Test for atangent constraint class ATanXY : public Test { public: /// Create and register test ATanXY(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st) : Test("Trigonometric::ATan::XY::"+s,2,d,st,CPLT_ASSIGNMENT,false) {} /// %Test whether \a x is solution virtual MaybeType solution(const Assignment& x) const { return eq(atan(x[0]), x[1]); } /// Post constraint on \a x virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) { if (flip()) Gecode::atan(home, x[0], x[1]); else Gecode::rel(home, atan(x[0]) == x[1]); } };
/// %Test for atangent constraint where solution is ensured class ATanXYSol : public Test { public: /// Create and register test ATanXYSol(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st) : Test("Trigonometric::ATan::XY::Sol::"+s,2,d,st,EXTEND_ASSIGNMENT,false) {} /// %Test whether \a x is solution virtual MaybeType solution(const Assignment& x) const { return eq(atan(x[0]), x[1]); } /// Extend assignment \a x virtual bool extendAssignement(Assignment& x) const { Gecode::FloatVal d = atan(x[0]); if (Gecode::Float::subset(d, dom)) { x.set(1, d); return true; } else { return false; } } /// Post constraint on \a x virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) { Gecode::atan(home, x[0], x[1]); } };
/// %Test for atangent constraint with shared variables class ATanXX : public Test { public: /// Create and register test ATanXX(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st) : Test("Trigonometric::ATan::XX::"+s,1,d,st,CPLT_ASSIGNMENT,false) {} /// %Test whether \a x is solution virtual MaybeType solution(const Assignment& x) const { return eq(atan(x[0]), x[0]); } /// Post constraint on \a x virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) { Gecode::atan(home, x[0], x[0]); } };
const Gecode::FloatNum step = 0.15; const Gecode::FloatNum step2 = 2*step; Gecode::FloatVal a(-8,5); Gecode::FloatVal b(9,12); Gecode::FloatVal c(-8,8);
SinXY sin_xy_a("A",a,step); SinXY sin_xy_b("B",b,step); SinXY sin_xy_c("C",c,step);
SinXYSol sin_xy_sol_a("A",a,step); SinXYSol sin_xy_sol_b("B",b,step); SinXYSol sin_xy_sol_c("C",c,step);
SinXX sin_xx_a("A",a,step); SinXX sin_xx_b("B",b,step); SinXX sin_xx_c("C",c,step);
CosXY cos_xy_a("A",a,step); CosXY cos_xy_b("B",b,step); CosXY cos_xy_c("C",c,step);
CosXYSol cos_xy_sol_a("A",a,step); CosXYSol cos_xy_sol_b("B",b,step); CosXYSol cos_xy_sol_c("C",c,step);
CosXX cos_xx_a("A",a,step); CosXX cos_xx_b("B",b,step); CosXX cos_xx_c("C",c,step);
TanXY tan_xy_a("A",a,step); TanXY tan_xy_b("B",b,step); TanXY tan_xy_c("C",c,step);
TanXYSol tan_xy_sol_a("A",a,step); TanXYSol tan_xy_sol_b("B",b,step); TanXYSol tan_xy_sol_c("C",c,step);
TanXX tan_xx_a("A",a,step); TanXX tan_xx_b("B",b,step); TanXX tan_xx_c("C",c,step);
ASinXY asin_xy_a("A",a,step); ASinXY asin_xy_b("B",b,step); ASinXY asin_xy_c("C",c,step);
ASinXYSol asin_xy_sol_a("A",a,step); ASinXYSol asin_xy_sol_b("B",b,step); ASinXYSol asin_xy_sol_c("C",c,step);
ASinXX asin_xx_a("A",a,step); ASinXX asin_xx_b("B",b,step); ASinXX asin_xx_c("C",c,step);
ACosXY acos_xy_a("A",a,step); ACosXY acos_xy_b("B",b,step); ACosXY acos_xy_c("C",c,step);
ACosXYSol acos_xy_sol_a("A",a,step); ACosXYSol acos_xy_sol_b("B",b,step); ACosXYSol acos_xy_sol_c("C",c,step);
ACosXX acos_xx_a("A",a,step); ACosXX acos_xx_b("B",b,step); ACosXX acos_xx_c("C",c,step);
ATanXY atan_xy_a("A",a,step); ATanXY atan_xy_b("B",b,step); ATanXY atan_xy_c("C",c,step);
ATanXYSol atan_xy_sol_a("A",a,step); ATanXYSol atan_xy_sol_b("B",b,step); ATanXYSol atan_xy_sol_c("C",c,step);
ATanXX atan_xx_a("A",a,step); ATanXX atan_xx_b("B",b,step); ATanXX atan_xx_c("C",c,step);
//@}
}}}
#endif// STATISTICS: test-float