main page
modules
namespaces
classes
files
Gecode home
Generated on Tue Jan 28 2020 00:00:00 for Gecode by
doxygen
1.8.17
test
float
dom.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: 2015-01-20 20:48:23 +0100 (Tue, 20 Jan 2015) $ by $Author: schulte $
13
* $Revision: 14369 $
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
42
#include <
gecode/minimodel.hh
>
43
44
namespace
Test
{
namespace
Float {
45
47
namespace
Dom {
48
54
class
Val
:
public
Test
{
56
protected
:
58
Gecode::FloatVal
c
;
59
public
:
61
Val
(
int
n
,
Gecode::FloatVal
c0,
Gecode::FloatNum
st)
62
:
Test
(
"Dom::Val::"
+
str
(
n
)+
"::"
+
str
(c0),
63
n
,-3,3,st,
CPLT_ASSIGNMENT
,
n
==1),
c
(c0) {
64
testsubsumed
=
false
;
65
}
67
virtual
MaybeType
solution
(
const
Assignment
&
x
)
const
{
68
for
(
int
i
=
x
.size();
i
--; )
69
if
((
x
[
i
].
max
() >
c
.
max
()) || (
x
[
i
].min() <
c
.
min
()))
70
return
MT_FALSE
;
71
return
MT_TRUE
;
72
}
74
virtual
void
post
(
Gecode::Space
& home,
Gecode::FloatVarArray
&
x
) {
75
if
(
x
.size() == 1)
76
Gecode::dom
(home,
x
[0],
c
);
77
else
78
Gecode::dom
(home,
x
,
c
);
79
}
81
virtual
void
post
(
Gecode::Space
& home,
Gecode::FloatVarArray
&
x
,
82
Gecode::Reify
r
) {
83
assert(
x
.size() == 1);
84
Gecode::dom
(home,
x
[0],
c
,
r
);
85
}
86
};
87
89
class
Num
:
public
Test
{
90
protected
:
92
Gecode::FloatNum
min
;
94
Gecode::FloatNum
max
;
95
public
:
97
Num
(
int
n
,
Gecode::FloatNum
min0,
Gecode::FloatNum
max0,
98
Gecode::FloatNum
st)
99
:
Test
(
"Dom::Num::"
+
str
(
n
)+
"::"
+
str
(min0)+
"::"
+
str
(max0),
100
n
,-3,3,st,
CPLT_ASSIGNMENT
,
n
==1),
min
(min0),
max
(max0) {
101
testsubsumed
=
false
;
102
}
104
virtual
MaybeType
solution
(
const
Assignment
&
x
)
const
{
105
if
(
max
<
min
)
106
return
MT_FALSE
;
107
for
(
int
i
=
x
.size();
i
--; )
108
if
((
x
[
i
].
max
() >
max
) || (
x
[
i
].
min
() <
min
))
109
return
MT_FALSE
;
110
return
MT_TRUE
;
111
}
113
virtual
void
post
(
Gecode::Space
& home,
Gecode::FloatVarArray
&
x
) {
114
if
(
x
.size() == 1)
115
Gecode::dom
(home,
x
[0],
min
,
max
);
116
else
117
Gecode::dom
(home,
x
,
min
,
max
);
118
}
120
virtual
void
post
(
Gecode::Space
& home,
Gecode::FloatVarArray
&
x
,
121
Gecode::Reify
r
) {
122
assert(
x
.size() == 1);
123
Gecode::dom
(home,
x
[0],
min
,
max
,
r
);
124
}
125
};
126
128
class
Create
{
129
public
:
131
Create
(
void
) {
132
using namespace
Gecode
;
133
FloatNum
step
= 0.7;
134
for
(
int
c
=-4;
c
<=4;
c
++) {
135
(void)
new
Val
(1,
c
,
step
);
136
(void)
new
Val
(2,
c
,
step
);
137
for
(
int
d
=-3;
d
<=3;
d
++) {
138
(void)
new
Num
(1,
c
,
d
,
step
);
139
(void)
new
Num
(2,
c
,
d
,
step
);
140
}
141
}
142
}
143
};
144
145
Create
c
;
147
148
}
149
150
}}
151
152
// STATISTICS: test-float
Test::Float::Dom::Num::min
Gecode::FloatNum min
Float number.
Definition:
dom.cpp:92
Test::r
Region r
Definition:
region.cpp:82
Test::Float::Arithmetic::step
const Gecode::FloatNum step
Definition:
arithmetic.cpp:789
Gecode::FloatVal::max
friend FloatVal max(const FloatVal &x, const FloatVal &y)
Definition:
val.hpp:390
minimodel.hh
Gecode::FloatVal::min
friend FloatVal min(const FloatVal &x, const FloatVal &y)
Definition:
val.hpp:402
Test::Float::MT_FALSE
@ MT_FALSE
Definition:
float.hh:56
Test::Float::Dom::Create
Help class to create and register tests.
Definition:
dom.cpp:128
Test::Int::Basic::i
Gecode::IntArgs i(4, 1, 2, 3, 4)
Test::Float::Dom::Val
Test for domain constraints with a float value
Definition:
dom.cpp:55
Gecode::Space
Computation spaces.
Definition:
core.hpp:1748
Test::Float::MT_TRUE
@ MT_TRUE
Definition:
float.hh:57
Test::Float::Dom::Val::Val
Val(int n, Gecode::FloatVal c0, Gecode::FloatNum st)
Create and register test.
Definition:
dom.cpp:61
Test::Float::Dom::Num::Num
Num(int n, Gecode::FloatNum min0, Gecode::FloatNum max0, Gecode::FloatNum st)
Create and register test.
Definition:
dom.cpp:97
Test::Float::Dom::Val::post
virtual void post(Gecode::Space &home, Gecode::FloatVarArray &x)
Post constraint on x.
Definition:
dom.cpp:74
Test::Float::Dom::Num::post
virtual void post(Gecode::Space &home, Gecode::FloatVarArray &x)
Post constraint on x.
Definition:
dom.cpp:113
Test::Float::Dom::Num::post
virtual void post(Gecode::Space &home, Gecode::FloatVarArray &x, Gecode::Reify r)
Post reified constraint on x for r.
Definition:
dom.cpp:120
Gecode
Gecode toplevel namespace
Test::Float::Dom::Val::solution
virtual MaybeType solution(const Assignment &x) const
Test whether x is solution
Definition:
dom.cpp:67
float.hh
x
Node * x
Pointer to corresponding Boolean expression node.
Definition:
bool-expr.cpp:253
Gecode::Reify
Reification specification.
Definition:
int.hh:857
Test::Float::Dom::Val::post
virtual void post(Gecode::Space &home, Gecode::FloatVarArray &x, Gecode::Reify r)
Post reified constraint on x for r.
Definition:
dom.cpp:81
Gecode::dom
void dom(Home home, FloatVar x, FloatVal n)
Propagates .
Definition:
dom.cpp:44
Gecode::FloatNum
double FloatNum
Floating point number base type.
Definition:
float.hh:110
Test::Float::CPLT_ASSIGNMENT
@ CPLT_ASSIGNMENT
Definition:
float.hh:66
Test::Float::Dom::Create::Create
Create(void)
Perform creation and registration.
Definition:
dom.cpp:131
Test::Float::Dom::Num
Test for domain constraints with float numbers
Definition:
dom.cpp:89
Test::Float::Dom::Num::solution
virtual MaybeType solution(const Assignment &x) const
Test whether x is solution
Definition:
dom.cpp:104
Test::Float::Dom::c
Create c
Definition:
dom.cpp:145
Gecode::FloatVal
Float value type.
Definition:
float.hh:338
Test::Float::Test::str
static std::string str(Gecode::FloatRelType frt)
Map float relation to string.
Definition:
float.hpp:198
Test::Int::Dom::d
Gecode::IntSet d(r, 4)
Test::Float::Dom::Val::c
Gecode::FloatVal c
Float constant.
Definition:
dom.cpp:58
Test::Float::MaybeType
MaybeType
Type for comparisons and solutions.
Definition:
float.hh:55
Gecode::FloatVarArray
Float variable array.
Definition:
float.hh:1031
Test
General test support.
Definition:
afc.cpp:43
Test::Float::Assignment
Base class for assignments
Definition:
float.hh:84
Test::Float::Dom::Num::max
Gecode::FloatNum max
Float number.
Definition:
dom.cpp:94
n
int n
Number of negative literals for node type.
Definition:
bool-expr.cpp:238
Gecode::Float::Limits::max
const FloatNum max
Largest allowed float value.
Definition:
float.hh:848
Test::Float::Test::testsubsumed
bool testsubsumed
Whether to test for subsumption.
Definition:
float.hh:267