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
set
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
* Guido Tack <tack@gecode.org>
5
*
6
* Copyright:
7
* Guido Tack, 2005
8
*
9
* This file is part of Gecode, the generic constraint
10
* development environment:
11
* http://www.gecode.org
12
*
13
* Permission is hereby granted, free of charge, to any person obtaining
14
* a copy of this software and associated documentation files (the
15
* "Software"), to deal in the Software without restriction, including
16
* without limitation the rights to use, copy, modify, merge, publish,
17
* distribute, sublicense, and/or sell copies of the Software, and to
18
* permit persons to whom the Software is furnished to do so, subject to
19
* the following conditions:
20
*
21
* The above copyright notice and this permission notice shall be
22
* included in all copies or substantial portions of the Software.
23
*
24
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
28
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
29
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
30
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31
*
32
*/
33
34
#include "
test/set.hh
"
35
36
using namespace
Gecode
;
37
38
namespace
Test
{
namespace
Set {
39
41
namespace
Sequence
{
42
48
49
static
IntSet
ds_33(-1,2);
50
52
class
Sequence
:
public
SetTest
{
53
public
:
55
Sequence
(
const
char
*
t
)
56
:
SetTest
(
t
,4,ds_33,false) {}
58
virtual
bool
solution
(
const
SetAssignment
&
x
)
const
{
59
int
max
=
Gecode::Set::Limits::min
- 1;
60
for
(
int
i
=0;
i
<4;
i
++) {
61
CountableSetRanges
xir(
x
.lub,
x
[
i
]);
62
IntSet
xi(xir);
63
if
(xi.
ranges
() > 0) {
64
int
oldMax =
max
;
65
max
= xi.
max
();
66
if
(xi.
min
() <= oldMax)
67
return
false
;
68
}
69
}
70
return
true
;
71
}
73
virtual
void
post
(
Space
& home,
SetVarArray
&
x
,
IntVarArray
&) {
74
Gecode::sequence
(home,
x
);
75
}
76
};
77
Sequence
_sequence
(
"Sequence::Sequence"
);
78
80
class
SeqU
:
public
SetTest
{
81
private
:
82
int
n
;
83
public
:
85
SeqU
(
int
n0)
86
:
SetTest
(
"Sequence::SeqU"
+str(n0),n0+1,ds_33,false),
n
(n0) {}
88
virtual
bool
solution
(
const
SetAssignment
&
x
)
const
{
89
int
max
=
Gecode::Set::Limits::min
- 1;
90
for
(
int
i
=0;
i
<
n
;
i
++) {
91
CountableSetRanges
xir(
x
.lub,
x
[
i
]);
92
IntSet
xi(xir);
93
if
(xi.
ranges
() > 0) {
94
int
oldMax =
max
;
95
max
= xi.
max
();
96
if
(xi.
min
() <= oldMax)
97
return
false
;
98
}
99
}
100
CountableSetRanges
* isrs =
new
CountableSetRanges
[
n
];
101
for
(
int
i
=
n
;
i
--; )
102
isrs[
i
].init(
x
.lub,
x
[
i
]);
103
bool
ret;
104
{
105
Region
r
;
106
Iter::Ranges::NaryUnion
u
(
r
, isrs,
n
);
107
CountableSetRanges
xnr(
x
.lub,
x
[
n
]);
108
ret =
Iter::Ranges::equal
(
u
, xnr);
109
}
110
delete
[] isrs;
111
return
ret;
112
}
114
virtual
void
post
(
Space
& home,
SetVarArray
&
x
,
IntVarArray
&) {
115
SetVarArgs
xs(
x
.size()-1);
116
for
(
int
i
=
x
.size()-1;
i
--;)
117
xs[
i
]=
x
[
i
];
118
Gecode::sequence
(home, xs,
x
[
x
.size()-1]);
119
}
120
};
121
SeqU
_sequ0
(0);
122
SeqU
_sequ1
(1);
123
SeqU
_sequ3
(3);
124
125
}}}
126
127
// STATISTICS: test-set
Test::Set::Sequence::Sequence::post
virtual void post(Space &home, SetVarArray &x, IntVarArray &)
Post constraint on x.
Definition:
sequence.cpp:73
Test::Set::Sequence::_sequ0
SeqU _sequ0(0)
Test::Set::Sequence::SeqU::post
virtual void post(Space &home, SetVarArray &x, IntVarArray &)
Post constraint on x.
Definition:
sequence.cpp:114
Gecode::x
Post propagator for SetVar x
Definition:
set.hh:767
Gecode::IntSet::min
int min(int i) const
Return minimum of range at position i.
Definition:
int-set-1.hpp:152
Test::Set::Sequence::Sequence::solution
virtual bool solution(const SetAssignment &x) const
Test whether x is solution
Definition:
sequence.cpp:58
Test::Set::Sequence::SeqU::solution
virtual bool solution(const SetAssignment &x) const
Test whether x is solution
Definition:
sequence.cpp:88
Gecode::max
void max(Home home, FloatVar x0, FloatVar x1, FloatVar x2)
Post propagator for .
Definition:
arithmetic.cpp:49
Gecode::IntSet::max
int max(int i) const
Return maximum of range at position i.
Definition:
int-set-1.hpp:158
Gecode::Set::Limits::min
const int min
Smallest allowed integer in integer set.
Definition:
set.hh:99
Test::Set::Sequence::SeqU::SeqU
SeqU(int n0)
Create and register test.
Definition:
sequence.cpp:85
Gecode::SetVarArgs
Passing set variables.
Definition:
set.hh:488
Test::Set::Sequence::Sequence::Sequence
Sequence(const char *t)
Create and register test.
Definition:
sequence.cpp:55
t
NodeType t
Type of node.
Definition:
bool-expr.cpp:230
Gecode::Space
Computation spaces.
Definition:
core.hpp:1742
Gecode::IntVarArray
Integer variable array.
Definition:
int.hh:763
set.hh
Test::Set::SetAssignment
Generate all set assignments.
Definition:
set.hh:142
Test::Set::Sequence::_sequ3
SeqU _sequ3(3)
u
union Gecode::@602::NNF::@65 u
Union depending on nodetype t.
Gecode
Gecode toplevel namespace
Gecode::IntSet
Integer sets.
Definition:
int.hh:174
Gecode::r
Post propagator for SetVar SetOpType SetVar SetRelType r
Definition:
set.hh:767
Test::Set::SetTest
Base class for tests with set constraints
Definition:
set.hh:273
Gecode::Iter::Ranges::equal
bool equal(I &i, J &j)
Check whether range iterators i and j are equal.
Definition:
ranges-operations.hpp:84
Gecode::Iter::Ranges::NaryUnion
Range iterator for union of iterators.
Definition:
ranges-union.hpp:74
Test::Set::Sequence::_sequ1
SeqU _sequ1(1)
Test::Set::Sequence::Sequence
Test for sequence constraint
Definition:
sequence.cpp:52
Test::Region
Test for Region memory area
Definition:
region.cpp:42
Test::Set::Sequence::SeqU
Test for sequential-union constraint
Definition:
sequence.cpp:80
Test
General test support.
Definition:
afc.cpp:39
Test::Set::CountableSetRanges
Range iterator producing subsets of an IntSet.
Definition:
set.hh:98
Test::Set::Sequence::_sequence
Sequence _sequence("Sequence::Sequence")
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
Gecode::SetVarArray
Set variable array
Definition:
set.hh:570
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::IntSet::ranges
int ranges(void) const
Return number of ranges of the specification.
Definition:
int-set-1.hpp:171