main page
modules
namespaces
classes
files
Gecode home
Generated on Mon Feb 8 2021 00:00:00 for Gecode by
doxygen
1.8.20
test
set
precede.cpp
Go to the documentation of this file.
1
/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2
/*
3
* Main authors:
4
* Christopher Mears <Chris.Mears@monash.edu>
5
*
6
* Contributing authors:
7
* Christian Schulte <schulte@gecode.org>
8
* Guido Tack <tack@gecode.org>
9
*
10
* Copyright:
11
* Christopher Mears, 2011
12
* Christian Schulte, 2011
13
* Guido Tack, 2011
14
*
15
* This file is part of Gecode, the generic constraint
16
* development environment:
17
* http://www.gecode.org
18
*
19
* Permission is hereby granted, free of charge, to any person obtaining
20
* a copy of this software and associated documentation files (the
21
* "Software"), to deal in the Software without restriction, including
22
* without limitation the rights to use, copy, modify, merge, publish,
23
* distribute, sublicense, and/or sell copies of the Software, and to
24
* permit persons to whom the Software is furnished to do so, subject to
25
* the following conditions:
26
*
27
* The above copyright notice and this permission notice shall be
28
* included in all copies or substantial portions of the Software.
29
*
30
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
31
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
32
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
33
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
34
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
35
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
36
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
37
*
38
*/
39
40
#include "
test/set.hh
"
41
42
using namespace
Gecode
;
43
44
namespace
Test
{
namespace
Set {
45
47
namespace
Precede {
48
49
static
IntSet
ds(-1,3);
50
52
class
Single
:
public
SetTest
{
53
private
:
55
int
s,
t
;
56
58
bool
in(
int
i
,
int
x
)
const
{
59
CountableSetRanges
xr(ds,
x
);
60
Iter::Ranges::Singleton
ir(
i
,
i
);
61
return
Iter::Ranges::subset
(ir,xr);
62
}
63
64
public
:
66
Single
(
int
s0,
int
t0)
67
:
SetTest
(
"Precede::Single::"
+str(s0)+
"<"
+str(t0),4,ds,false),
68
s(s0),
t
(t0) {}
70
virtual
bool
solution
(
const
SetAssignment
&
x
)
const
{
71
int
n
=
x
.size();
72
for
(
int
i
= 0 ;
i
<
n
;
i
++) {
73
if
(!in(s,
x
[
i
]) && in(
t
,
x
[
i
]))
74
return
false
;
75
if
(in(s,
x
[
i
]) && !in(
t
,
x
[
i
]))
76
return
true
;
77
}
78
return
true
;
79
}
81
virtual
void
post
(
Gecode::Space
& home,
Gecode::SetVarArray
&
x
,
82
Gecode::IntVarArray
&) {
83
Gecode::precede
(home,
x
, s,
t
);
84
}
85
};
86
88
class
Multi
:
public
SetTest
{
89
private
:
91
Gecode::IntArgs
c
;
92
94
bool
in(
int
i
,
int
x
)
const
{
95
CountableSetRanges
xr(ds,
x
);
96
Iter::Ranges::Singleton
ir(
i
,
i
);
97
return
Iter::Ranges::subset
(ir,xr);
98
}
99
public
:
101
Multi
(
const
Gecode::IntArgs
& c0)
102
:
SetTest
(
"Precede::Multi::"
+str(c0),4,ds,false),
c
(c0) {}
104
virtual
bool
solution
(
const
SetAssignment
&
x
)
const
{
105
for
(
int
j=0; j<
c
.
size
()-1; j++)
106
for
(
int
i
=0;
i
<
x
.size();
i
++) {
107
if
(!in(
c
[j],
x
[
i
]) && in(
c
[j+1],
x
[
i
]))
108
return
false
;
109
if
(in(
c
[j],
x
[
i
]) && !in(
c
[j+1],
x
[
i
]))
110
break
;
111
}
112
return
true
;
113
}
115
virtual
void
post
(
Gecode::Space
& home,
Gecode::SetVarArray
&
x
,
116
Gecode::IntVarArray
&) {
117
Gecode::precede
(home,
x
,
c
);
118
}
119
};
120
121
Single
_a
(2, 3);
122
Single
_b
(0, 3);
123
124
Multi
_c
(
Gecode::IntArgs
({1,2,3}));
125
Multi
_d
(
Gecode::IntArgs
({3,2,1}));
126
Multi
_e
(
Gecode::IntArgs
({4,2,3,1}));
127
128
}
129
130
}}
131
132
// STATISTICS: test-set
Gecode::x
Post propagator for SetVar x
Definition:
set.hh:767
Test::Set::Precede::_a
Single _a(2, 3)
Test::Set::Precede::Multi::post
virtual void post(Gecode::Space &home, Gecode::SetVarArray &x, Gecode::IntVarArray &)
Post constraint on x.
Definition:
precede.cpp:115
Test::Set::Precede::_b
Single _b(0, 3)
Test::Set::Precede::Single::Single
Single(int s0, int t0)
Create and register test.
Definition:
precede.cpp:66
t
NodeType t
Type of node.
Definition:
bool-expr.cpp:230
Gecode::Space
Computation spaces.
Definition:
core.hpp:1742
Gecode::Iter::Ranges::subset
bool subset(I &i, J &j)
Check whether range iterator i is subset of range iterator j.
Definition:
ranges-operations.hpp:97
Test::Set::Precede::Multi::solution
virtual bool solution(const SetAssignment &x) const
Test whether x is solution
Definition:
precede.cpp:104
Gecode::IntVarArray
Integer variable array.
Definition:
int.hh:763
Test::Set::Precede::Single
Test for single value precedence constraint
Definition:
precede.cpp:52
set.hh
Test::Set::SetAssignment
Generate all set assignments.
Definition:
set.hh:142
Test::Set::Precede::_c
Multi _c(Gecode::IntArgs({1, 2, 3}))
Gecode
Gecode toplevel namespace
Gecode::IntSet
Integer sets.
Definition:
int.hh:174
Test::Set::Precede::Multi
Test for multiple value precedence constraint
Definition:
precede.cpp:88
Test::Set::Precede::_e
Multi _e(Gecode::IntArgs({4, 2, 3, 1}))
Test::Set::SetTest
Base class for tests with set constraints
Definition:
set.hh:273
Test::Set::Precede::Single::solution
virtual bool solution(const SetAssignment &x) const
Test whether x is solution
Definition:
precede.cpp:70
Gecode::FloatVal::size
FloatNum size(void) const
Return size of float value (distance between maximum and minimum)
Definition:
val.hpp:78
Gecode::precede
void precede(Home home, const IntVarArgs &x, int s, int t, IntPropLevel)
Post propagator that s precedes t in x.
Definition:
precede.cpp:43
Test::Set::Precede::_d
Multi _d(Gecode::IntArgs({3, 2, 1}))
Test::Set::Precede::Single::post
virtual void post(Gecode::Space &home, Gecode::SetVarArray &x, Gecode::IntVarArray &)
Post constraint on x.
Definition:
precede.cpp:81
Test
General test support.
Definition:
afc.cpp:39
Test::Set::CountableSetRanges
Range iterator producing subsets of an IntSet.
Definition:
set.hh:99
Gecode::Iter::Ranges::Singleton
Range iterator for singleton range.
Definition:
ranges-singleton.hpp:42
Test::Float::Arithmetic::c
Gecode::FloatVal c(-8, 8)
Gecode::SetVarArray
Set variable array
Definition:
set.hh:570
n
int n
Number of negative literals for node type.
Definition:
bool-expr.cpp:234
Gecode::IntArgs
Passing integer arguments.
Definition:
int.hh:628
Test::Int::Basic::i
Gecode::IntArgs i({1, 2, 3, 4})
Test::Set::Precede::Multi::Multi
Multi(const Gecode::IntArgs &c0)
Create and register test.
Definition:
precede.cpp:101