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
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
* Last modified:
16
* $Date: 2016-04-19 17:19:45 +0200 (Tue, 19 Apr 2016) $ by $Author: schulte $
17
* $Revision: 14967 $
18
*
19
* This file is part of Gecode, the generic constraint
20
* development environment:
21
* http://www.gecode.org
22
*
23
* Permission is hereby granted, free of charge, to any person obtaining
24
* a copy of this software and associated documentation files (the
25
* "Software"), to deal in the Software without restriction, including
26
* without limitation the rights to use, copy, modify, merge, publish,
27
* distribute, sublicense, and/or sell copies of the Software, and to
28
* permit persons to whom the Software is furnished to do so, subject to
29
* the following conditions:
30
*
31
* The above copyright notice and this permission notice shall be
32
* included in all copies or substantial portions of the Software.
33
*
34
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
35
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
36
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
37
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
38
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
39
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
40
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
41
*
42
*/
43
44
#include "
test/set.hh
"
45
46
using namespace
Gecode
;
47
48
namespace
Test
{
namespace
Set {
49
51
namespace
Precede {
52
53
static
IntSet
ds(-1,3);
54
56
class
Single
:
public
SetTest
{
57
private
:
59
int
s,
t
;
60
62
bool
in(
int
i
,
int
x
)
const
{
63
CountableSetRanges
xr(ds,
x
);
64
Iter::Ranges::Singleton
ir(
i
,
i
);
65
return
Iter::Ranges::subset
(ir,xr);
66
}
67
68
public
:
70
Single
(
int
s0,
int
t0)
71
:
SetTest
(
"Precede::Single::"
+str(s0)+
"<"
+str(t0),4,ds,false),
72
s(s0),
t
(t0) {}
74
virtual
bool
solution
(
const
SetAssignment
&
x
)
const
{
75
int
n
=
x
.size();
76
for
(
int
i
= 0 ;
i
<
n
;
i
++) {
77
if
(!in(s,
x
[
i
]) && in(
t
,
x
[
i
]))
78
return
false
;
79
if
(in(s,
x
[
i
]) && !in(
t
,
x
[
i
]))
80
return
true
;
81
}
82
return
true
;
83
}
85
virtual
void
post
(
Gecode::Space
& home,
Gecode::SetVarArray
&
x
,
86
Gecode::IntVarArray
&) {
87
Gecode::precede
(home,
x
, s,
t
);
88
}
89
};
90
92
class
Multi
:
public
SetTest
{
93
private
:
95
Gecode::IntArgs
c
;
96
98
bool
in(
int
i
,
int
x
)
const
{
99
CountableSetRanges
xr(ds,
x
);
100
Iter::Ranges::Singleton
ir(
i
,
i
);
101
return
Iter::Ranges::subset
(ir,xr);
102
}
103
public
:
105
Multi
(
const
Gecode::IntArgs
& c0)
106
:
SetTest
(
"Precede::Multi::"
+str(c0),4,ds,false),
c
(c0) {}
108
virtual
bool
solution
(
const
SetAssignment
&
x
)
const
{
109
for
(
int
j=0; j<
c
.
size
()-1; j++)
110
for
(
int
i
=0;
i
<
x
.size();
i
++) {
111
if
(!in(
c
[j],
x
[
i
]) && in(
c
[j+1],
x
[
i
]))
112
return
false
;
113
if
(in(
c
[j],
x
[
i
]) && !in(
c
[j+1],
x
[
i
]))
114
break
;
115
}
116
return
true
;
117
}
119
virtual
void
post
(
Gecode::Space
& home,
Gecode::SetVarArray
&
x
,
120
Gecode::IntVarArray
&) {
121
Gecode::precede
(home,
x
,
c
);
122
}
123
};
124
125
Single
_a
(2, 3);
126
Single
_b
(0, 3);
127
128
Multi
_c
(
Gecode::IntArgs
(3, 1,2,3));
129
Multi
_d
(
Gecode::IntArgs
(3, 3,2,1));
130
Multi
_e
(
Gecode::IntArgs
(4, 4,2,3,1));
131
132
}
133
134
}}
135
136
// STATISTICS: test-set
Gecode::x
Post propagator for SetVar x
Definition:
set.hh:784
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:119
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:70
Test::Int::Basic::i
Gecode::IntArgs i(4, 1, 2, 3, 4)
t
NodeType t
Type of node.
Definition:
bool-expr.cpp:234
Gecode::Space
Computation spaces.
Definition:
core.hpp:1748
Test::Set::Precede::_d
Multi _d(Gecode::IntArgs(3, 3, 2, 1))
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:101
Test::Set::Precede::Multi::solution
virtual bool solution(const SetAssignment &x) const
Test whether x is solution
Definition:
precede.cpp:108
Gecode::IntVarArray
Integer variable array.
Definition:
int.hh:744
Test::Set::Precede::Single
Test for single value precedence constraint
Definition:
precede.cpp:56
set.hh
Test::Set::SetAssignment
Generate all set assignments.
Definition:
set.hh:158
Test::Set::Precede::_c
Multi _c(Gecode::IntArgs(3, 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:92
Test::Set::SetTest
Base class for tests with set constraints
Definition:
set.hh:289
Test::Set::Precede::Single::solution
virtual bool solution(const SetAssignment &x) const
Test whether x is solution
Definition:
precede.cpp:74
Gecode::FloatVal::size
FloatNum size(void) const
Return size of float value (distance between maximum and minimum)
Definition:
val.hpp:82
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:47
Test::Set::Precede::Single::post
virtual void post(Gecode::Space &home, Gecode::SetVarArray &x, Gecode::IntVarArray &)
Post constraint on x.
Definition:
precede.cpp:85
Test
General test support.
Definition:
afc.cpp:43
Test::Set::CountableSetRanges
Range iterator producing subsets of an IntSet.
Definition:
set.hh:114
Gecode::Iter::Ranges::Singleton
Range iterator for singleton range.
Definition:
ranges-singleton.hpp:46
Test::Float::Arithmetic::c
Gecode::FloatVal c(-8, 8)
Gecode::SetVarArray
Set variable array
Definition:
set.hh:572
n
int n
Number of negative literals for node type.
Definition:
bool-expr.cpp:238
Test::Set::Precede::_e
Multi _e(Gecode::IntArgs(4, 4, 2, 3, 1))
Gecode::IntArgs
Passing integer arguments.
Definition:
int.hh:610
Test::Set::Precede::Multi::Multi
Multi(const Gecode::IntArgs &c0)
Create and register test.
Definition:
precede.cpp:105