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
re-eq.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
* Bugfixes provided by:
8
* Grégoire Dooms <dooms@info.ucl.ac.be>
9
*
10
* Copyright:
11
* Guido Tack, 2004
12
* Christian Schulte, 2004
13
*
14
* Last modified:
15
* $Date: 2016-06-29 17:28:17 +0200 (Wed, 29 Jun 2016) $ by $Author: schulte $
16
* $Revision: 15137 $
17
*
18
* This file is part of Gecode, the generic constraint
19
* development environment:
20
* http://www.gecode.org
21
*
22
* Permission is hereby granted, free of charge, to any person obtaining
23
* a copy of this software and associated documentation files (the
24
* "Software"), to deal in the Software without restriction, including
25
* without limitation the rights to use, copy, modify, merge, publish,
26
* distribute, sublicense, and/or sell copies of the Software, and to
27
* permit persons to whom the Software is furnished to do so, subject to
28
* the following conditions:
29
*
30
* The above copyright notice and this permission notice shall be
31
* included in all copies or substantial portions of the Software.
32
*
33
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
34
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
35
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
36
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
37
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
38
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
39
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
40
*
41
*/
42
43
namespace
Gecode
{
namespace
Set {
namespace
Rel {
44
45
template
<
class
View0,
class
View1,
class
CtrlView, ReifyMode rm>
46
forceinline
47
ReEq<View0,View1,CtrlView,rm>::ReEq
(
Home
home, View0 y0, View1 y1,
48
CtrlView y2)
49
:
Propagator
(home), x0(y0), x1(y1),
b
(y2) {
50
b
.subscribe(home,*
this
,
Gecode::Int::PC_INT_VAL
);
51
x0
.subscribe(home,*
this
,
PC_SET_ANY
);
52
x1
.subscribe(home,*
this
,
PC_SET_ANY
);
53
}
54
55
template
<
class
View0,
class
View1,
class
CtrlView, ReifyMode rm>
56
forceinline
57
ReEq<View0,View1,CtrlView,rm>::ReEq
(
Space
& home,
bool
share,
ReEq
&
p
)
58
:
Propagator
(home,share,
p
) {
59
x0
.update(home,share,
p
.x0);
60
x1
.update(home,share,
p
.x1);
61
b
.update(home,share,
p
.b);
62
}
63
64
template
<
class
View0,
class
View1,
class
CtrlView, ReifyMode rm>
65
PropCost
66
ReEq<View0,View1,CtrlView,rm>::cost
(
const
Space
&,
const
ModEventDelta
&)
const
{
67
return
PropCost::ternary
(
PropCost::LO
);
68
}
69
70
template
<
class
View0,
class
View1,
class
CtrlView, ReifyMode rm>
71
void
72
ReEq<View0,View1,CtrlView,rm>::reschedule
(
Space
& home) {
73
b
.reschedule(home,*
this
,
Gecode::Int::PC_INT_VAL
);
74
x0.reschedule(home,*
this
,
PC_SET_ANY
);
75
x1.reschedule(home,*
this
,
PC_SET_ANY
);
76
}
77
78
template
<
class
View0,
class
View1,
class
CtrlView, ReifyMode rm>
79
forceinline
size_t
80
ReEq<View0,View1,CtrlView,rm>::dispose
(
Space
& home) {
81
b
.cancel(home,*
this
,
Gecode::Int::PC_INT_VAL
);
82
x0.cancel(home,*
this
,
PC_SET_ANY
);
83
x1.cancel(home,*
this
,
PC_SET_ANY
);
84
(void)
Propagator::dispose
(home);
85
return
sizeof
(*this);
86
}
87
88
template
<
class
View0,
class
View1,
class
CtrlView, ReifyMode rm>
89
ExecStatus
90
ReEq<View0,View1,CtrlView,rm>::post
(
Home
home, View0 x0, View1 x1,
91
CtrlView
b
) {
92
(void)
new
(home)
ReEq<View0,View1,CtrlView,rm>
(home,x0,x1,
b
);
93
return
ES_OK
;
94
}
95
96
template
<
class
View0,
class
View1,
class
CtrlView, ReifyMode rm>
97
Actor
*
98
ReEq<View0,View1,CtrlView,rm>::copy
(
Space
& home,
bool
share) {
99
return
new
(home)
ReEq<View0,View1,CtrlView,rm>
(home,share,*
this
);
100
}
101
102
template
<
class
View0,
class
View1,
class
CtrlView, ReifyMode rm>
103
ExecStatus
104
ReEq<View0,View1,CtrlView,rm>::propagate
(
Space
& home,
105
const
ModEventDelta
&) {
106
if
(
b
.one()) {
107
if
(rm ==
RM_PMI
)
108
return
home.
ES_SUBSUMED
(*
this
);
109
GECODE_REWRITE
(*
this
,(
Eq<View0,View1>::post
(home(*
this
),x0,x1)));
110
}
111
if
(
b
.zero()) {
112
if
(rm ==
RM_IMP
)
113
return
home.
ES_SUBSUMED
(*
this
);
114
GECODE_REWRITE
(*
this
,(
Distinct<View0,View1>::post
(home(*
this
),x0,x1)));
115
}
116
117
if
(x0.assigned() && x1.assigned()) {
118
// directly test x0==x1
119
GlbRanges<View0>
x0lb(x0);
120
GlbRanges<View1>
x1lb(x1);
121
bool
x0eqx1 =
true
;
122
for
(; x0lb() && x1lb(); ++x0lb, ++x1lb) {
123
if
(x0lb.
min
() != x1lb.
min
() ||
124
x0lb.
max
() != x1lb.
max
()) {
125
x0eqx1 =
false
;
126
break
;
127
}
128
}
129
if
(x0eqx1 && !x0lb() && !x1lb()) {
130
if
(rm !=
RM_IMP
)
131
GECODE_ME_CHECK
(
b
.one_none(home));
132
return
home.
ES_SUBSUMED
(*
this
);
133
}
else
{
134
if
(rm !=
RM_PMI
)
135
GECODE_ME_CHECK
(
b
.zero_none(home));
136
return
home.
ES_SUBSUMED
(*
this
);
137
}
138
}
139
140
// check whether cardinalities still allow equality
141
if
(x0.cardMin() > x1.cardMax() ||
142
x1.cardMin() > x0.cardMax()) {
143
if
(rm !=
RM_PMI
)
144
GECODE_ME_CHECK
(
b
.zero_none(home));
145
return
home.
ES_SUBSUMED
(*
this
);
146
}
147
148
// check glb(x0) subset lub(x1)
149
GlbRanges<View0>
x0lb(x0);
150
LubRanges<View1>
x1ub(x1);
151
Iter::Ranges::Diff<GlbRanges<View0>
,
LubRanges<View1>
> diff1(x0lb, x1ub);
152
if
( diff1() ) {
153
if
(rm !=
RM_PMI
)
154
GECODE_ME_CHECK
(
b
.zero_none(home));
155
return
home.
ES_SUBSUMED
(*
this
);
156
}
157
158
// check glb(x1) subset lub(x0)
159
GlbRanges<View1>
x1lb(x1);
160
LubRanges<View0>
x0ub(x0);
161
Iter::Ranges::Diff<GlbRanges<View1>
,
LubRanges<View0>
> diff2(x1lb, x0ub);
162
if
( diff2() ) {
163
if
(rm !=
RM_PMI
)
164
GECODE_ME_CHECK
(
b
.zero_none(home));
165
return
home.
ES_SUBSUMED
(*
this
);
166
}
167
168
return
ES_FIX
;
169
}
170
171
}}}
172
173
// STATISTICS: set-prop
forceinline
#define forceinline
Definition:
config.hpp:173
Gecode::RM_PMI
@ RM_PMI
Inverse implication for reification.
Definition:
int.hh:850
Gecode::Space::ES_SUBSUMED
ExecStatus ES_SUBSUMED(Propagator &p)
Definition:
core.hpp:3614
Gecode::Set::Rel::ReEq::propagate
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
Definition:
re-eq.hpp:104
Gecode::Set::Rel::ReEq::x1
View1 x1
Definition:
rel.hh:177
Gecode::Set::Rel::ReEq::dispose
virtual size_t dispose(Space &home)
Delete propagator and return its size.
Definition:
re-eq.hpp:80
Gecode::RM_IMP
@ RM_IMP
Implication for reification.
Definition:
int.hh:843
Gecode::PropCost::LO
@ LO
Cheap.
Definition:
core.hpp:581
Gecode::Set::Rel::Eq
Propagator for set equality
Definition:
rel.hh:150
Gecode::Set::Rel::ReEq::b
CtrlView b
Definition:
rel.hh:178
Gecode::Space
Computation spaces.
Definition:
core.hpp:1748
Gecode::Actor
Base-class for both propagators and branchers.
Definition:
core.hpp:696
Gecode
Gecode toplevel namespace
Gecode::Propagator
Base-class for propagators.
Definition:
core.hpp:1092
Gecode::Set::GlbRanges::max
int max(void) const
Return largest value of range.
Gecode::Set::Rel::ReEq::ReEq
ReEq(Space &home, bool share, ReEq &)
Constructor for cloning p.
Definition:
re-eq.hpp:57
Gecode::Home
Home class for posting propagators
Definition:
core.hpp:922
Gecode::Set::Rel::ReEq::reschedule
virtual void reschedule(Space &home)
Schedule function.
Definition:
re-eq.hpp:72
b
struct Gecode::@579::NNF::@61::@62 b
For binary nodes (and, or, eqv)
Gecode::Iter::Ranges::Diff
Range iterator for computing set difference.
Definition:
ranges-diff.hpp:47
Gecode::Set::Rel::ReEq
Reified equality propagator
Definition:
rel.hh:174
Gecode::Set::GlbRanges
Range iterator for the greatest lower bound.
Definition:
var-imp.hpp:363
Gecode::Set::GlbRanges::min
int min(void) const
Return smallest value of range.
Gecode::PropCost::ternary
static PropCost ternary(PropCost::Mod m)
Three variables for modifier pcm.
Definition:
core.hpp:4850
Gecode::Set::Rel::ReEq::x0
View0 x0
Definition:
rel.hh:176
Gecode::PropCost
Propagation cost.
Definition:
core.hpp:554
Gecode::Set::Rel::Distinct
Propagator for negated equality
Definition:
rel.hh:267
Gecode::Set::Rel::ReEq::post
static ExecStatus post(Home home, View0 x, View1 y, CtrlView b)
Post propagator for .
Definition:
re-eq.hpp:90
Gecode::Int::PC_INT_VAL
const Gecode::PropCond PC_INT_VAL
Propagate when a view becomes assigned (single value)
Definition:
var-type.hpp:82
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::Rel::ReEq::copy
virtual Actor * copy(Space &home, bool)
Copy propagator during cloning.
Definition:
re-eq.hpp:98
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_ME_CHECK
#define GECODE_ME_CHECK(me)
Check whether modification event me is failed, and forward failure.
Definition:
macros.hpp:56
Gecode::Actor::dispose
virtual size_t dispose(Space &home)
Delete actor and return its size.
Definition:
core.hpp:3354
Gecode::Set::Rel::ReEq::cost
virtual PropCost cost(const Space &home, const ModEventDelta &med) const
Cost function (defined as PC_TERNARY_LO)
Definition:
re-eq.hpp:66
Gecode::ModEventDelta
int ModEventDelta
Modification event deltas.
Definition:
core.hpp:169
GECODE_REWRITE
#define GECODE_REWRITE(prop, post)
Rewrite propagator by executing post function.
Definition:
macros.hpp:120
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::ExecStatus
ExecStatus
Definition:
core.hpp:540