main page
modules
namespaces
classes
files
Gecode home
Generated on Wed Jan 1 2020 10:37:59 for Gecode by
doxygen
1.8.16
test
int
sequence.cpp
Go to the documentation of this file.
1
/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2
/*
3
* Main authors:
4
* David Rijsman <David.Rijsman@quintiq.com>
5
*
6
* Contributing authors:
7
* Christian Schulte <schulte@gecode.org>
8
*
9
* Copyright:
10
* David Rijsman, 2009
11
* Christian Schulte, 2009
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
#include <
gecode/minimodel.hh
>
41
#include <climits>
42
43
namespace
Test
{
namespace
Int {
44
46
namespace
Sequence {
47
53
class
SequenceTest
:
public
Test
{
55
protected
:
56
Gecode::IntSet
s
;
57
int
q
,
l
,
u
;
58
public
:
60
SequenceTest
(
const
std::string&
s
,
61
const
Gecode::IntSet
& s0,
int
q0,
int
l0,
int
u0,
62
int
size
,
int
min
,
int
max
)
63
:
Test
(
"Sequence::"
+
s
,
size
,
min
,
max
),
s
(s0),
q
(q0),
l
(l0),
u
(u0) {
64
}
66
virtual
bool
solution
(
const
Assignment
&
x
)
const
{
67
for
(
int
i
=0;
i
< (
x
.size() -
q
+ 1);
i
++ ) {
68
int
total = 0;
69
for
(
int
j=
i
; j <
i
+
q
; j++ ) {
70
if
(
s
.
in
(
x
[j]))
71
total++;
72
if
(total >
u
)
73
return
false
;
74
}
75
if
( total <
l
)
76
return
false
;
77
}
78
return
true
;
79
}
80
};
81
82
84
class
SequenceBoolTest
:
public
SequenceTest
{
85
public
:
87
SequenceBoolTest
(
const
std::string&
s
,
const
Gecode::IntSet
& s0,
88
int
q0,
int
l0,
int
u0,
int
size
)
89
:
SequenceTest
(
"Bool::"
+
s
,s0,q0,l0,u0,
size
,0,1) {
90
}
91
93
virtual
void
post
(
Gecode::Space
& home,
Gecode::IntVarArray
&
x
) {
94
Gecode::BoolVarArgs
c
(
x
.size());
95
96
for
(
int
i
=0;
i
<
x
.size();
i
++) {
97
c
[
i
]=
Gecode::channel
(home,
x
[
i
]);
98
}
99
100
Gecode::sequence
(home,
c
,
s
,
q
,
l
,
u
);
101
}
102
};
103
105
class
SequenceIntTest
:
public
SequenceTest
{
106
public
:
108
SequenceIntTest
(
const
std::string&
s
,
const
Gecode::IntSet
& s0,
109
int
q0,
int
l0,
int
u0,
int
size
,
int
min
,
int
max
)
110
:
SequenceTest
(
"Int::"
+
s
,s0,q0,l0,u0,
size
,
min
,
max
) {
111
}
112
114
virtual
void
post
(
Gecode::Space
& home,
Gecode::IntVarArray
&
x
) {
115
Gecode::sequence
(home,
x
,
s
,
q
,
l
,
u
);
116
}
117
};
118
120
class
Create
{
121
public
:
122
124
Create
(
void
) {
125
using namespace
Gecode
;
126
127
IntSet
a
(0,0);
128
IntSet
b
(1,1);
129
IntSet
c
(2,2);
130
IntSet
d
(0,1);
131
IntArgs
ie({0,2});
132
IntSet
e(ie);
133
134
(void)
new
SequenceBoolTest
(
"A"
,
a
,3,2,2,6);
135
(void)
new
SequenceBoolTest
(
"B"
,
b
,3,2,2,6);
136
(void)
new
SequenceBoolTest
(
"C"
,
b
,6,2,2,6);
137
(void)
new
SequenceBoolTest
(
"D"
,
b
,6,0,0,6);
138
(void)
new
SequenceBoolTest
(
"E"
,
b
,6,6,6,6);
139
140
141
(void)
new
SequenceIntTest
(
"A"
,
c
,3,2,2,6,2,3);
142
(void)
new
SequenceIntTest
(
"B"
,
c
,3,2,2,6,2,4);
143
(void)
new
SequenceIntTest
(
"C"
,
b
,3,2,2,6,1,3);
144
(void)
new
SequenceIntTest
(
"D"
,
c
,3,0,0,3,1,3);
145
(void)
new
SequenceIntTest
(
"E"
,
c
,3,3,3,3,1,3);
146
(void)
new
SequenceIntTest
(
"F"
,
c
,3,2,2,10,2,3);
147
148
(void)
new
SequenceIntTest
(
"G"
,
d
,3,2,2,6,0,3);
149
(void)
new
SequenceIntTest
(
"H"
,
d
,3,2,2,6,0,4);
150
(void)
new
SequenceIntTest
(
"I"
,
d
,3,2,2,6,1,3);
151
(void)
new
SequenceIntTest
(
"J"
,e,3,0,0,6,0,3);
152
(void)
new
SequenceIntTest
(
"K"
,e,3,3,3,6,0,3);
153
(void)
new
SequenceIntTest
(
"L"
,e,3,2,2,6,0,3);
154
155
}
156
};
157
158
Create
c
;
160
161
}
162
}}
163
164
// STATISTICS: test-int
b
struct Gecode::@602::NNF::@65::@66 b
For binary nodes (and, or, eqv)
Gecode::IntSet::in
bool in(int n) const
Return whether n is included in the set.
Definition:
int-set-1.hpp:177
Test::Int::Sequence::SequenceTest::s
Gecode::IntSet s
Definition:
sequence.cpp:56
minimodel.hh
Gecode::Iter::Ranges::size
unsigned int size(I &i)
Size of all ranges of range iterator i.
Definition:
ranges-operations.hpp:74
Test::Int::Sequence::SequenceIntTest
Test for sequence with boolean variables
Definition:
sequence.cpp:105
Gecode::Float::Limits::min
const FloatNum min
Smallest allowed float value.
Definition:
float.hh:846
Test::Int::Sequence::SequenceTest::q
int q
Definition:
sequence.cpp:57
Gecode::Space
Computation spaces.
Definition:
core.hpp:1742
int.hh
Gecode::IntVarArray
Integer variable array.
Definition:
int.hh:763
Test::Int::Sequence::SequenceTest::SequenceTest
SequenceTest(const std::string &s, const Gecode::IntSet &s0, int q0, int l0, int u0, int size, int min, int max)
Create and register test.
Definition:
sequence.cpp:60
Test::Int::Sequence::c
Create c
Definition:
sequence.cpp:158
Gecode
Gecode toplevel namespace
Gecode::IntSet
Integer sets.
Definition:
int.hh:174
a
struct Gecode::@602::NNF::@65::@67 a
For atomic nodes.
x
Node * x
Pointer to corresponding Boolean expression node.
Definition:
bool-expr.cpp:249
Gecode::BoolVarArgs
Passing Boolean variables.
Definition:
int.hh:712
Test::Int::Sequence::Create
Help class to create and register tests.
Definition:
sequence.cpp:120
Test::Int::Sequence::Create::Create
Create(void)
Perform creation and registration.
Definition:
sequence.cpp:124
Test::Int::Sequence::SequenceTest::u
int u
Definition:
sequence.cpp:57
Test::Int::Sequence::SequenceTest::l
int l
Definition:
sequence.cpp:57
Test::Int::Sequence::SequenceIntTest::post
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
Definition:
sequence.cpp:114
Test::Int::Assignment
Base class for assignments
Definition:
int.hh:59
Test::Int::Sequence::SequenceBoolTest::SequenceBoolTest
SequenceBoolTest(const std::string &s, const Gecode::IntSet &s0, int q0, int l0, int u0, int size)
Create and register test.
Definition:
sequence.cpp:87
Test::Int::Distinct::d
Gecode::IntSet d(v, 7)
Gecode::channel
void channel(Home home, FloatVar x0, IntVar x1)
Post propagator for channeling a float and an integer variable .
Definition:
channel.cpp:41
Test::Int::Sequence::SequenceTest
Base test for sequence
Definition:
sequence.cpp:54
Test::Int::Sequence::SequenceBoolTest::post
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
Definition:
sequence.cpp:93
Test
General test support.
Definition:
afc.cpp:39
Gecode::sequence
void sequence(Home home, const IntVarArgs &x, const IntSet &s, int q, int l, int u, IntPropLevel)
Post propagator for .
Definition:
sequence.cpp:47
Test::Int::Sequence::SequenceIntTest::SequenceIntTest
SequenceIntTest(const std::string &s, const Gecode::IntSet &s0, int q0, int l0, int u0, int size, int min, int max)
Create and register test.
Definition:
sequence.cpp:108
Gecode::IntArgs
Passing integer arguments.
Definition:
int.hh:628
Test::Int::Basic::i
Gecode::IntArgs i({1, 2, 3, 4})
Test::Int::Sequence::SequenceBoolTest
Test for sequence with boolean variables
Definition:
sequence.cpp:84
Gecode::Float::Limits::max
const FloatNum max
Largest allowed float value.
Definition:
float.hh:844
Test::Int::Sequence::SequenceTest::solution
virtual bool solution(const Assignment &x) const
Test whether x is solutionin
Definition:
sequence.cpp:66