main page
modules
namespaces
classes
files
Gecode home
Generated on Fri Jan 10 2020 11:38:25 for Gecode by
doxygen
1.8.16
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
* This file is part of Gecode, the generic constraint
12
* development environment:
13
* http://www.gecode.org
14
*
15
* Permission is hereby granted, free of charge, to any person obtaining
16
* a copy of this software and associated documentation files (the
17
* "Software"), to deal in the Software without restriction, including
18
* without limitation the rights to use, copy, modify, merge, publish,
19
* distribute, sublicense, and/or sell copies of the Software, and to
20
* permit persons to whom the Software is furnished to do so, subject to
21
* the following conditions:
22
*
23
* The above copyright notice and this permission notice shall be
24
* included in all copies or substantial portions of the Software.
25
*
26
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
27
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
28
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
29
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
30
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
31
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
32
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
33
*
34
*/
35
36
#include "
test/float.hh
"
37
38
#include <
gecode/minimodel.hh
>
39
40
namespace
Test
{
namespace
Float {
41
43
namespace
Dom {
44
50
class
Val
:
public
Test
{
52
protected
:
54
Gecode::FloatVal
c
;
55
public
:
57
Val
(
int
n
,
Gecode::FloatVal
c0,
Gecode::FloatNum
st)
58
:
Test
(
"Dom::Val::"
+
str
(
n
)+
"::"
+
str
(c0),
59
n
,-3,3,st,
CPLT_ASSIGNMENT
,
n
==1),
c
(c0) {
60
testsubsumed
=
false
;
61
}
63
virtual
MaybeType
solution
(
const
Assignment
&
x
)
const
{
64
for
(
int
i
=
x
.size();
i
--; )
65
if
((
x
[
i
].
max
() >
c
.
max
()) || (
x
[
i
].
min
() <
c
.
min
()))
66
return
MT_FALSE
;
67
return
MT_TRUE
;
68
}
70
virtual
void
post
(
Gecode::Space
& home,
Gecode::FloatVarArray
&
x
) {
71
if
(
x
.size() == 1)
72
Gecode::dom
(home,
x
[0],
c
);
73
else
74
Gecode::dom
(home,
x
,
c
);
75
}
77
virtual
void
post
(
Gecode::Space
& home,
Gecode::FloatVarArray
&
x
,
78
Gecode::Reify
r
) {
79
assert(
x
.size() == 1);
80
Gecode::dom
(home,
x
[0],
c
,
r
);
81
}
82
};
83
85
class
Num
:
public
Test
{
86
protected
:
88
Gecode::FloatNum
min
;
90
Gecode::FloatNum
max
;
91
public
:
93
Num
(
int
n
,
Gecode::FloatNum
min0,
Gecode::FloatNum
max0,
94
Gecode::FloatNum
st)
95
:
Test
(
"Dom::Num::"
+
str
(
n
)+
"::"
+
str
(min0)+
"::"
+
str
(max0),
96
n
,-3,3,st,
CPLT_ASSIGNMENT
,
n
==1),
min
(min0),
max
(max0) {
97
testsubsumed
=
false
;
98
}
100
virtual
MaybeType
solution
(
const
Assignment
&
x
)
const
{
101
if
(
max
<
min
)
102
return
MT_FALSE
;
103
for
(
int
i
=
x
.size();
i
--; )
104
if
((
x
[
i
].
max
() >
max
) || (
x
[
i
].min() <
min
))
105
return
MT_FALSE
;
106
return
MT_TRUE
;
107
}
109
virtual
void
post
(
Gecode::Space
& home,
Gecode::FloatVarArray
&
x
) {
110
if
(
x
.size() == 1)
111
Gecode::dom
(home,
x
[0],
min
,
max
);
112
else
113
Gecode::dom
(home,
x
,
min
,
max
);
114
}
116
virtual
void
post
(
Gecode::Space
& home,
Gecode::FloatVarArray
&
x
,
117
Gecode::Reify
r
) {
118
assert(
x
.size() == 1);
119
Gecode::dom
(home,
x
[0],
min
,
max
,
r
);
120
}
121
};
122
124
class
Create
{
125
public
:
127
Create
(
void
) {
128
using namespace
Gecode
;
129
FloatNum
step
= 0.7;
130
for
(
int
c
=-4;
c
<=4;
c
++) {
131
(void)
new
Val
(1,
c
,
step
);
132
(void)
new
Val
(2,
c
,
step
);
133
for
(
int
d
=-3;
d
<=3;
d
++) {
134
(void)
new
Num
(1,
c
,
d
,
step
);
135
(void)
new
Num
(2,
c
,
d
,
step
);
136
}
137
}
138
}
139
};
140
141
Create
c
;
143
144
}
145
146
}}
147
148
// STATISTICS: test-float
Test::Float::Dom::Num::min
Gecode::FloatNum min
Float number.
Definition:
dom.cpp:88
Test::r
Region r
Definition:
region.cpp:65
Test::Float::Arithmetic::step
const Gecode::FloatNum step
Definition:
arithmetic.cpp:785
Gecode::FloatVal::max
friend FloatVal max(const FloatVal &x, const FloatVal &y)
Definition:
val.hpp:386
minimodel.hh
Gecode::FloatVal::min
friend FloatVal min(const FloatVal &x, const FloatVal &y)
Definition:
val.hpp:398
Test::Float::MT_FALSE
Definition:
float.hh:52
Test::Float::Dom::Create
Help class to create and register tests.
Definition:
dom.cpp:124
Test::Float::Dom::Val
Test for domain constraints with a float value
Definition:
dom.cpp:51
Gecode::Float::Limits::min
const FloatNum min
Smallest allowed float value.
Definition:
float.hh:846
Gecode::Space
Computation spaces.
Definition:
core.hpp:1742
Test::Float::MT_TRUE
Definition:
float.hh:53
Test::Float::Dom::Val::Val
Val(int n, Gecode::FloatVal c0, Gecode::FloatNum st)
Create and register test.
Definition:
dom.cpp:57
Test::Float::Dom::Num::Num
Num(int n, Gecode::FloatNum min0, Gecode::FloatNum max0, Gecode::FloatNum st)
Create and register test.
Definition:
dom.cpp:93
Test::Float::Dom::Val::post
virtual void post(Gecode::Space &home, Gecode::FloatVarArray &x)
Post constraint on x.
Definition:
dom.cpp:70
Test::Float::Dom::Num::post
virtual void post(Gecode::Space &home, Gecode::FloatVarArray &x)
Post constraint on x.
Definition:
dom.cpp:109
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:116
Gecode
Gecode toplevel namespace
Test::Float::Dom::Val::solution
virtual MaybeType solution(const Assignment &x) const
Test whether x is solution
Definition:
dom.cpp:63
float.hh
x
Node * x
Pointer to corresponding Boolean expression node.
Definition:
bool-expr.cpp:249
Gecode::Reify
Reification specification.
Definition:
int.hh:876
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:77
Gecode::dom
void dom(Home home, FloatVar x, FloatVal n)
Propagates .
Definition:
dom.cpp:40
Gecode::FloatNum
double FloatNum
Floating point number base type.
Definition:
float.hh:106
Test::Float::CPLT_ASSIGNMENT
Definition:
float.hh:62
Test::Float::Dom::Create::Create
Create(void)
Perform creation and registration.
Definition:
dom.cpp:127
Test::Float::Dom::Num
Test for domain constraints with float numbers
Definition:
dom.cpp:85
Test::Float::Dom::Num::solution
virtual MaybeType solution(const Assignment &x) const
Test whether x is solution
Definition:
dom.cpp:100
Test::Float::Dom::c
Create c
Definition:
dom.cpp:141
Gecode::FloatVal
Float value type.
Definition:
float.hh:334
Test::Float::Test::str
static std::string str(Gecode::FloatRelType frt)
Map float relation to string.
Definition:
float.hpp:194
Test::Int::Dom::d
Gecode::IntSet d(r, 4)
Test::Float::Dom::Val::c
Gecode::FloatVal c
Float constant.
Definition:
dom.cpp:54
Test::Float::MaybeType
MaybeType
Type for comparisons and solutions.
Definition:
float.hh:51
Gecode::FloatVarArray
Float variable array.
Definition:
float.hh:1030
Test
General test support.
Definition:
afc.cpp:39
Test::Float::Assignment
Base class for assignments
Definition:
float.hh:80
Test::Float::Dom::Num::max
Gecode::FloatNum max
Float number.
Definition:
dom.cpp:90
n
int n
Number of negative literals for node type.
Definition:
bool-expr.cpp:234
Test::Int::Basic::i
Gecode::IntArgs i({1, 2, 3, 4})
Gecode::Float::Limits::max
const FloatNum max
Largest allowed float value.
Definition:
float.hh:844
Test::Float::Test::testsubsumed
bool testsubsumed
Whether to test for subsumption.
Definition:
float.hh:263