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
00037
00038
00039
00040 #include "test/float.hh"
00041 #include <gecode/minimodel.hh>
00042
00043 #ifdef GECODE_HAS_MPFR
00044
00045 #include <cmath>
00046 #include <algorithm>
00047
00048 namespace Test { namespace Float {
00049
00051 namespace Transcendental {
00052
00054 class ExpXY : public Test {
00055 public:
00057 ExpXY(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st)
00058 : Test("Transcendental::Exp::XY::"+s,2,d,st,CPLT_ASSIGNMENT,false) {}
00060 virtual MaybeType solution(const Assignment& x) const {
00061 return eq(exp(x[0]), x[1]);
00062 }
00064 virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
00065 if (flip())
00066 Gecode::exp(home, x[0], x[1]);
00067 else
00068 Gecode::rel(home, exp(x[0]) == x[1]);
00069 }
00070 };
00071
00073 class ExpXYSol : public Test {
00074 public:
00076 ExpXYSol(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st)
00077 : Test("Transcendental::Exp::XY::Sol::"+s,2,d,st,EXTEND_ASSIGNMENT,false) {}
00079 virtual MaybeType solution(const Assignment& x) const {
00080 return eq(exp(x[0]), x[1]);
00081 }
00083 virtual bool extendAssignement(Assignment& x) const {
00084 Gecode::FloatVal d = exp(x[0]);
00085 if (Gecode::Float::subset(d, dom)) {
00086 x.set(1, d);
00087 return true;
00088 } else {
00089 return false;
00090 }
00091 }
00093 virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
00094 Gecode::exp(home, x[0], x[1]);
00095 }
00096 };
00097
00099 class ExpXX : public Test {
00100 public:
00102 ExpXX(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st)
00103 : Test("Transcendental::Exp::XX::"+s,1,d,st,CPLT_ASSIGNMENT,false) {}
00105 virtual MaybeType solution(const Assignment& x) const {
00106 return eq(exp(x[0]), x[0]);
00107 }
00109 virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
00110 Gecode::exp(home, x[0], x[0]);
00111 }
00112 };
00113
00115 class LogXY : public Test {
00116 public:
00118 LogXY(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st)
00119 : Test("Transcendental::Log::XY::"+s,2,d,st,CPLT_ASSIGNMENT,false) {}
00121 virtual MaybeType solution(const Assignment& x) const {
00122 if (x[0].max() < 0.0)
00123 return MT_FALSE;
00124 return eq(log(x[0]), x[1]);
00125 }
00127 virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
00128 if (flip())
00129 Gecode::log(home, x[0], x[1]);
00130 else
00131 Gecode::rel(home, log(x[0]) == x[1]);
00132 }
00133 };
00134
00136 class LogXYSol : public Test {
00137 public:
00139 LogXYSol(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st)
00140 : Test("Transcendental::Log::XY::Sol::"+s,2,d,st,EXTEND_ASSIGNMENT,false) {}
00142 virtual MaybeType solution(const Assignment& x) const {
00143 if (x[0].max() < 0.0)
00144 return MT_FALSE;
00145 return eq(log(x[0]), x[1]);
00146 }
00148 virtual bool extendAssignement(Assignment& x) const {
00149 if (x[0].max() < 0.0) return false;
00150 Gecode::FloatVal d = log(x[0]);
00151 if (Gecode::Float::subset(d, dom)) {
00152 x.set(1, d);
00153 return true;
00154 } else {
00155 return false;
00156 }
00157 }
00159 virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
00160 Gecode::log(home, x[0], x[1]);
00161 }
00162 };
00163
00165 class LogXX : public Test {
00166 public:
00168 LogXX(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum st)
00169 : Test("Transcendental::Log::XX::"+s,1,d,st,CPLT_ASSIGNMENT,false) {}
00171 virtual MaybeType solution(const Assignment& x) const {
00172 if (x[0].max() < 0.0)
00173 return MT_FALSE;
00174 return eq(log(x[0]), x[0]);
00175 }
00177 virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
00178 Gecode::log(home, x[0], x[0]);
00179 }
00180 };
00181
00183 class LogNXY : public Test {
00184 Gecode::FloatNum base;
00185 public:
00187 LogNXY(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum _base, Gecode::FloatNum st)
00188 : Test("Transcendental::Log::N::"+str(_base)+"::XY::"+s,2,d,st,CPLT_ASSIGNMENT,false), base(_base) {}
00190 virtual MaybeType solution(const Assignment& x) const {
00191 if ((x[0].max() <= 0.0) || (base <= 0.0))
00192 return MT_FALSE;
00193 return eq(log(x[0]) / log(base), x[1]);
00194 }
00196 virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
00197 Gecode::log(home, base, x[0], x[1]);
00198 }
00199 };
00200
00202 class LogNXYSol : public Test {
00203 Gecode::FloatNum base;
00204 public:
00206 LogNXYSol(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum _base, Gecode::FloatNum st)
00207 : Test("Transcendental::Log::N::"+str(_base)+"::XY::Sol::"+s,2,d,st,EXTEND_ASSIGNMENT,false), base(_base) {}
00209 virtual MaybeType solution(const Assignment& x) const {
00210 if ((x[0].max() <= 0.0) || (base <= 0.0))
00211 return MT_FALSE;
00212 return eq(log(x[0]) / log(base), x[1]);
00213 }
00215 virtual bool extendAssignement(Assignment& x) const {
00216 if ((x[0].max() <= 0.0) || (base <= 0.0))
00217 return false;
00218 Gecode::FloatVal d = log(x[0])/log(base);
00219 if (Gecode::Float::subset(d, dom)) {
00220 x.set(1, d);
00221 return true;
00222 } else {
00223 return false;
00224 }
00225 }
00227 virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
00228 Gecode::log(home, base, x[0], x[1]);
00229 }
00230 };
00231
00233 class LogNXX : public Test {
00234 Gecode::FloatNum base;
00235 public:
00237 LogNXX(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum _base, Gecode::FloatNum st)
00238 : Test("Transcendental::Log::N::"+str(_base)+"::XX::"+s,1,d,st,CPLT_ASSIGNMENT,false), base(_base) {}
00240 virtual MaybeType solution(const Assignment& x) const {
00241 if ((x[0].max() <= 0.0) || (base <= 0.0))
00242 return MT_FALSE;
00243 return eq(log(x[0]) / log(base), x[0]);
00244 }
00246 virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
00247 Gecode::log(home, base, x[0], x[0]);
00248 }
00249 };
00250
00252 class PowXY : public Test {
00253 Gecode::FloatNum base;
00254 public:
00256 PowXY(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum _base, Gecode::FloatNum st)
00257 : Test("Transcendental::Pow::N::"+str(_base)+"::XY::"+s,2,d,st,CPLT_ASSIGNMENT,false), base(_base) {}
00259 virtual MaybeType solution(const Assignment& x) const {
00260 if (base <= 0.0)
00261 return MT_FALSE;
00262 return eq(exp(x[0] * log(base)), x[1]);
00263 }
00265 virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
00266 Gecode::pow(home, base, x[0], x[1]);
00267 }
00268 };
00269
00271 class PowXYSol : public Test {
00272 Gecode::FloatNum base;
00273 public:
00275 PowXYSol(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum _base, Gecode::FloatNum st)
00276 : Test("Transcendental::Pow::N::"+str(_base)+"::XY::Sol::"+s,2,d,st,EXTEND_ASSIGNMENT,false), base(_base) {}
00278 virtual MaybeType solution(const Assignment& x) const {
00279 if (base <= 0.0)
00280 return MT_FALSE;
00281 return eq(exp(x[0] * log(base)), x[1]);
00282 }
00284 virtual bool extendAssignement(Assignment& x) const {
00285 if (base <= 0.0) return false;
00286 Gecode::FloatVal d = exp(x[0]*log(base));
00287 if (Gecode::Float::subset(d, dom)) {
00288 x.set(1, d);
00289 return true;
00290 } else {
00291 return false;
00292 }
00293 }
00295 virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
00296 Gecode::pow(home, base, x[0], x[1]);
00297 }
00298 };
00299
00301 class PowXX : public Test {
00302 Gecode::FloatNum base;
00303 public:
00305 PowXX(const std::string& s, const Gecode::FloatVal& d, Gecode::FloatNum _base, Gecode::FloatNum st)
00306 : Test("Transcendental::Pow::N::"+str(_base)+"::XX::"+s,1,d,st,CPLT_ASSIGNMENT,false), base(_base) {}
00308 virtual MaybeType solution(const Assignment& x) const {
00309 if ((x[0].max() <= 0.0) || (base <= 0.0))
00310 return MT_FALSE;
00311 return eq(exp(x[0] * log(base)), x[0]);
00312 }
00314 virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
00315 Gecode::pow(home, base, x[0], x[0]);
00316 }
00317 };
00318
00319 const Gecode::FloatNum step = 0.15;
00320 const Gecode::FloatNum step2 = 2*step;
00321 Gecode::FloatVal a(-8,5);
00322 Gecode::FloatVal b(9,12);
00323 Gecode::FloatVal c(-8,8);
00324
00325 ExpXY exp_xy_a("A",a,step);
00326 ExpXY exp_xy_b("B",b,step);
00327 ExpXY exp_xy_c("C",c,step);
00328
00329 ExpXYSol exp_xy_sol_a("A",a,step);
00330 ExpXYSol exp_xy_sol_b("B",b,step);
00331 ExpXYSol exp_xy_sol_c("C",c,step);
00332
00333 ExpXX exp_xx_a("A",a,step);
00334 ExpXX exp_xx_b("B",b,step);
00335 ExpXX exp_xx_c("C",c,step);
00336
00337 LogXY log_xy_a("A",a,step);
00338 LogXY log_xy_b("B",b,step);
00339 LogXY log_xy_c("C",c,step);
00340
00341 LogXYSol log_xy_sol_a("A",a,step);
00342 LogXYSol log_xy_sol_b("B",b,step);
00343 LogXYSol log_xy_sol_c("C",c,step);
00344
00345 LogXX log_xx_a("A",a,step);
00346 LogXX log_xx_b("B",b,step);
00347 LogXX log_xx_c("C",c,step);
00348
00349 LogNXY logn_xy_a_1("A",a,-1.5,step);
00350 LogNXY logn_xy_b_1("B",b,-1.5,step);
00351 LogNXY logn_xy_c_1("C",c,-1.5,step);
00352
00353 LogNXYSol logn_xy_sol_a_1("A",a,-1.5,step);
00354 LogNXYSol logn_xy_sol_b_1("B",b,-1.5,step);
00355 LogNXYSol logn_xy_sol_c_1("C",c,-1.5,step);
00356
00357 LogNXX logn_xx_a_1("A",a,-1.5,step);
00358 LogNXX logn_xx_b_1("B",b,-1.5,step);
00359 LogNXX logn_xx_c_1("C",c,-1.5,step);
00360
00361 LogNXY logn_xy_a_2("A",a,1.5,step);
00362 LogNXY logn_xy_b_2("B",b,1.5,step);
00363 LogNXY logn_xy_c_2("C",c,1.5,step);
00364
00365 LogNXYSol logn_xy_sol_a_2("A",a,1.5,step);
00366 LogNXYSol logn_xy_sol_b_2("B",b,1.5,step);
00367 LogNXYSol logn_xy_sol_c_2("C",c,1.5,step);
00368
00369 LogNXX logn_xx_a_2("A",a,1.5,step);
00370 LogNXX logn_xx_b_2("B",b,1.5,step);
00371 LogNXX logn_xx_c_2("C",c,1.5,step);
00372
00373 LogNXY logn_xy_a_3("A",a,0,step);
00374 LogNXY logn_xy_b_3("B",b,0,step);
00375 LogNXY logn_xy_c_3("C",c,0,step);
00376
00377 LogNXYSol logn_xy_sol_a_3("A",a,0,step);
00378 LogNXYSol logn_xy_sol_b_3("B",b,0,step);
00379 LogNXYSol logn_xy_sol_c_3("C",c,0,step);
00380
00381 LogNXX logn_xx_a_3("A",a,0,step);
00382 LogNXX logn_xx_b_3("B",b,0,step);
00383 LogNXX logn_xx_c_3("C",c,0,step);
00384
00385 PowXY pow_xy_a_1("A",a,-1.5,step);
00386 PowXY pow_xy_b_1("B",b,-1.5,step);
00387 PowXY pow_xy_c_1("C",c,-1.5,step);
00388
00389 PowXYSol pow_xy_sol_a_1("A",a,-1.5,step);
00390 PowXYSol pow_xy_sol_b_1("B",b,-1.5,step);
00391 PowXYSol pow_xy_sol_c_1("C",c,-1.5,step);
00392
00393 PowXX pow_xx_a_1("A",a,-1.5,step);
00394 PowXX pow_xx_b_1("B",b,-1.5,step);
00395 PowXX pow_xx_c_1("C",c,-1.5,step);
00396
00397 PowXY pow_xy_a_2("A",a,1.5,step);
00398 PowXY pow_xy_b_2("B",b,1.5,step);
00399 PowXY pow_xy_c_2("C",c,1.5,step);
00400
00401 PowXYSol pow_xy_sol_a_2("A",a,1.5,step);
00402 PowXYSol pow_xy_sol_b_2("B",b,1.5,step);
00403 PowXYSol pow_xy_sol_c_2("C",c,1.5,step);
00404
00405 PowXX pow_xx_a_2("A",a,1.5,step);
00406 PowXX pow_xx_b_2("B",b,1.5,step);
00407 PowXX pow_xx_c_2("C",c,1.5,step);
00408
00409 PowXY pow_xy_a_3("A",a,0,step);
00410 PowXY pow_xy_b_3("B",b,0,step);
00411 PowXY pow_xy_c_3("C",c,0,step);
00412
00413 PowXYSol pow_xy_sol_a_3("A",a,0,step);
00414 PowXYSol pow_xy_sol_b_3("B",b,0,step);
00415 PowXYSol pow_xy_sol_c_3("C",c,0,step);
00416
00417 PowXX pow_xx_a_3("A",a,0,step);
00418 PowXX pow_xx_b_3("B",b,0,step);
00419 PowXX pow_xx_c_3("C",c,0,step);
00420
00422
00423 }
00424 }}
00425
00426 #endif
00427