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
int
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
*
6
* Copyright:
7
* Christian Schulte, 2005
8
*
9
* Last modified:
10
* $Date: 2016-10-25 12:52:26 +0200 (Tue, 25 Oct 2016) $ by $Author: schulte $
11
* $Revision: 15233 $
12
*
13
* This file is part of Gecode, the generic constraint
14
* development environment:
15
* http://www.gecode.org
16
*
17
* Permission is hereby granted, free of charge, to any person obtaining
18
* a copy of this software and associated documentation files (the
19
* "Software"), to deal in the Software without restriction, including
20
* without limitation the rights to use, copy, modify, merge, publish,
21
* distribute, sublicense, and/or sell copies of the Software, and to
22
* permit persons to whom the Software is furnished to do so, subject to
23
* the following conditions:
24
*
25
* The above copyright notice and this permission notice shall be
26
* included in all copies or substantial portions of the Software.
27
*
28
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
29
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
30
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
31
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
32
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
33
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
34
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35
*
36
*/
37
38
#include "
test/int.hh
"
39
40
namespace
Test
{
namespace
Int {
41
43
namespace
Dom {
44
50
class
DomInt
:
public
Test
{
52
public
:
54
DomInt
(
int
n
)
55
:
Test
(
"Dom::Int::"
+
str
(
n
),
n
,-4,4,
n
== 1,
56
Gecode
::
IPL_DOM
) {}
58
virtual
bool
solution
(
const
Assignment
&
x
)
const
{
59
for
(
int
i
=
x
.size();
i
--; )
60
if
(
x
[
i
] != -2)
61
return
false
;
62
return
true
;
63
}
65
virtual
void
post
(
Gecode::Space
& home,
Gecode::IntVarArray
&
x
) {
66
if
(
x
.size() == 1)
67
Gecode::dom
(home,
x
[0], -2);
68
else
69
Gecode::dom
(home,
x
, -2);
70
}
72
virtual
void
post
(
Gecode::Space
& home,
Gecode::IntVarArray
&
x
,
73
Gecode::Reify
r
) {
74
assert(
x
.size() == 1);
75
Gecode::dom
(home,
x
[0], -2,
r
);
76
}
77
};
78
79
81
class
DomRange
:
public
Test
{
82
public
:
84
DomRange
(
int
n
)
85
:
Test
(
"Dom::Range::"
+
str
(
n
),
n
,-4,4,
n
== 1,
86
Gecode
::
IPL_DOM
) {}
88
virtual
bool
solution
(
const
Assignment
&
x
)
const
{
89
for
(
int
i
=
x
.size();
i
--; )
90
if
((
x
[
i
] < -2) || (
x
[
i
] > 2))
91
return
false
;
92
return
true
;
93
}
95
virtual
void
post
(
Gecode::Space
& home,
Gecode::IntVarArray
&
x
) {
96
if
(
x
.size() == 1)
97
Gecode::dom
(home,
x
[0], -2, 2);
98
else
99
Gecode::dom
(home,
x
, -2, 2);
100
}
102
virtual
void
post
(
Gecode::Space
& home,
Gecode::IntVarArray
&
x
,
103
Gecode::Reify
r
) {
104
assert(
x
.size() == 1);
105
Gecode::dom
(home,
x
[0], -2, 2,
r
);
106
}
107
};
108
110
class
DomRangeEmpty
:
public
Test
{
111
public
:
113
DomRangeEmpty
(
void
) :
Test
(
"Dom::Range::Empty"
,1,-4,4,true) {}
115
virtual
bool
solution
(
const
Assignment
&)
const
{
116
return
false
;
117
}
119
virtual
void
post
(
Gecode::Space
& home,
Gecode::IntVarArray
&) {
120
home.
fail
();
121
}
123
virtual
void
post
(
Gecode::Space
& home,
Gecode::IntVarArray
&
x
,
124
Gecode::Reify
r
) {
125
Gecode::dom
(home,
x
[0], 3, 2,
r
);
126
}
127
};
128
129
130
const
int
r
[4][2] = {
131
{-4,-3},{-1,-1},{1,1},{3,5}
132
};
133
Gecode::IntSet
d
(
r
,4);
134
136
class
DomDom
:
public
Test
{
137
public
:
139
DomDom
(
int
n
)
140
:
Test
(
"Dom::Dom::"
+
str
(
n
),
n
,-6,6,
n
== 1,
141
Gecode
::
IPL_DOM
) {}
143
virtual
bool
solution
(
const
Assignment
&
x
)
const
{
144
for
(
int
i
=
x
.size();
i
--; )
145
if
(!(((
x
[
i
] >= -4) && (
x
[
i
] <= -3)) ||
146
((
x
[
i
] >= -1) && (
x
[
i
] <= -1)) ||
147
((
x
[
i
] >= 1) && (
x
[
i
] <= 1)) ||
148
((
x
[
i
] >= 3) && (
x
[
i
] <= 5))))
149
return
false
;
150
return
true
;
151
}
153
virtual
void
post
(
Gecode::Space
& home,
Gecode::IntVarArray
&
x
) {
154
if
(
x
.size() == 1)
155
Gecode::dom
(home,
x
[0],
d
);
156
else
157
Gecode::dom
(home,
x
,
d
);
158
}
160
virtual
void
post
(
Gecode::Space
& home,
Gecode::IntVarArray
&
x
,
161
Gecode::Reify
r
) {
162
assert(
x
.size() == 1);
163
Gecode::dom
(home,
x
[0],
d
,
r
);
164
}
165
};
166
167
DomInt
di1
(1);
168
DomInt
di3
(3);
169
DomRange
dr1
(1);
170
DomRange
dr3
(3);
171
DomDom
dd1
(1);
172
DomDom
dd3
(3);
173
DomRangeEmpty
dre
;
175
176
}
177
}}
178
179
// STATISTICS: test-int
180
Test::Int::Dom::DomRange
Test for domain constraint (range)
Definition:
dom.cpp:81
Test::Int::Dom::di3
DomInt di3(3)
Test::Int::Dom::DomRange::DomRange
DomRange(int n)
Create and register test.
Definition:
dom.cpp:84
Test::Int::Dom::DomDom::post
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
Definition:
dom.cpp:153
Test::Int::Dom::DomDom::solution
virtual bool solution(const Assignment &x) const
Test whether x is solution
Definition:
dom.cpp:143
Test::Int::Basic::i
Gecode::IntArgs i(4, 1, 2, 3, 4)
Test::Int::Dom::DomInt::solution
virtual bool solution(const Assignment &x) const
Test whether x is solution
Definition:
dom.cpp:58
Test::Int::Dom::DomRange::solution
virtual bool solution(const Assignment &x) const
Test whether x is solution
Definition:
dom.cpp:88
Test::Int::Dom::dd1
DomDom dd1(1)
Gecode::Space
Computation spaces.
Definition:
core.hpp:1748
int.hh
Gecode::IntVarArray
Integer variable array.
Definition:
int.hh:744
Gecode
Gecode toplevel namespace
Test::Int::Dom::dr3
DomRange dr3(3)
Gecode::IntSet
Integer sets.
Definition:
int.hh:174
x
Node * x
Pointer to corresponding Boolean expression node.
Definition:
bool-expr.cpp:253
Test::Int::Dom::DomRangeEmpty::post
virtual void post(Gecode::Space &home, Gecode::IntVarArray &)
Post constraint on x.
Definition:
dom.cpp:119
Gecode::Reify
Reification specification.
Definition:
int.hh:857
Test::Int::Dom::dre
DomRangeEmpty dre
Definition:
dom.cpp:173
Test::Int::Dom::DomRangeEmpty::solution
virtual bool solution(const Assignment &) const
Test whether x is solution
Definition:
dom.cpp:115
Test::Int::Dom::r
const int r[4][2]
Definition:
dom.cpp:130
Gecode::dom
void dom(Home home, FloatVar x, FloatVal n)
Propagates .
Definition:
dom.cpp:44
Test::Int::Dom::dd3
DomDom dd3(3)
Gecode::IPL_DOM
@ IPL_DOM
Domain propagation Preferences: prefer speed or memory.
Definition:
int.hh:960
Test::Int::Dom::DomRangeEmpty::DomRangeEmpty
DomRangeEmpty(void)
Create and register test.
Definition:
dom.cpp:113
Test::Int::Dom::DomRangeEmpty::post
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x, Gecode::Reify r)
Post reified constraint on x for r.
Definition:
dom.cpp:123
Test::Int::Dom::di1
DomInt di1(1)
Test::Int::Dom::DomInt
Test for domain constraint (integer)
Definition:
dom.cpp:51
Test::Int::Dom::DomInt::post
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x, Gecode::Reify r)
Post reified constraint on x for r.
Definition:
dom.cpp:72
Test::Int::Assignment
Base class for assignments
Definition:
int.hh:63
Test::Int::Dom::DomDom
Test for domain constraint (full integer set)
Definition:
dom.cpp:136
Test::Int::Dom::DomInt::post
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
Definition:
dom.cpp:65
Gecode::Space::fail
void fail(void)
Fail space.
Definition:
core.hpp:4081
Test::Int::Dom::DomRange::post
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x, Gecode::Reify r)
Post reified constraint on x for r.
Definition:
dom.cpp:102
Test::Int::Dom::d
Gecode::IntSet d(r, 4)
Test::Int::Dom::DomDom::DomDom
DomDom(int n)
Create and register test.
Definition:
dom.cpp:139
Test::Int::Dom::DomRangeEmpty
Test for domain constraint (empty range)
Definition:
dom.cpp:110
Test::Int::Dom::DomInt::DomInt
DomInt(int n)
Create and register test.
Definition:
dom.cpp:54
Test::Int::Dom::DomDom::post
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x, Gecode::Reify r)
Post reified constraint on x for r.
Definition:
dom.cpp:160
Test
General test support.
Definition:
afc.cpp:43
n
int n
Number of negative literals for node type.
Definition:
bool-expr.cpp:238
Test::Int::Dom::dr1
DomRange dr1(1)
Test::Int::Dom::DomRange::post
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
Definition:
dom.cpp:95
Test::Int::Test::str
static std::string str(Gecode::IntPropLevel ipl)
Map integer propagation level to string.
Definition:
int.hpp:212