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
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
* Last modified:
10
* $Date: 2012-09-07 17:31:22 +0200 (Fri, 07 Sep 2012) $ by $Author: schulte $
11
* $Revision: 13068 $
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/set.hh
"
39
40
using namespace
Gecode
;
41
42
namespace
Test
{
namespace
Set {
43
45
namespace
Sequence
{
46
52
53
static
IntSet
ds_33(-1,2);
54
56
class
Sequence
:
public
SetTest
{
57
public
:
59
Sequence
(
const
char
*
t
)
60
:
SetTest
(
t
,4,ds_33,false) {}
62
virtual
bool
solution
(
const
SetAssignment
&
x
)
const
{
63
int
max
=
Gecode::Set::Limits::min
- 1;
64
for
(
int
i
=0;
i
<4;
i
++) {
65
CountableSetRanges
xir(
x
.lub,
x
[
i
]);
66
IntSet
xi(xir);
67
if
(xi.
ranges
() > 0) {
68
int
oldMax =
max
;
69
max
= xi.
max
();
70
if
(xi.
min
() <= oldMax)
71
return
false
;
72
}
73
}
74
return
true
;
75
}
77
virtual
void
post
(
Space
& home,
SetVarArray
&
x
,
IntVarArray
&) {
78
Gecode::sequence
(home,
x
);
79
}
80
};
81
Sequence
_sequence
(
"Sequence::Sequence"
);
82
84
class
SeqU
:
public
SetTest
{
85
private
:
86
int
n
;
87
public
:
89
SeqU
(
int
n0)
90
:
SetTest
(
"Sequence::SeqU"
+str(n0),n0+1,ds_33,false),
n
(n0) {}
92
virtual
bool
solution
(
const
SetAssignment
&
x
)
const
{
93
int
max
=
Gecode::Set::Limits::min
- 1;
94
for
(
int
i
=0;
i
<
n
;
i
++) {
95
CountableSetRanges
xir(
x
.lub,
x
[
i
]);
96
IntSet
xi(xir);
97
if
(xi.
ranges
() > 0) {
98
int
oldMax =
max
;
99
max
= xi.
max
();
100
if
(xi.
min
() <= oldMax)
101
return
false
;
102
}
103
}
104
CountableSetRanges
* isrs =
new
CountableSetRanges
[
n
];
105
for
(
int
i
=
n
;
i
--; )
106
isrs[
i
].init(
x
.lub,
x
[
i
]);
107
FakeSpace
* fs =
new
FakeSpace
;
108
bool
ret;
109
{
110
Region
r
(*fs);
111
Iter::Ranges::NaryUnion
u
(
r
, isrs,
n
);
112
CountableSetRanges
xnr(
x
.lub,
x
[
n
]);
113
ret =
Iter::Ranges::equal
(
u
, xnr);
114
}
115
delete
[] isrs;
116
delete
fs;
117
return
ret;
118
}
120
virtual
void
post
(
Space
& home,
SetVarArray
&
x
,
IntVarArray
&) {
121
SetVarArgs
xs(
x
.size()-1);
122
for
(
int
i
=
x
.size()-1;
i
--;)
123
xs[
i
]=
x
[
i
];
124
Gecode::sequence
(home, xs,
x
[
x
.size()-1]);
125
}
126
};
127
SeqU
_sequ0
(0);
128
SeqU
_sequ1
(1);
129
SeqU
_sequ3
(3);
130
131
}}}
132
133
// STATISTICS: test-set
Test::Set::Sequence::Sequence::post
virtual void post(Space &home, SetVarArray &x, IntVarArray &)
Post constraint on x.
Definition:
sequence.cpp:77
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:120
Gecode::x
Post propagator for SetVar x
Definition:
set.hh:784
Gecode::IntSet::min
int min(int i) const
Return minimum of range at position i.
Definition:
int-set-1.hpp:115
Test::Set::Sequence::Sequence::solution
virtual bool solution(const SetAssignment &x) const
Test whether x is solution
Definition:
sequence.cpp:62
Test::Set::Sequence::SeqU::solution
virtual bool solution(const SetAssignment &x) const
Test whether x is solution
Definition:
sequence.cpp:92
Gecode::max
void max(Home home, FloatVar x0, FloatVar x1, FloatVar x2)
Post propagator for .
Definition:
arithmetic.cpp:53
Gecode::IntSet::max
int max(int i) const
Return maximum of range at position i.
Definition:
int-set-1.hpp:121
Gecode::Set::Limits::min
const int min
Smallest allowed integer in integer set.
Definition:
set.hh:103
Test::Set::Sequence::SeqU::SeqU
SeqU(int n0)
Create and register test.
Definition:
sequence.cpp:89
Test::Int::Basic::i
Gecode::IntArgs i(4, 1, 2, 3, 4)
Gecode::SetVarArgs
Passing set variables.
Definition:
set.hh:492
Test::Set::Sequence::Sequence::Sequence
Sequence(const char *t)
Create and register test.
Definition:
sequence.cpp:59
t
NodeType t
Type of node.
Definition:
bool-expr.cpp:234
Gecode::Space
Computation spaces.
Definition:
core.hpp:1748
Gecode::IntVarArray
Integer variable array.
Definition:
int.hh:744
u
union Gecode::@579::NNF::@61 u
Union depending on nodetype t.
set.hh
Test::Set::SetAssignment
Generate all set assignments.
Definition:
set.hh:158
Test::Set::Sequence::_sequ3
SeqU _sequ3(3)
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:784
Test::Set::SetTest
Base class for tests with set constraints
Definition:
set.hh:289
Gecode::Iter::Ranges::equal
bool equal(I &i, J &j)
Check whether range iterators i and j are equal.
Definition:
ranges-operations.hpp:88
Gecode::Iter::Ranges::NaryUnion
Range iterator for union of iterators.
Definition:
ranges-union.hpp:78
Test::Set::Sequence::_sequ1
SeqU _sequ1(1)
Test::Set::Sequence::Sequence
Test for sequence constraint
Definition:
sequence.cpp:56
Test::Region
Test for Region memory area
Definition:
region.cpp:46
Test::Set::Sequence::SeqU
Test for sequential-union constraint
Definition:
sequence.cpp:84
Test
General test support.
Definition:
afc.cpp:43
Test::Set::CountableSetRanges
Range iterator producing subsets of an IntSet.
Definition:
set.hh:114
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:51
Test::Set::FakeSpace
Fake space for creation of regions.
Definition:
set.hh:58
Gecode::SetVarArray
Set variable array
Definition:
set.hh:572
n
int n
Number of negative literals for node type.
Definition:
bool-expr.cpp:238
Gecode::IntSet::ranges
int ranges(void) const
Return number of ranges of the specification.
Definition:
int-set-1.hpp:134