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
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
* Last modified:
14
* $Date: 2016-04-19 17:19:45 +0200 (Tue, 19 Apr 2016) $
15
* $Revision: 14967 $
16
*
17
* This file is part of Gecode, the generic constraint
18
* development environment:
19
* http://www.gecode.org
20
*
21
* Permission is hereby granted, free of charge, to any person obtaining
22
* a copy of this software and associated documentation files (the
23
* "Software"), to deal in the Software without restriction, including
24
* without limitation the rights to use, copy, modify, merge, publish,
25
* distribute, sublicense, and/or sell copies of the Software, and to
26
* permit persons to whom the Software is furnished to do so, subject to
27
* the following conditions:
28
*
29
* The above copyright notice and this permission notice shall be
30
* included in all copies or substantial portions of the Software.
31
*
32
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
33
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
34
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
35
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
36
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
37
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
38
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
39
*
40
*/
41
42
#include "
test/int.hh
"
43
44
#include <
gecode/minimodel.hh
>
45
#include <climits>
46
47
namespace
Test
{
namespace
Int {
48
50
namespace
Sequence {
51
57
class
SequenceTest
:
public
Test
{
59
protected
:
60
Gecode::IntSet
s
;
61
int
q
,
l
,
u
;
62
public
:
64
SequenceTest
(
const
std::string&
s
,
65
const
Gecode::IntSet
& s0,
int
q0,
int
l0,
int
u0,
66
int
size
,
int
min
,
int
max
)
67
:
Test
(
"Sequence::"
+
s
,
size
,
min
,
max
),
s
(s0),
q
(q0),
l
(l0),
u
(u0) {
68
}
70
virtual
bool
solution
(
const
Assignment
&
x
)
const
{
71
for
(
int
i
=0;
i
< (
x
.size() -
q
+ 1);
i
++ ) {
72
int
total = 0;
73
for
(
int
j=
i
; j <
i
+
q
; j++ ) {
74
if
(
s
.
in
(
x
[j]))
75
total++;
76
if
(total >
u
)
77
return
false
;
78
}
79
if
( total <
l
)
80
return
false
;
81
}
82
return
true
;
83
}
84
};
85
86
88
class
SequenceBoolTest
:
public
SequenceTest
{
89
public
:
91
SequenceBoolTest
(
const
std::string&
s
,
const
Gecode::IntSet
& s0,
92
int
q0,
int
l0,
int
u0,
int
size
)
93
:
SequenceTest
(
"Bool::"
+
s
,s0,q0,l0,u0,
size
,0,1) {
94
}
95
97
virtual
void
post
(
Gecode::Space
& home,
Gecode::IntVarArray
&
x
) {
98
Gecode::BoolVarArgs
c
(
x
.size());
99
100
for
(
int
i
=0;
i
<
x
.size();
i
++) {
101
c
[
i
]=
Gecode::channel
(home,
x
[
i
]);
102
}
103
104
Gecode::sequence
(home,
c
,
s
,
q
,
l
,
u
);
105
}
106
};
107
109
class
SequenceIntTest
:
public
SequenceTest
{
110
public
:
112
SequenceIntTest
(
const
std::string&
s
,
const
Gecode::IntSet
& s0,
113
int
q0,
int
l0,
int
u0,
int
size
,
int
min
,
int
max
)
114
:
SequenceTest
(
"Int::"
+
s
,s0,q0,l0,u0,
size
,
min
,
max
) {
115
}
116
118
virtual
void
post
(
Gecode::Space
& home,
Gecode::IntVarArray
&
x
) {
119
Gecode::sequence
(home,
x
,
s
,
q
,
l
,
u
);
120
}
121
};
122
124
class
Create
{
125
public
:
126
128
Create
(
void
) {
129
using namespace
Gecode
;
130
131
IntSet
a
(0,0);
132
IntSet
b
(1,1);
133
IntSet
c
(2,2);
134
IntSet
d
(0,1);
135
IntArgs
ie(2, 0,2);
136
IntSet
e(ie);
137
138
(void)
new
SequenceBoolTest
(
"A"
,
a
,3,2,2,6);
139
(void)
new
SequenceBoolTest
(
"B"
,
b
,3,2,2,6);
140
(void)
new
SequenceBoolTest
(
"C"
,
b
,6,2,2,6);
141
(void)
new
SequenceBoolTest
(
"D"
,
b
,6,0,0,6);
142
(void)
new
SequenceBoolTest
(
"E"
,
b
,6,6,6,6);
143
144
145
(void)
new
SequenceIntTest
(
"A"
,
c
,3,2,2,6,2,3);
146
(void)
new
SequenceIntTest
(
"B"
,
c
,3,2,2,6,2,4);
147
(void)
new
SequenceIntTest
(
"C"
,
b
,3,2,2,6,1,3);
148
(void)
new
SequenceIntTest
(
"D"
,
c
,3,0,0,3,1,3);
149
(void)
new
SequenceIntTest
(
"E"
,
c
,3,3,3,3,1,3);
150
(void)
new
SequenceIntTest
(
"F"
,
c
,3,2,2,10,2,3);
151
152
(void)
new
SequenceIntTest
(
"G"
,
d
,3,2,2,6,0,3);
153
(void)
new
SequenceIntTest
(
"H"
,
d
,3,2,2,6,0,4);
154
(void)
new
SequenceIntTest
(
"I"
,
d
,3,2,2,6,1,3);
155
(void)
new
SequenceIntTest
(
"J"
,e,3,0,0,6,0,3);
156
(void)
new
SequenceIntTest
(
"K"
,e,3,3,3,6,0,3);
157
(void)
new
SequenceIntTest
(
"L"
,e,3,2,2,6,0,3);
158
159
}
160
};
161
162
Create
c
;
164
165
}
166
}}
167
168
// STATISTICS: test-int
Gecode::IntSet::in
bool in(int n) const
Return whether n is included in the set.
Definition:
int-set-1.hpp:140
Test::Int::Sequence::SequenceTest::s
Gecode::IntSet s
Definition:
sequence.cpp:60
minimodel.hh
Gecode::Iter::Ranges::size
unsigned int size(I &i)
Size of all ranges of range iterator i.
Definition:
ranges-operations.hpp:78
Test::Int::Sequence::SequenceIntTest
Test for sequence with boolean variables
Definition:
sequence.cpp:109
Test::Int::Basic::i
Gecode::IntArgs i(4, 1, 2, 3, 4)
Gecode::Float::Limits::min
const FloatNum min
Smallest allowed float value.
Definition:
float.hh:850
Test::Int::Sequence::SequenceTest::q
int q
Definition:
sequence.cpp:61
Gecode::Space
Computation spaces.
Definition:
core.hpp:1748
int.hh
Gecode::IntVarArray
Integer variable array.
Definition:
int.hh:744
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:64
Test::Int::Sequence::c
Create c
Definition:
sequence.cpp:162
Gecode
Gecode toplevel namespace
Gecode::IntSet
Integer sets.
Definition:
int.hh:174
x
Node * x
Pointer to corresponding Boolean expression node.
Definition:
bool-expr.cpp:253
Gecode::BoolVarArgs
Passing Boolean variables.
Definition:
int.hh:693
a
struct Gecode::@579::NNF::@61::@63 a
For atomic nodes.
b
struct Gecode::@579::NNF::@61::@62 b
For binary nodes (and, or, eqv)
Test::Int::Sequence::Create
Help class to create and register tests.
Definition:
sequence.cpp:124
Test::Int::Sequence::Create::Create
Create(void)
Perform creation and registration.
Definition:
sequence.cpp:128
Test::Int::Sequence::SequenceTest::u
int u
Definition:
sequence.cpp:61
Test::Int::Sequence::SequenceTest::l
int l
Definition:
sequence.cpp:61
Test::Int::Sequence::SequenceIntTest::post
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
Definition:
sequence.cpp:118
Test::Int::Assignment
Base class for assignments
Definition:
int.hh:63
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:91
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:45
Test::Int::Sequence::SequenceTest
Base test for sequence
Definition:
sequence.cpp:58
Test::Int::Sequence::SequenceBoolTest::post
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
Definition:
sequence.cpp:97
Test
General test support.
Definition:
afc.cpp:43
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:51
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:112
Gecode::IntArgs
Passing integer arguments.
Definition:
int.hh:610
Test::Int::Sequence::SequenceBoolTest
Test for sequence with boolean variables
Definition:
sequence.cpp:88
Gecode::Float::Limits::max
const FloatNum max
Largest allowed float value.
Definition:
float.hh:848
Test::Int::Sequence::SequenceTest::solution
virtual bool solution(const Assignment &x) const
Test whether x is solutionin
Definition:
sequence.cpp:70