main page
modules
namespaces
classes
files
Gecode home
Generated on Tue Jan 28 2020 00:00:00 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
* Last modified:
16
* $Date: 2010-03-03 17:32:21 +0100 (Wed, 03 Mar 2010) $ by $Author: schulte $
17
* $Revision: 10364 $
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
namespace
Gecode
{
namespace
Set {
namespace
RelOp {
45
46
template
<
class
View0,
class
View1,
class
View2>
47
forceinline
48
SuperOfInter<View0,View1,View2>::SuperOfInter
49
(
Home
home, View0 y0, View1 y1, View2 y2)
50
:
MixTernaryPropagator
<View0,
PC_SET_ANY
,View1,
PC_SET_ANY
,
51
View2,
PC_SET_CLUB
>(home,y0,y1,y2) {}
52
53
template
<
class
View0,
class
View1,
class
View2>
54
forceinline
55
SuperOfInter<View0,View1,View2>::SuperOfInter
56
(
Space
& home,
bool
share,
SuperOfInter<View0,View1,View2>
&
p
)
57
:
MixTernaryPropagator
<View0,
PC_SET_ANY
,View1,
PC_SET_ANY
,
58
View2,
PC_SET_CLUB
>(home,share,
p
) {}
59
60
template
<
class
View0,
class
View1,
class
View2>
61
ExecStatus
62
SuperOfInter<View0,View1,View2>::post
(
Home
home,
63
View0 x0, View1 x1, View2 x2) {
64
(void)
new
(home)
SuperOfInter<View0,View1,View2>
(home, x0, x1, x2);
65
return
ES_OK
;
66
}
67
68
template
<
class
View0,
class
View1,
class
View2>
69
Actor
*
70
SuperOfInter<View0,View1,View2>::copy
(
Space
& home,
bool
share) {
71
return
new
(home)
SuperOfInter
(home,share,*
this
);
72
}
73
74
template
<
class
View0,
class
View1,
class
View2>
75
ExecStatus
76
SuperOfInter<View0,View1,View2>::propagate
(
Space
& home,
const
ModEventDelta
& med) {
77
78
bool
allassigned = x0.assigned() && x1.assigned() && x2.assigned();
79
80
ModEvent
me0 = View0::me(med);
81
ModEvent
me1 = View1::me(med);
82
ModEvent
me2 = View2::me(med);
83
84
bool
modified =
false
;
85
86
do
{
87
// glb(x2) >= glb(x0) ^ glb(x1)
88
if
( modified ||
Rel::testSetEventLB
(me0,me1)) {
89
GlbRanges<View0>
lb0(x0);
90
GlbRanges<View1>
lb1(x1);
91
Iter::Ranges::Inter<GlbRanges<View0>
,
GlbRanges<View1>
>
92
is(lb0, lb1);
93
94
GECODE_ME_CHECK_MODIFIED
(modified,x2.includeI(home,is));
95
}
96
97
// lub(x0) -= glb(x1)-lub(x2)
98
// lub(x1) -= glb(x0)-lub(x2)
99
if
( modified ||
Rel::testSetEventAnyB
(me0,me1,me2)) {
100
modified =
false
;
101
GlbRanges<View1>
lb12(x1);
102
LubRanges<View2>
ub22(x2);
103
Iter::Ranges::Diff<GlbRanges<View1>
,
LubRanges<View2>
>
104
diff1(lb12, ub22);
105
106
GECODE_ME_CHECK_MODIFIED
(modified, x0.excludeI(home,diff1));
107
108
GlbRanges<View0>
lb01(x0);
109
LubRanges<View2>
ub23(x2);
110
Iter::Ranges::Diff<GlbRanges<View0>
,
LubRanges<View2>
>
111
diff2(lb01, ub23);
112
113
GECODE_ME_CHECK_MODIFIED
(modified, x1.excludeI(home,diff2));
114
}
else
{
115
modified =
false
;
116
}
117
118
// Cardinality propagation
119
if
( modified ||
120
Rel::testSetEventCard
(me0,me1,me2) ||
121
Rel::testSetEventUB
(me0,me1)
122
) {
123
124
LubRanges<View0>
ub0(x0);
125
LubRanges<View1>
ub1(x1);
126
Iter::Ranges::Union<LubRanges<View0>
,
LubRanges<View1>
>
u
(ub0,ub1);
127
128
unsigned
int
m =
Iter::Ranges::size
(
u
);
129
130
if
(m < x0.cardMin() + x1.cardMin()) {
131
GECODE_ME_CHECK_MODIFIED
(modified,
132
x2.cardMin( home,
133
x0.cardMin()+x1.cardMin() - m ) );
134
}
135
if
(m + x2.cardMax() > x1.cardMin()) {
136
GECODE_ME_CHECK_MODIFIED
(modified,
137
x0.cardMax( home,
138
m+x2.cardMax()-x1.cardMin() ) );
139
}
140
if
(m + x2.cardMax() > x0.cardMin()) {
141
GECODE_ME_CHECK_MODIFIED
(modified,
142
x1.cardMax( home,
143
m+x2.cardMax()-x0.cardMin() ) );
144
}
145
}
146
}
while
(modified);
147
148
149
if
(
shared
(x0,x1,x2)) {
150
if
(allassigned) {
151
return
home.
ES_SUBSUMED
(*
this
);
152
}
else
{
153
return
ES_NOFIX
;
154
}
155
}
else
{
156
if
(x0.assigned() + x1.assigned() + x2.assigned() >= 2) {
157
return
home.
ES_SUBSUMED
(*
this
);
158
}
else
{
159
return
ES_FIX
;
160
}
161
}
162
163
}
164
165
}}}
166
167
// STATISTICS: set-prop
forceinline
#define forceinline
Definition:
config.hpp:173
GECODE_ME_CHECK_MODIFIED
#define GECODE_ME_CHECK_MODIFIED(modified, me)
Check whether me is failed or modified, and forward failure.
Definition:
macros.hpp:68
Gecode::Space::ES_SUBSUMED
ExecStatus ES_SUBSUMED(Propagator &p)
Definition:
core.hpp:3614
Gecode::Iter::Ranges::size
unsigned int size(I &i)
Size of all ranges of range iterator i.
Definition:
ranges-operations.hpp:78
Gecode::Set::RelOp::shared
bool shared(View0 v0, View1 v1, View2 v2)
Definition:
common.hpp:89
Gecode::Space
Computation spaces.
Definition:
core.hpp:1748
Gecode::Actor
Base-class for both propagators and branchers.
Definition:
core.hpp:696
Gecode::Set::RelOp::SuperOfInter::propagate
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
Definition:
superofinter.hpp:76
u
union Gecode::@579::NNF::@61 u
Union depending on nodetype t.
Gecode::MixTernaryPropagator
Mixed ternary propagator.
Definition:
propagator.hpp:247
Gecode::Set::Rel::testSetEventCard
bool testSetEventCard(ModEvent me0, ModEvent me1, ModEvent me2)
Definition:
common.hpp:87
Gecode
Gecode toplevel namespace
Gecode::Set::Rel::testSetEventUB
bool testSetEventUB(ModEvent me0, ModEvent me1, ModEvent me2)
Definition:
common.hpp:79
Gecode::Set::RelOp::SuperOfInter::copy
virtual Actor * copy(Space &home, bool)
Copy propagator during cloning.
Definition:
superofinter.hpp:70
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:922
Gecode::Iter::Ranges::Inter
Range iterator for computing intersection (binary)
Definition:
ranges-inter.hpp:48
Gecode::Iter::Ranges::Diff
Range iterator for computing set difference.
Definition:
ranges-diff.hpp:47
Gecode::Set::GlbRanges
Range iterator for the greatest lower bound.
Definition:
var-imp.hpp:363
Gecode::ModEvent
int ModEvent
Type for modification events.
Definition:
core.hpp:142
Gecode::Iter::Ranges::Union
Range iterator for computing union (binary)
Definition:
ranges-union.hpp:48
Gecode::Set::Rel::testSetEventAnyB
bool testSetEventAnyB(ModEvent me0, ModEvent me1, ModEvent me2)
Definition:
common.hpp:83
Gecode::ES_FIX
@ ES_FIX
Propagation has computed fixpoint.
Definition:
core.hpp:545
Gecode::Set::LubRanges
Range iterator for the least upper bound.
Definition:
var-imp.hpp:321
Gecode::Set::RelOp::SuperOfInter::post
static ExecStatus post(Home home, View0 x, View1 y, View2 z)
Post propagator .
Definition:
superofinter.hpp:62
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:65
Gecode::Set::Rel::testSetEventLB
bool testSetEventLB(ModEvent me0, ModEvent me1, ModEvent me2)
Definition:
common.hpp:75
Gecode::ModEventDelta
int ModEventDelta
Modification event deltas.
Definition:
core.hpp:169
Gecode::ES_NOFIX
@ ES_NOFIX
Propagation has not computed fixpoint.
Definition:
core.hpp:543
Gecode::ES_OK
@ ES_OK
Execution is okay.
Definition:
core.hpp:544
p
int p
Number of positive literals for node type.
Definition:
bool-expr.cpp:236
Gecode::Set::RelOp::SuperOfInter::SuperOfInter
SuperOfInter(Space &home, bool share, SuperOfInter &p)
Constructor for cloning p.
Definition:
superofinter.hpp:56
Gecode::ExecStatus
ExecStatus
Definition:
core.hpp:540