00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 #include "test/float.hh"
00037 #include <gecode/minimodel.hh>
00038
00039 #ifdef GECODE_HAS_MPFR
00040
00041 #include <cmath>
00042 #include <algorithm>
00043
00044 namespace Test { namespace Float {
00045
00047 namespace Trigonometric {
00048
00050 class SinXY : public Test {
00051 public:
00053 SinXY(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st)
00054 : Test("Trigonometric::Sin::XY::"+s,2,d,st,CPLT_ASSIGNMENT,false) {}
00056 virtual MaybeType solution(const Assignment& x) const {
00057 return eq(sin(x[0]), x[1]);
00058 }
00060 virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
00061 if (flip())
00062 Gecode::sin(home, x[0], x[1]);
00063 else
00064 Gecode::rel(home, sin(x[0]) == x[1]);
00065 }
00066 };
00067
00069 class SinXYSol : public Test {
00070 public:
00072 SinXYSol(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st)
00073 : Test("Trigonometric::Sin::XY::Sol::"+s,2,d,st,EXTEND_ASSIGNMENT,false) {}
00075 virtual MaybeType solution(const Assignment& x) const {
00076 return eq(sin(x[0]), x[1]);
00077 }
00079 virtual bool extendAssignement(Assignment& x) const {
00080 Gecode::FloatVal d = sin(x[0]);
00081 if (Gecode::Float::subset(d, dom)) {
00082 x.set(1, d);
00083 return true;
00084 } else {
00085 return false;
00086 }
00087 }
00089 virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
00090 Gecode::sin(home, x[0], x[1]);
00091 }
00092 };
00093
00095 class SinXX : public Test {
00096 public:
00098 SinXX(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st)
00099 : Test("Trigonometric::Sin::XX::"+s,1,d,st,CPLT_ASSIGNMENT,false) {}
00101 virtual MaybeType solution(const Assignment& x) const {
00102 return eq(sin(x[0]), x[0]);
00103 }
00105 virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
00106 Gecode::sin(home, x[0], x[0]);
00107 }
00108 };
00109
00111 class CosXY : public Test {
00112 public:
00114 CosXY(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st)
00115 : Test("Trigonometric::Cos::XY::"+s,2,d,st,CPLT_ASSIGNMENT,false) {}
00117 virtual MaybeType solution(const Assignment& x) const {
00118 return eq(cos(x[0]), x[1]);
00119 }
00121 virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
00122 if (flip())
00123 Gecode::cos(home, x[0], x[1]);
00124 else
00125 Gecode::rel(home, cos(x[0]) == x[1]);
00126 }
00127 };
00128
00130 class CosXYSol : public Test {
00131 public:
00133 CosXYSol(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st)
00134 : Test("Trigonometric::Cos::XY::Sol::"+s,2,d,st,EXTEND_ASSIGNMENT,false) {}
00136 virtual MaybeType solution(const Assignment& x) const {
00137 return eq(cos(x[0]), x[1]);
00138 }
00140 virtual bool extendAssignement(Assignment& x) const {
00141 Gecode::FloatVal d = cos(x[0]);
00142 if (Gecode::Float::subset(d, dom)) {
00143 x.set(1, d);
00144 return true;
00145 } else {
00146 return false;
00147 }
00148 }
00150 virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
00151 Gecode::cos(home, x[0], x[1]);
00152 }
00153 };
00154
00156 class CosXX : public Test {
00157 public:
00159 CosXX(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st)
00160 : Test("Trigonometric::Cos::XX::"+s,1,d,st,CPLT_ASSIGNMENT,false) {}
00162 virtual MaybeType solution(const Assignment& x) const {
00163 return eq(cos(x[0]), x[0]);
00164 }
00166 virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
00167 Gecode::cos(home, x[0], x[0]);
00168 }
00169 };
00170
00172 class TanXY : public Test {
00173 public:
00175 TanXY(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st)
00176 : Test("Trigonometric::Tan::XY::"+s,2,d,st,CPLT_ASSIGNMENT,false) {}
00178 virtual MaybeType solution(const Assignment& x) const {
00179 return eq(tan(x[0]), x[1]);
00180 }
00182 virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
00183 if (flip())
00184 Gecode::tan(home, x[0], x[1]);
00185 else
00186 Gecode::rel(home, tan(x[0]) == x[1]);
00187 }
00188 };
00189
00191 class TanXYSol : public Test {
00192 public:
00194 TanXYSol(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st)
00195 : Test("Trigonometric::Tan::XY::Sol::"+s,2,d,st,EXTEND_ASSIGNMENT,false) {}
00197 virtual MaybeType solution(const Assignment& x) const {
00198 return eq(tan(x[0]), x[1]);
00199 }
00201 virtual bool extendAssignement(Assignment& x) const {
00202 Gecode::FloatVal d = tan(x[0]);
00203 if (Gecode::Float::subset(d, dom)) {
00204 x.set(1, d);
00205 return true;
00206 } else {
00207 return false;
00208 }
00209 }
00211 virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
00212 Gecode::tan(home, x[0], x[1]);
00213 }
00214 };
00215
00217 class TanXX : public Test {
00218 public:
00220 TanXX(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st)
00221 : Test("Trigonometric::Tan::XX::"+s,1,d,st,CPLT_ASSIGNMENT,false) {}
00223 virtual MaybeType solution(const Assignment& x) const {
00224 return eq(tan(x[0]), x[0]);
00225 }
00227 virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
00228 Gecode::tan(home, x[0], x[0]);
00229 }
00230 };
00231
00233 class ASinXY : public Test {
00234 public:
00236 ASinXY(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st)
00237 : Test("Trigonometric::ASin::XY::"+s,2,d,st,CPLT_ASSIGNMENT,false) {}
00239 virtual MaybeType solution(const Assignment& x) const {
00240 if ((x[0].min() > 1.0) || (x[0].max() < -1.0))
00241 return MT_FALSE;
00242 return eq(asin(x[0]), x[1]);
00243 }
00245 virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
00246 if (flip())
00247 Gecode::asin(home, x[0], x[1]);
00248 else
00249 Gecode::rel(home, asin(x[0]) == x[1]);
00250 }
00251 };
00252
00254 class ASinXYSol : public Test {
00255 public:
00257 ASinXYSol(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st)
00258 : Test("Trigonometric::ASin::XY::Sol::"+s,2,d,st,EXTEND_ASSIGNMENT,false) {}
00260 virtual MaybeType solution(const Assignment& x) const {
00261 if ((x[0].min() > 1.0) || (x[0].max() < -1.0))
00262 return MT_FALSE;
00263 return eq(asin(x[0]), x[1]);
00264 }
00266 virtual bool extendAssignement(Assignment& x) const {
00267 if ((x[0].min() > 1.0) || (x[0].max() < -1.0))
00268 return false;
00269 Gecode::FloatVal d = asin(x[0]);
00270 if (Gecode::Float::subset(d, dom)) {
00271 x.set(1, d);
00272 return true;
00273 } else {
00274 return false;
00275 }
00276 }
00278 virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
00279 Gecode::asin(home, x[0], x[1]);
00280 }
00281 };
00282
00284 class ASinXX : public Test {
00285 public:
00287 ASinXX(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st)
00288 : Test("Trigonometric::ASin::XX::"+s,1,d,st,CPLT_ASSIGNMENT,false) {}
00290 virtual MaybeType solution(const Assignment& x) const {
00291 if ((x[0].min() > 1.0) || (x[0].max() < -1.0))
00292 return MT_FALSE;
00293 return eq(asin(x[0]), x[0]);
00294 }
00296 virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
00297 Gecode::asin(home, x[0], x[0]);
00298 }
00299 };
00300
00302 class ACosXY : public Test {
00303 public:
00305 ACosXY(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st)
00306 : Test("Trigonometric::ACos::XY::"+s,2,d,st,CPLT_ASSIGNMENT,false) {}
00308 virtual MaybeType solution(const Assignment& x) const {
00309 if ((x[0].min() > 1.0) || (x[0].max() < -1.0))
00310 return MT_FALSE;
00311 return eq(acos(x[0]), x[1]);
00312 }
00314 virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
00315 if (flip())
00316 Gecode::acos(home, x[0], x[1]);
00317 else
00318 Gecode::rel(home, acos(x[0]) == x[1]);
00319 }
00320 };
00321
00323 class ACosXYSol : public Test {
00324 public:
00326 ACosXYSol(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st)
00327 : Test("Trigonometric::ACos::XY::Sol::"+s,2,d,st,EXTEND_ASSIGNMENT,false) {}
00329 virtual MaybeType solution(const Assignment& x) const {
00330 if ((x[0].min() > 1.0) || (x[0].max() < -1.0))
00331 return MT_FALSE;
00332 return eq(acos(x[0]), x[1]);
00333 }
00335 virtual bool extendAssignement(Assignment& x) const {
00336 if ((x[0].min() > 1.0) || (x[0].max() < -1.0))
00337 return false;
00338 Gecode::FloatVal d = acos(x[0]);
00339 if (Gecode::Float::subset(d, dom)) {
00340 x.set(1, d);
00341 return true;
00342 } else {
00343 return false;
00344 }
00345 }
00347 virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
00348 Gecode::acos(home, x[0], x[1]);
00349 }
00350 };
00351
00353 class ACosXX : public Test {
00354 public:
00356 ACosXX(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st)
00357 : Test("Trigonometric::ACos::XX::"+s,1,d,st,CPLT_ASSIGNMENT,false) {}
00359 virtual MaybeType solution(const Assignment& x) const {
00360 if ((x[0].min() > 1.0) || (x[0].max() < -1.0))
00361 return MT_FALSE;
00362 return eq(acos(x[0]), x[0]);
00363 }
00365 virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
00366 Gecode::acos(home, x[0], x[0]);
00367 }
00368 };
00369
00371 class ATanXY : public Test {
00372 public:
00374 ATanXY(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st)
00375 : Test("Trigonometric::ATan::XY::"+s,2,d,st,CPLT_ASSIGNMENT,false) {}
00377 virtual MaybeType solution(const Assignment& x) const {
00378 return eq(atan(x[0]), x[1]);
00379 }
00381 virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
00382 if (flip())
00383 Gecode::atan(home, x[0], x[1]);
00384 else
00385 Gecode::rel(home, atan(x[0]) == x[1]);
00386 }
00387 };
00388
00390 class ATanXYSol : public Test {
00391 public:
00393 ATanXYSol(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st)
00394 : Test("Trigonometric::ATan::XY::Sol::"+s,2,d,st,EXTEND_ASSIGNMENT,false) {}
00396 virtual MaybeType solution(const Assignment& x) const {
00397 return eq(atan(x[0]), x[1]);
00398 }
00400 virtual bool extendAssignement(Assignment& x) const {
00401 Gecode::FloatVal d = atan(x[0]);
00402 if (Gecode::Float::subset(d, dom)) {
00403 x.set(1, d);
00404 return true;
00405 } else {
00406 return false;
00407 }
00408 }
00410 virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
00411 Gecode::atan(home, x[0], x[1]);
00412 }
00413 };
00414
00416 class ATanXX : public Test {
00417 public:
00419 ATanXX(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st)
00420 : Test("Trigonometric::ATan::XX::"+s,1,d,st,CPLT_ASSIGNMENT,false) {}
00422 virtual MaybeType solution(const Assignment& x) const {
00423 return eq(atan(x[0]), x[0]);
00424 }
00426 virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
00427 Gecode::atan(home, x[0], x[0]);
00428 }
00429 };
00430
00431 const Gecode::FloatNum step = 0.15;
00432 const Gecode::FloatNum step2 = 2*step;
00433 Gecode::FloatVal a(-8,5);
00434 Gecode::FloatVal b(9,12);
00435 Gecode::FloatVal c(-8,8);
00436
00437 SinXY sin_xy_a("A",a,step);
00438 SinXY sin_xy_b("B",b,step);
00439 SinXY sin_xy_c("C",c,step);
00440
00441 SinXYSol sin_xy_sol_a("A",a,step);
00442 SinXYSol sin_xy_sol_b("B",b,step);
00443 SinXYSol sin_xy_sol_c("C",c,step);
00444
00445 SinXX sin_xx_a("A",a,step);
00446 SinXX sin_xx_b("B",b,step);
00447 SinXX sin_xx_c("C",c,step);
00448
00449 CosXY cos_xy_a("A",a,step);
00450 CosXY cos_xy_b("B",b,step);
00451 CosXY cos_xy_c("C",c,step);
00452
00453 CosXYSol cos_xy_sol_a("A",a,step);
00454 CosXYSol cos_xy_sol_b("B",b,step);
00455 CosXYSol cos_xy_sol_c("C",c,step);
00456
00457 CosXX cos_xx_a("A",a,step);
00458 CosXX cos_xx_b("B",b,step);
00459 CosXX cos_xx_c("C",c,step);
00460
00461 TanXY tan_xy_a("A",a,step);
00462 TanXY tan_xy_b("B",b,step);
00463 TanXY tan_xy_c("C",c,step);
00464
00465 TanXYSol tan_xy_sol_a("A",a,step);
00466 TanXYSol tan_xy_sol_b("B",b,step);
00467 TanXYSol tan_xy_sol_c("C",c,step);
00468
00469 TanXX tan_xx_a("A",a,step);
00470 TanXX tan_xx_b("B",b,step);
00471 TanXX tan_xx_c("C",c,step);
00472
00473 ASinXY asin_xy_a("A",a,step);
00474 ASinXY asin_xy_b("B",b,step);
00475 ASinXY asin_xy_c("C",c,step);
00476
00477 ASinXYSol asin_xy_sol_a("A",a,step);
00478 ASinXYSol asin_xy_sol_b("B",b,step);
00479 ASinXYSol asin_xy_sol_c("C",c,step);
00480
00481 ASinXX asin_xx_a("A",a,step);
00482 ASinXX asin_xx_b("B",b,step);
00483 ASinXX asin_xx_c("C",c,step);
00484
00485 ACosXY acos_xy_a("A",a,step);
00486 ACosXY acos_xy_b("B",b,step);
00487 ACosXY acos_xy_c("C",c,step);
00488
00489 ACosXYSol acos_xy_sol_a("A",a,step);
00490 ACosXYSol acos_xy_sol_b("B",b,step);
00491 ACosXYSol acos_xy_sol_c("C",c,step);
00492
00493 ACosXX acos_xx_a("A",a,step);
00494 ACosXX acos_xx_b("B",b,step);
00495 ACosXX acos_xx_c("C",c,step);
00496
00497 ATanXY atan_xy_a("A",a,step);
00498 ATanXY atan_xy_b("B",b,step);
00499 ATanXY atan_xy_c("C",c,step);
00500
00501 ATanXYSol atan_xy_sol_a("A",a,step);
00502 ATanXYSol atan_xy_sol_b("B",b,step);
00503 ATanXYSol atan_xy_sol_c("C",c,step);
00504
00505 ATanXX atan_xx_a("A",a,step);
00506 ATanXX atan_xx_b("B",b,step);
00507 ATanXX atan_xx_c("C",c,step);
00508
00510
00511 }
00512 }}
00513
00514 #endif
00515