main page
modules
namespaces
classes
files
Gecode home
Generated on Sat May 25 2013 18:00:41 for Gecode by
doxygen
1.8.3.1
test
float
trigonometric.cpp
Go to the documentation of this file.
1
/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2
/*
3
* Main authors:
4
* Christian Schulte <schulte@gecode.org>
5
* Vincent Barichard <Vincent.Barichard@univ-angers.fr>
6
*
7
* Copyright:
8
* Christian Schulte, 2005
9
* Vincent Barichard, 2012
10
*
11
* Last modified:
12
* $Date: 2013-02-04 22:41:43 +0100 (Mon, 04 Feb 2013) $ by $Author: schulte $
13
* $Revision: 13264 $
14
*
15
* This file is part of Gecode, the generic constraint
16
* development environment:
17
* http://www.gecode.org
18
*
19
* Permission is hereby granted, free of charge, to any person obtaining
20
* a copy of this software and associated documentation files (the
21
* "Software"), to deal in the Software without restriction, including
22
* without limitation the rights to use, copy, modify, merge, publish,
23
* distribute, sublicense, and/or sell copies of the Software, and to
24
* permit persons to whom the Software is furnished to do so, subject to
25
* the following conditions:
26
*
27
* The above copyright notice and this permission notice shall be
28
* included in all copies or substantial portions of the Software.
29
*
30
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
31
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
32
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
33
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
34
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
35
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
36
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
37
*
38
*/
39
40
#include "
test/float.hh
"
41
#include <
gecode/minimodel.hh
>
42
43
#ifdef GECODE_HAS_MPFR
44
45
#include <cmath>
46
#include <algorithm>
47
48
namespace
Test {
namespace
Float {
49
51
namespace
Trigonometric {
52
54
class
SinXY
:
public
Test
{
55
public
:
57
SinXY
(
const
std::string& s,
const
Gecode::FloatVal
&
d
,
Gecode::FloatNum
st)
58
:
Test
(
"Trigonometric::Sin::XY::"
+s,2,d,st,
CPLT_ASSIGNMENT
,false) {}
60
virtual
MaybeType
solution
(
const
Assignment
&
x
)
const
{
61
return
eq
(
sin
(x[0]), x[1]);
62
}
64
virtual
void
post
(
Gecode::Space
& home,
Gecode::FloatVarArray
&
x
) {
65
if
(
flip
())
66
Gecode::sin
(home, x[0], x[1]);
67
else
68
Gecode::rel
(home,
sin
(x[0]) == x[1]);
69
}
70
};
71
73
class
SinXYSol
:
public
Test
{
74
public
:
76
SinXYSol
(
const
std::string& s,
const
Gecode::FloatVal
&
d
,
Gecode::FloatNum
st)
77
:
Test
(
"Trigonometric::Sin::XY::Sol::"
+s,2,d,st,
EXTEND_ASSIGNMENT
,false) {}
79
virtual
MaybeType
solution
(
const
Assignment
&
x
)
const
{
80
return
eq
(
sin
(x[0]), x[1]);
81
}
83
virtual
bool
extendAssignement
(
Assignment
&
x
)
const
{
84
Gecode::FloatVal
d
=
sin
(x[0]);
85
if
(
Gecode::Float::subset
(d,
dom
)) {
86
x.
set
(1, d);
87
return
true
;
88
}
else
{
89
return
false
;
90
}
91
}
93
virtual
void
post
(
Gecode::Space
& home,
Gecode::FloatVarArray
&
x
) {
94
Gecode::sin
(home, x[0], x[1]);
95
}
96
};
97
99
class
SinXX
:
public
Test
{
100
public
:
102
SinXX
(
const
std::string& s,
const
Gecode::FloatVal
&
d
,
Gecode::FloatNum
st)
103
:
Test
(
"Trigonometric::Sin::XX::"
+s,1,d,st,
CPLT_ASSIGNMENT
,false) {}
105
virtual
MaybeType
solution
(
const
Assignment
&
x
)
const
{
106
return
eq
(
sin
(x[0]), x[0]);
107
}
109
virtual
void
post
(
Gecode::Space
& home,
Gecode::FloatVarArray
&
x
) {
110
Gecode::sin
(home, x[0], x[0]);
111
}
112
};
113
115
class
CosXY
:
public
Test
{
116
public
:
118
CosXY
(
const
std::string& s,
const
Gecode::FloatVal
&
d
,
Gecode::FloatNum
st)
119
:
Test
(
"Trigonometric::Cos::XY::"
+s,2,d,st,
CPLT_ASSIGNMENT
,false) {}
121
virtual
MaybeType
solution
(
const
Assignment
&
x
)
const
{
122
return
eq
(
cos
(x[0]), x[1]);
123
}
125
virtual
void
post
(
Gecode::Space
& home,
Gecode::FloatVarArray
&
x
) {
126
if
(
flip
())
127
Gecode::cos
(home, x[0], x[1]);
128
else
129
Gecode::rel
(home,
cos
(x[0]) == x[1]);
130
}
131
};
132
134
class
CosXYSol
:
public
Test
{
135
public
:
137
CosXYSol
(
const
std::string& s,
const
Gecode::FloatVal
&
d
,
Gecode::FloatNum
st)
138
:
Test
(
"Trigonometric::Cos::XY::Sol::"
+s,2,d,st,
EXTEND_ASSIGNMENT
,false) {}
140
virtual
MaybeType
solution
(
const
Assignment
&
x
)
const
{
141
return
eq
(
cos
(x[0]), x[1]);
142
}
144
virtual
bool
extendAssignement
(
Assignment
&
x
)
const
{
145
Gecode::FloatVal
d
=
cos
(x[0]);
146
if
(
Gecode::Float::subset
(d,
dom
)) {
147
x.
set
(1, d);
148
return
true
;
149
}
else
{
150
return
false
;
151
}
152
}
154
virtual
void
post
(
Gecode::Space
& home,
Gecode::FloatVarArray
&
x
) {
155
Gecode::cos
(home, x[0], x[1]);
156
}
157
};
158
160
class
CosXX
:
public
Test
{
161
public
:
163
CosXX
(
const
std::string& s,
const
Gecode::FloatVal
&
d
,
Gecode::FloatNum
st)
164
:
Test
(
"Trigonometric::Cos::XX::"
+s,1,d,st,
CPLT_ASSIGNMENT
,false) {}
166
virtual
MaybeType
solution
(
const
Assignment
&
x
)
const
{
167
return
eq
(
cos
(x[0]), x[0]);
168
}
170
virtual
void
post
(
Gecode::Space
& home,
Gecode::FloatVarArray
&
x
) {
171
Gecode::cos
(home, x[0], x[0]);
172
}
173
};
174
176
class
TanXY
:
public
Test
{
177
public
:
179
TanXY
(
const
std::string& s,
const
Gecode::FloatVal
&
d
,
Gecode::FloatNum
st)
180
:
Test
(
"Trigonometric::Tan::XY::"
+s,2,d,st,
CPLT_ASSIGNMENT
,false) {}
182
virtual
MaybeType
solution
(
const
Assignment
&
x
)
const
{
183
return
eq
(
tan
(x[0]), x[1]);
184
}
186
virtual
void
post
(
Gecode::Space
& home,
Gecode::FloatVarArray
&
x
) {
187
if
(
flip
())
188
Gecode::tan
(home, x[0], x[1]);
189
else
190
Gecode::rel
(home,
tan
(x[0]) == x[1]);
191
}
192
};
193
195
class
TanXYSol
:
public
Test
{
196
public
:
198
TanXYSol
(
const
std::string& s,
const
Gecode::FloatVal
&
d
,
Gecode::FloatNum
st)
199
:
Test
(
"Trigonometric::Tan::XY::Sol::"
+s,2,d,st,
EXTEND_ASSIGNMENT
,false) {}
201
virtual
MaybeType
solution
(
const
Assignment
&
x
)
const
{
202
return
eq
(
tan
(x[0]), x[1]);
203
}
205
virtual
bool
extendAssignement
(
Assignment
&
x
)
const
{
206
Gecode::FloatVal
d
=
tan
(x[0]);
207
if
(
Gecode::Float::subset
(d,
dom
)) {
208
x.
set
(1, d);
209
return
true
;
210
}
else
{
211
return
false
;
212
}
213
}
215
virtual
void
post
(
Gecode::Space
& home,
Gecode::FloatVarArray
&
x
) {
216
Gecode::tan
(home, x[0], x[1]);
217
}
218
};
219
221
class
TanXX
:
public
Test
{
222
public
:
224
TanXX
(
const
std::string& s,
const
Gecode::FloatVal
&
d
,
Gecode::FloatNum
st)
225
:
Test
(
"Trigonometric::Tan::XX::"
+s,1,d,st,
CPLT_ASSIGNMENT
,false) {}
227
virtual
MaybeType
solution
(
const
Assignment
&
x
)
const
{
228
return
eq
(
tan
(x[0]), x[0]);
229
}
231
virtual
void
post
(
Gecode::Space
& home,
Gecode::FloatVarArray
&
x
) {
232
Gecode::tan
(home, x[0], x[0]);
233
}
234
};
235
237
class
ASinXY
:
public
Test
{
238
public
:
240
ASinXY
(
const
std::string& s,
const
Gecode::FloatVal
&
d
,
Gecode::FloatNum
st)
241
:
Test
(
"Trigonometric::ASin::XY::"
+s,2,d,st,
CPLT_ASSIGNMENT
,false) {}
243
virtual
MaybeType
solution
(
const
Assignment
&
x
)
const
{
244
if
((x[0].
min
() > 1.0) || (x[0].
max
() < -1.0))
245
return
MT_FALSE
;
246
return
eq
(
asin
(x[0]), x[1]);
247
}
249
virtual
void
post
(
Gecode::Space
& home,
Gecode::FloatVarArray
&
x
) {
250
if
(
flip
())
251
Gecode::asin
(home, x[0], x[1]);
252
else
253
Gecode::rel
(home,
asin
(x[0]) == x[1]);
254
}
255
};
256
258
class
ASinXYSol
:
public
Test
{
259
public
:
261
ASinXYSol
(
const
std::string& s,
const
Gecode::FloatVal
&
d
,
Gecode::FloatNum
st)
262
:
Test
(
"Trigonometric::ASin::XY::Sol::"
+s,2,d,st,
EXTEND_ASSIGNMENT
,false) {}
264
virtual
MaybeType
solution
(
const
Assignment
&
x
)
const
{
265
if
((x[0].
min
() > 1.0) || (x[0].
max
() < -1.0))
266
return
MT_FALSE
;
267
return
eq
(
asin
(x[0]), x[1]);
268
}
270
virtual
bool
extendAssignement
(
Assignment
&
x
)
const
{
271
if
((x[0].
min
() > 1.0) || (x[0].
max
() < -1.0))
272
return
false
;
273
Gecode::FloatVal
d
=
asin
(x[0]);
274
if
(
Gecode::Float::subset
(d,
dom
)) {
275
x.
set
(1, d);
276
return
true
;
277
}
else
{
278
return
false
;
279
}
280
}
282
virtual
void
post
(
Gecode::Space
& home,
Gecode::FloatVarArray
&
x
) {
283
Gecode::asin
(home, x[0], x[1]);
284
}
285
};
286
288
class
ASinXX
:
public
Test
{
289
public
:
291
ASinXX
(
const
std::string& s,
const
Gecode::FloatVal
&
d
,
Gecode::FloatNum
st)
292
:
Test
(
"Trigonometric::ASin::XX::"
+s,1,d,st,
CPLT_ASSIGNMENT
,false) {}
294
virtual
MaybeType
solution
(
const
Assignment
&
x
)
const
{
295
if
((x[0].
min
() > 1.0) || (x[0].
max
() < -1.0))
296
return
MT_FALSE
;
297
return
eq
(
asin
(x[0]), x[0]);
298
}
300
virtual
void
post
(
Gecode::Space
& home,
Gecode::FloatVarArray
&
x
) {
301
Gecode::asin
(home, x[0], x[0]);
302
}
303
};
304
306
class
ACosXY
:
public
Test
{
307
public
:
309
ACosXY
(
const
std::string& s,
const
Gecode::FloatVal
&
d
,
Gecode::FloatNum
st)
310
:
Test
(
"Trigonometric::ACos::XY::"
+s,2,d,st,
CPLT_ASSIGNMENT
,false) {}
312
virtual
MaybeType
solution
(
const
Assignment
&
x
)
const
{
313
if
((x[0].
min
() > 1.0) || (x[0].
max
() < -1.0))
314
return
MT_FALSE
;
315
return
eq
(
acos
(x[0]), x[1]);
316
}
318
virtual
void
post
(
Gecode::Space
& home,
Gecode::FloatVarArray
&
x
) {
319
if
(
flip
())
320
Gecode::acos
(home, x[0], x[1]);
321
else
322
Gecode::rel
(home,
acos
(x[0]) == x[1]);
323
}
324
};
325
327
class
ACosXYSol
:
public
Test
{
328
public
:
330
ACosXYSol
(
const
std::string& s,
const
Gecode::FloatVal
&
d
,
Gecode::FloatNum
st)
331
:
Test
(
"Trigonometric::ACos::XY::Sol::"
+s,2,d,st,
EXTEND_ASSIGNMENT
,false) {}
333
virtual
MaybeType
solution
(
const
Assignment
&
x
)
const
{
334
if
((x[0].
min
() > 1.0) || (x[0].
max
() < -1.0))
335
return
MT_FALSE
;
336
return
eq
(
acos
(x[0]), x[1]);
337
}
339
virtual
bool
extendAssignement
(
Assignment
&
x
)
const
{
340
if
((x[0].
min
() > 1.0) || (x[0].
max
() < -1.0))
341
return
false
;
342
Gecode::FloatVal
d
=
acos
(x[0]);
343
if
(
Gecode::Float::subset
(d,
dom
)) {
344
x.
set
(1, d);
345
return
true
;
346
}
else
{
347
return
false
;
348
}
349
}
351
virtual
void
post
(
Gecode::Space
& home,
Gecode::FloatVarArray
&
x
) {
352
Gecode::acos
(home, x[0], x[1]);
353
}
354
};
355
357
class
ACosXX
:
public
Test
{
358
public
:
360
ACosXX
(
const
std::string& s,
const
Gecode::FloatVal
&
d
,
Gecode::FloatNum
st)
361
:
Test
(
"Trigonometric::ACos::XX::"
+s,1,d,st,
CPLT_ASSIGNMENT
,false) {}
363
virtual
MaybeType
solution
(
const
Assignment
&
x
)
const
{
364
if
((x[0].
min
() > 1.0) || (x[0].
max
() < -1.0))
365
return
MT_FALSE
;
366
return
eq
(
acos
(x[0]), x[0]);
367
}
369
virtual
void
post
(
Gecode::Space
& home,
Gecode::FloatVarArray
&
x
) {
370
Gecode::acos
(home, x[0], x[0]);
371
}
372
};
373
375
class
ATanXY
:
public
Test
{
376
public
:
378
ATanXY
(
const
std::string& s,
const
Gecode::FloatVal
&
d
,
Gecode::FloatNum
st)
379
:
Test
(
"Trigonometric::ATan::XY::"
+s,2,d,st,
CPLT_ASSIGNMENT
,false) {}
381
virtual
MaybeType
solution
(
const
Assignment
&
x
)
const
{
382
return
eq
(
atan
(x[0]), x[1]);
383
}
385
virtual
void
post
(
Gecode::Space
& home,
Gecode::FloatVarArray
&
x
) {
386
if
(
flip
())
387
Gecode::atan
(home, x[0], x[1]);
388
else
389
Gecode::rel
(home,
atan
(x[0]) == x[1]);
390
}
391
};
392
394
class
ATanXYSol
:
public
Test
{
395
public
:
397
ATanXYSol
(
const
std::string& s,
const
Gecode::FloatVal
&
d
,
Gecode::FloatNum
st)
398
:
Test
(
"Trigonometric::ATan::XY::Sol::"
+s,2,d,st,
EXTEND_ASSIGNMENT
,false) {}
400
virtual
MaybeType
solution
(
const
Assignment
&
x
)
const
{
401
return
eq
(
atan
(x[0]), x[1]);
402
}
404
virtual
bool
extendAssignement
(
Assignment
&
x
)
const
{
405
Gecode::FloatVal
d
=
atan
(x[0]);
406
if
(
Gecode::Float::subset
(d,
dom
)) {
407
x.
set
(1, d);
408
return
true
;
409
}
else
{
410
return
false
;
411
}
412
}
414
virtual
void
post
(
Gecode::Space
& home,
Gecode::FloatVarArray
&
x
) {
415
Gecode::atan
(home, x[0], x[1]);
416
}
417
};
418
420
class
ATanXX
:
public
Test
{
421
public
:
423
ATanXX
(
const
std::string& s,
const
Gecode::FloatVal
&
d
,
Gecode::FloatNum
st)
424
:
Test
(
"Trigonometric::ATan::XX::"
+s,1,d,st,
CPLT_ASSIGNMENT
,false) {}
426
virtual
MaybeType
solution
(
const
Assignment
&
x
)
const
{
427
return
eq
(
atan
(x[0]), x[0]);
428
}
430
virtual
void
post
(
Gecode::Space
& home,
Gecode::FloatVarArray
&
x
) {
431
Gecode::atan
(home, x[0], x[0]);
432
}
433
};
434
435
const
Gecode::FloatNum
step
= 0.15;
436
const
Gecode::FloatNum
step2
= 2*
step
;
437
Gecode::FloatVal
a
(-8,5);
438
Gecode::FloatVal
b
(9,12);
439
Gecode::FloatVal
c
(-8,8);
440
441
SinXY
sin_xy_a
(
"A"
,
a
,
step
);
442
SinXY
sin_xy_b
(
"B"
,
b
,
step
);
443
SinXY
sin_xy_c
(
"C"
,
c
,
step
);
444
445
SinXYSol
sin_xy_sol_a
(
"A"
,
a
,
step
);
446
SinXYSol
sin_xy_sol_b
(
"B"
,
b
,
step
);
447
SinXYSol
sin_xy_sol_c
(
"C"
,
c
,
step
);
448
449
SinXX
sin_xx_a
(
"A"
,
a
,
step
);
450
SinXX
sin_xx_b
(
"B"
,
b
,
step
);
451
SinXX
sin_xx_c
(
"C"
,
c
,
step
);
452
453
CosXY
cos_xy_a
(
"A"
,
a
,
step
);
454
CosXY
cos_xy_b
(
"B"
,
b
,
step
);
455
CosXY
cos_xy_c
(
"C"
,
c
,
step
);
456
457
CosXYSol
cos_xy_sol_a
(
"A"
,
a
,
step
);
458
CosXYSol
cos_xy_sol_b
(
"B"
,
b
,
step
);
459
CosXYSol
cos_xy_sol_c
(
"C"
,
c
,
step
);
460
461
CosXX
cos_xx_a
(
"A"
,
a
,
step
);
462
CosXX
cos_xx_b
(
"B"
,
b
,
step
);
463
CosXX
cos_xx_c
(
"C"
,
c
,
step
);
464
465
TanXY
tan_xy_a
(
"A"
,
a
,
step
);
466
TanXY
tan_xy_b
(
"B"
,
b
,
step
);
467
TanXY
tan_xy_c
(
"C"
,
c
,
step
);
468
469
TanXYSol
tan_xy_sol_a
(
"A"
,
a
,
step
);
470
TanXYSol
tan_xy_sol_b
(
"B"
,
b
,
step
);
471
TanXYSol
tan_xy_sol_c
(
"C"
,
c
,
step
);
472
473
TanXX
tan_xx_a
(
"A"
,
a
,
step
);
474
TanXX
tan_xx_b
(
"B"
,
b
,
step
);
475
TanXX
tan_xx_c
(
"C"
,
c
,
step
);
476
477
ASinXY
asin_xy_a
(
"A"
,
a
,
step
);
478
ASinXY
asin_xy_b
(
"B"
,
b
,
step
);
479
ASinXY
asin_xy_c
(
"C"
,
c
,
step
);
480
481
ASinXYSol
asin_xy_sol_a
(
"A"
,
a
,
step
);
482
ASinXYSol
asin_xy_sol_b
(
"B"
,
b
,
step
);
483
ASinXYSol
asin_xy_sol_c
(
"C"
,
c
,
step
);
484
485
ASinXX
asin_xx_a
(
"A"
,
a
,
step
);
486
ASinXX
asin_xx_b
(
"B"
,
b
,
step
);
487
ASinXX
asin_xx_c
(
"C"
,
c
,
step
);
488
489
ACosXY
acos_xy_a
(
"A"
,
a
,
step
);
490
ACosXY
acos_xy_b
(
"B"
,
b
,
step
);
491
ACosXY
acos_xy_c
(
"C"
,
c
,
step
);
492
493
ACosXYSol
acos_xy_sol_a
(
"A"
,
a
,
step
);
494
ACosXYSol
acos_xy_sol_b
(
"B"
,
b
,
step
);
495
ACosXYSol
acos_xy_sol_c
(
"C"
,
c
,
step
);
496
497
ACosXX
acos_xx_a
(
"A"
,
a
,
step
);
498
ACosXX
acos_xx_b
(
"B"
,
b
,
step
);
499
ACosXX
acos_xx_c
(
"C"
,
c
,
step
);
500
501
ATanXY
atan_xy_a
(
"A"
,
a
,
step
);
502
ATanXY
atan_xy_b
(
"B"
,
b
,
step
);
503
ATanXY
atan_xy_c
(
"C"
,
c
,
step
);
504
505
ATanXYSol
atan_xy_sol_a
(
"A"
,
a
,
step
);
506
ATanXYSol
atan_xy_sol_b
(
"B"
,
b
,
step
);
507
ATanXYSol
atan_xy_sol_c
(
"C"
,
c
,
step
);
508
509
ATanXX
atan_xx_a
(
"A"
,
a
,
step
);
510
ATanXX
atan_xx_b
(
"B"
,
b
,
step
);
511
ATanXX
atan_xx_c
(
"C"
,
c
,
step
);
512
514
515
}
516
}}
517
518
#endif
519
// STATISTICS: test-float