main page
modules
namespaces
classes
files
Gecode home
Generated on Tue Mar 24 2020 14:04:04 for Gecode by
doxygen
1.8.17
gecode
set
rel-op
superofinter.hpp
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
* Christian Schulte <schulte@gecode.org>
6
*
7
* Contributing authors:
8
* Gabor Szokoli <szokoli@gecode.org>
9
*
10
* Copyright:
11
* Guido Tack, 2004
12
* Christian Schulte, 2004
13
* Gabor Szokoli, 2004
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
namespace
Gecode
{
namespace
Set {
namespace
RelOp {
41
42
template
<
class
View0,
class
View1,
class
View2>
43
forceinline
44
SuperOfInter<View0,View1,View2>::SuperOfInter
45
(
Home
home, View0 y0, View1 y1, View2 y2)
46
:
MixTernaryPropagator
<View0,
PC_SET_ANY
,View1,
PC_SET_ANY
,
47
View2,
PC_SET_CLUB
>(home,y0,y1,y2) {}
48
49
template
<
class
View0,
class
View1,
class
View2>
50
forceinline
51
SuperOfInter<View0,View1,View2>::SuperOfInter
52
(
Space
& home,
SuperOfInter<View0,View1,View2>
&
p
)
53
:
MixTernaryPropagator
<View0,
PC_SET_ANY
,View1,
PC_SET_ANY
,
54
View2,
PC_SET_CLUB
>(home,
p
) {}
55
56
template
<
class
View0,
class
View1,
class
View2>
57
ExecStatus
58
SuperOfInter<View0,View1,View2>::post
(
Home
home,
59
View0 x0, View1 x1, View2 x2) {
60
(void)
new
(home)
SuperOfInter<View0,View1,View2>
(home, x0, x1, x2);
61
return
ES_OK
;
62
}
63
64
template
<
class
View0,
class
View1,
class
View2>
65
Actor
*
66
SuperOfInter<View0,View1,View2>::copy
(
Space
& home) {
67
return
new
(home)
SuperOfInter
(home,*
this
);
68
}
69
70
template
<
class
View0,
class
View1,
class
View2>
71
ExecStatus
72
SuperOfInter<View0,View1,View2>::propagate
(
Space
& home,
const
ModEventDelta
& med) {
73
74
bool
allassigned = x0.assigned() && x1.assigned() && x2.assigned();
75
76
ModEvent
me0 = View0::me(med);
77
ModEvent
me1 = View1::me(med);
78
ModEvent
me2 = View2::me(med);
79
80
bool
modified =
false
;
81
82
do
{
83
// glb(x2) >= glb(x0) ^ glb(x1)
84
if
( modified ||
Rel::testSetEventLB
(me0,me1)) {
85
GlbRanges<View0>
lb0(x0);
86
GlbRanges<View1>
lb1(x1);
87
Iter::Ranges::Inter<GlbRanges<View0>
,
GlbRanges<View1>
>
88
is(lb0, lb1);
89
90
GECODE_ME_CHECK_MODIFIED
(modified,x2.includeI(home,is));
91
}
92
93
// lub(x0) -= glb(x1)-lub(x2)
94
// lub(x1) -= glb(x0)-lub(x2)
95
if
( modified ||
Rel::testSetEventAnyB
(me0,me1,me2)) {
96
modified =
false
;
97
GlbRanges<View1>
lb12(x1);
98
LubRanges<View2>
ub22(x2);
99
Iter::Ranges::Diff<GlbRanges<View1>
,
LubRanges<View2>
>
100
diff1(lb12, ub22);
101
102
GECODE_ME_CHECK_MODIFIED
(modified, x0.excludeI(home,diff1));
103
104
GlbRanges<View0>
lb01(x0);
105
LubRanges<View2>
ub23(x2);
106
Iter::Ranges::Diff<GlbRanges<View0>
,
LubRanges<View2>
>
107
diff2(lb01, ub23);
108
109
GECODE_ME_CHECK_MODIFIED
(modified, x1.excludeI(home,diff2));
110
}
else
{
111
modified =
false
;
112
}
113
114
// Cardinality propagation
115
if
( modified ||
116
Rel::testSetEventCard
(me0,me1,me2) ||
117
Rel::testSetEventUB
(me0,me1)
118
) {
119
120
LubRanges<View0>
ub0(x0);
121
LubRanges<View1>
ub1(x1);
122
Iter::Ranges::Union<LubRanges<View0>
,
LubRanges<View1>
>
u
(ub0,ub1);
123
124
unsigned
int
m =
Iter::Ranges::size
(
u
);
125
126
if
(m < x0.cardMin() + x1.cardMin()) {
127
GECODE_ME_CHECK_MODIFIED
(modified,
128
x2.cardMin( home,
129
x0.cardMin()+x1.cardMin() - m ) );
130
}
131
if
(m + x2.cardMax() > x1.cardMin()) {
132
GECODE_ME_CHECK_MODIFIED
(modified,
133
x0.cardMax( home,
134
m+x2.cardMax()-x1.cardMin() ) );
135
}
136
if
(m + x2.cardMax() > x0.cardMin()) {
137
GECODE_ME_CHECK_MODIFIED
(modified,
138
x1.cardMax( home,
139
m+x2.cardMax()-x0.cardMin() ) );
140
}
141
}
142
}
while
(modified);
143
144
145
if
(
shared
(x0,x1,x2)) {
146
if
(allassigned) {
147
return
home.
ES_SUBSUMED
(*
this
);
148
}
else
{
149
return
ES_NOFIX
;
150
}
151
}
else
{
152
if
(x0.assigned() + x1.assigned() + x2.assigned() >= 2) {
153
return
home.
ES_SUBSUMED
(*
this
);
154
}
else
{
155
return
ES_FIX
;
156
}
157
}
158
159
}
160
161
}}}
162
163
// STATISTICS: set-prop
GECODE_ME_CHECK_MODIFIED
#define GECODE_ME_CHECK_MODIFIED(modified, me)
Check whether me is failed or modified, and forward failure.
Definition:
macros.hpp:64
Gecode::Space::ES_SUBSUMED
ExecStatus ES_SUBSUMED(Propagator &p)
Definition:
core.hpp:3563
Gecode::Iter::Ranges::size
unsigned int size(I &i)
Size of all ranges of range iterator i.
Definition:
ranges-operations.hpp:74
Gecode::Set::RelOp::shared
bool shared(View0 v0, View1 v1, View2 v2)
Definition:
common.hpp:84
Gecode::Space
Computation spaces.
Definition:
core.hpp:1742
Gecode::Actor
Base-class for both propagators and branchers.
Definition:
core.hpp:628
Gecode::Set::RelOp::SuperOfInter::propagate
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
Definition:
superofinter.hpp:72
Gecode::MixTernaryPropagator
Mixed ternary propagator.
Definition:
pattern.hpp:237
Gecode::Set::Rel::testSetEventCard
bool testSetEventCard(ModEvent me0, ModEvent me1, ModEvent me2)
Definition:
common.hpp:95
Gecode
Gecode toplevel namespace
u
union Gecode::@602::NNF::@65 u
Union depending on nodetype t.
Gecode::Set::Rel::testSetEventUB
bool testSetEventUB(ModEvent me0, ModEvent me1, ModEvent me2)
Definition:
common.hpp:87
Gecode::Set::PC_SET_CLUB
const Gecode::PropCond PC_SET_CLUB
Propagate when the cardinality or the least upper bound of a view changes.
Definition:
var-type.hpp:227
Gecode::Home
Home class for posting propagators
Definition:
core.hpp:856
Gecode::Iter::Ranges::Inter
Range iterator for computing intersection (binary)
Definition:
ranges-inter.hpp:44
Gecode::Iter::Ranges::Diff
Range iterator for computing set difference.
Definition:
ranges-diff.hpp:43
Gecode::Set::RelOp::SuperOfInter::copy
virtual Actor * copy(Space &home)
Copy propagator during cloning.
Definition:
superofinter.hpp:66
Gecode::Set::GlbRanges
Range iterator for the greatest lower bound.
Definition:
var-imp.hpp:359
Gecode::ModEvent
int ModEvent
Type for modification events.
Definition:
core.hpp:62
Gecode::Iter::Ranges::Union
Range iterator for computing union (binary)
Definition:
ranges-union.hpp:44
Gecode::Set::Rel::testSetEventAnyB
bool testSetEventAnyB(ModEvent me0, ModEvent me1, ModEvent me2)
Definition:
common.hpp:91
Gecode::ES_FIX
@ ES_FIX
Propagation has computed fixpoint.
Definition:
core.hpp:477
Gecode::Set::LubRanges
Range iterator for the least upper bound.
Definition:
var-imp.hpp:317
Gecode::Set::RelOp::SuperOfInter::post
static ExecStatus post(Home home, View0 x, View1 y, View2 z)
Post propagator .
Definition:
superofinter.hpp:58
forceinline
#define forceinline
Definition:
config.hpp:185
Gecode::Set::PC_SET_ANY
const Gecode::PropCond PC_SET_ANY
Propagate when any bound or the cardinality of a view changes.
Definition:
var-type.hpp:248
Gecode::Set::RelOp::SuperOfInter
Propagator for the superset of intersection
Definition:
rel-op.hh:61
Gecode::Set::RelOp::SuperOfInter::SuperOfInter
SuperOfInter(Space &home, SuperOfInter &p)
Constructor for cloning p.
Definition:
superofinter.hpp:52
Gecode::Set::Rel::testSetEventLB
bool testSetEventLB(ModEvent me0, ModEvent me1, ModEvent me2)
Definition:
common.hpp:83
Gecode::ModEventDelta
int ModEventDelta
Modification event deltas.
Definition:
core.hpp:89
Gecode::ES_NOFIX
@ ES_NOFIX
Propagation has not computed fixpoint.
Definition:
core.hpp:475
Gecode::ES_OK
@ ES_OK
Execution is okay.
Definition:
core.hpp:476
p
int p
Number of positive literals for node type.
Definition:
bool-expr.cpp:232
Gecode::ExecStatus
ExecStatus
Definition:
core.hpp:472