main page
modules
namespaces
classes
files
Gecode home
Generated on Sat Nov 9 2013 19:18:29 for Gecode by
doxygen
1.8.4
gecode
int
member
re-prop.hpp
Go to the documentation of this file.
1
/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2
/*
3
* Main authors:
4
* Christian Schulte <schulte@gecode.org>
5
*
6
* Copyright:
7
* Christian Schulte, 2011
8
*
9
* Last modified:
10
* $Date: 2012-09-07 17:31:22 +0200 (Fri, 07 Sep 2012) $ by $Author: schulte $
11
* $Revision: 13068 $
12
*
13
* This file is part of Gecode, the generic constraint
14
* development environment:
15
* http://www.gecode.org
16
*
17
* Permission is hereby granted, free of charge, to any person obtaining
18
* a copy of this software and associated documentation files (the
19
* "Software"), to deal in the Software without restriction, including
20
* without limitation the rights to use, copy, modify, merge, publish,
21
* distribute, sublicense, and/or sell copies of the Software, and to
22
* permit persons to whom the Software is furnished to do so, subject to
23
* the following conditions:
24
*
25
* The above copyright notice and this permission notice shall be
26
* included in all copies or substantial portions of the Software.
27
*
28
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
29
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
30
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
31
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
32
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
33
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
34
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35
*
36
*/
37
38
#include <
gecode/int/rel.hh
>
39
40
namespace
Gecode {
namespace
Int {
namespace
Member {
41
42
template
<
class
View, ReifyMode rm>
43
forceinline
44
ReProp<View,rm>::ReProp
(
Home
home,
ValSet
& vs,
ViewArray<View>
&
x
, View y,
45
BoolView
b0)
46
:
Prop
<View>(home,vs,x,y),
b
(b0) {
47
b
.
subscribe
(home,*
this
,
PC_BOOL_VAL
);
48
}
49
50
template
<
class
View, ReifyMode rm>
51
inline
ExecStatus
52
ReProp<View,rm>::post
(
Home
home,
ViewArray<View>
&
x
, View y,
BoolView
b
) {
53
if
(x.
size
() == 0) {
54
if
(rm !=
RM_PMI
)
55
GECODE_ME_CHECK
(b.
zero
(home));
56
return
ES_OK
;
57
}
58
59
x.
unique
(home);
60
61
if
(x.
size
() == 1)
62
return
Rel::ReEqDom<View,BoolView,rm>::post
(home,x[0],y,b);
63
64
if
(x.
same
(home,y)) {
65
if
(rm !=
RM_IMP
)
66
GECODE_ME_CHECK
(b.
one
(home));
67
return
ES_OK
;
68
}
69
70
// Eliminate assigned views and store them into the value set
71
ValSet
vs;
72
add(home, vs, x);
73
74
switch
(vs.
compare
(y)) {
75
case
Iter::Ranges::CS_SUBSET
:
76
if
(rm !=
RM_IMP
)
77
GECODE_ME_CHECK
(b.
one
(home));
78
return
ES_OK
;
79
case
Iter::Ranges::CS_DISJOINT
:
80
if
(x.
size
() == 0) {
81
if
(rm !=
RM_PMI
)
82
GECODE_ME_CHECK
(b.
zero
(home));
83
return
ES_OK
;
84
}
85
break
;
86
case
Iter::Ranges::CS_NONE
:
87
break
;
88
default
:
89
GECODE_NEVER
;
90
}
91
92
(void)
new
(home)
ReProp<View,rm>
(home, vs,
x
, y,
b
);
93
return
ES_OK
;
94
}
95
96
template
<
class
View, ReifyMode rm>
97
forceinline
98
ReProp<View,rm>::ReProp
(
Space
& home,
bool
share,
ReProp<View,rm>
&
p
)
99
:
Prop
<View>(home, share, p) {
100
b
.
update
(home, share, p.
b
);
101
}
102
103
template
<
class
View, ReifyMode rm>
104
Propagator
*
105
ReProp<View,rm>::copy
(
Space
& home,
bool
share) {
106
return
new
(home)
ReProp<View,rm>
(home, share, *
this
);
107
}
108
109
template
<
class
View, ReifyMode rm>
110
forceinline
size_t
111
ReProp<View,rm>::dispose
(
Space
& home) {
112
b
.cancel(home, *
this
,
PC_BOOL_VAL
);
113
(void)
Prop<View>::dispose
(home);
114
return
sizeof
(*this);
115
}
116
117
template
<
class
View, ReifyMode rm>
118
ExecStatus
119
ReProp<View,rm>::propagate
(
Space
& home,
const
ModEventDelta
& med) {
120
// Add assigned views to value set
121
if
(View::me(med) ==
ME_INT_VAL
)
122
add(home,vs,
x
);
123
124
if
(
b
.one()) {
125
if
(rm ==
RM_PMI
)
126
return
home.
ES_SUBSUMED
(*
this
);
127
ValSet
vsc(vs);
128
vs.flush();
129
GECODE_REWRITE
(*
this
,
Prop<View>::post
(home,vsc,
x
,y));
130
}
131
132
if
(
b
.zero()) {
133
if
(rm !=
RM_IMP
) {
134
ValSet::Ranges
vsr(vs);
135
GECODE_ME_CHECK
(y.minus_r(home,vsr,
false
));
136
for
(
int
i
=
x
.size();
i
--; )
137
GECODE_ES_CHECK
(
Rel::Nq<View>::post
(home,
x
[
i
],y));
138
}
139
return
home.
ES_SUBSUMED
(*
this
);
140
}
141
142
// Eliminate views from x
143
eliminate
(home);
144
145
switch
(vs.compare(y)) {
146
case
Iter::Ranges::CS_SUBSET
:
147
if
(rm !=
RM_IMP
)
148
GECODE_ME_CHECK
(
b
.one(home));
149
return
home.
ES_SUBSUMED
(*
this
);
150
case
Iter::Ranges::CS_DISJOINT
:
151
if
(
x
.size() == 0) {
152
if
(rm !=
RM_PMI
)
153
GECODE_ME_CHECK
(
b
.zero(home));
154
return
home.
ES_SUBSUMED
(*
this
);
155
}
156
break
;
157
case
Iter::Ranges::CS_NONE
:
158
break
;
159
default
:
160
GECODE_NEVER
;
161
}
162
163
// Check whether y is in union of x and value set
164
if
(
x
.size() > 0) {
165
Region
r
(home);
166
167
ValSet::Ranges
vsr(vs);
168
ViewRanges<View>
xsr(
x
[
x
.size()-1]);
169
Iter::Ranges::NaryUnion
u
(r,vsr,xsr);
170
for
(
int
i
=
x
.size()-1;
i
--; ) {
171
ViewRanges<View>
xir(
x
[
i
]);
172
u |= xir;
173
}
174
175
ViewRanges<View>
yr(y);
176
177
if
(
Iter::Ranges::disjoint
(u,yr)) {
178
if
(rm !=
RM_PMI
)
179
GECODE_ME_CHECK
(
b
.zero(home));
180
return
home.
ES_SUBSUMED
(*
this
);
181
}
182
}
183
184
return
ES_FIX
;
185
}
186
187
}}}
188
189
// STATISTICS: int-prop