main page
modules
namespaces
classes
files
Gecode home
Generated on Fri Aug 24 2012 04:52:21 for Gecode by
doxygen
1.8.1.1
gecode
set
rel
re-subset.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
* Copyright:
8
* Guido Tack, 2004
9
* Christian Schulte, 2004
10
*
11
* Last modified:
12
* $Date: 2010-03-04 03:32:21 +1100 (Thu, 04 Mar 2010) $ by $Author: schulte $
13
* $Revision: 10364 $
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
Rel {
41
42
template
<
class
View0,
class
View1>
43
forceinline
44
ReSubset<View0,View1>::ReSubset
(
Home
home, View0 y0,
45
View1 y1,
Gecode::Int::BoolView
y2)
46
:
Propagator
(home), x0(y0), x1(y1),
b
(y2) {
47
b
.
subscribe
(home,*
this
,
Gecode::Int::PC_INT_VAL
);
48
x0
.subscribe(home,*
this
,
PC_SET_ANY
);
49
x1
.subscribe(home,*
this
,
PC_SET_ANY
);
50
}
51
52
template
<
class
View0,
class
View1>
53
forceinline
54
ReSubset<View0,View1>::ReSubset
(
Space
& home,
bool
share,
ReSubset
& p)
55
:
Propagator
(home,share,p) {
56
x0
.update(home,share,p.
x0
);
57
x1
.update(home,share,p.
x1
);
58
b
.
update
(home,share,p.
b
);
59
}
60
61
template
<
class
View0,
class
View1>
62
PropCost
63
ReSubset<View0,View1>::cost
(
const
Space
&,
const
ModEventDelta
&)
const
{
64
return
PropCost::ternary
(
PropCost::LO
);
65
}
66
67
template
<
class
View0,
class
View1>
68
forceinline
size_t
69
ReSubset<View0,View1>::dispose
(
Space
& home) {
70
b
.cancel(home,*
this
,
Gecode::Int::PC_INT_VAL
);
71
x0.cancel(home,*
this
,
PC_SET_ANY
);
72
x1.cancel(home,*
this
,
PC_SET_ANY
);
73
(void)
Propagator::dispose
(home);
74
return
sizeof
(*this);
75
}
76
77
template
<
class
View0,
class
View1>
78
ExecStatus
79
ReSubset<View0,View1>::post
(
Home
home, View0 x0, View1 x1,
80
Gecode::Int::BoolView
b
) {
81
(void)
new
(home)
ReSubset<View0,View1>
(home,x0,x1,
b
);
82
return
ES_OK
;
83
}
84
85
template
<
class
View0,
class
View1>
86
Actor
*
87
ReSubset<View0,View1>::copy
(
Space
& home,
bool
share) {
88
return
new
(home)
ReSubset<View0,View1>
(home,share,*
this
);
89
}
90
91
template
<
class
View0,
class
View1>
92
ExecStatus
93
ReSubset<View0,View1>::propagate
(
Space
& home,
const
ModEventDelta
&) {
94
if
(
b
.one())
95
GECODE_REWRITE
(*
this
,(
Subset<View0,View1>::post
(home(*
this
),x0,x1)));
96
if
(
b
.zero())
97
GECODE_REWRITE
(*
this
,(
NoSubset<View0,View1>::post
(home(*
this
),x0,x1)));
98
99
// check whether cardinalities still allow subset
100
if
(x0.cardMin() > x1.cardMax()) {
101
GECODE_ME_CHECK
(
b
.zero_none(home));
102
return
home.
ES_SUBSUMED
(*
this
);
103
}
104
105
// check lub(x0) subset glb(x1)
106
{
107
LubRanges<View0>
x0ub(x0);
108
GlbRanges<View1>
x1lb(x1);
109
Iter::Ranges::Diff<LubRanges<View0>
,
GlbRanges<View1>
>
d
(x0ub,x1lb);
110
if
(!
d
()) {
111
GECODE_ME_CHECK
(
b
.one_none(home));
112
return
home.
ES_SUBSUMED
(*
this
);
113
}
114
}
115
116
// check glb(x0) subset lub(x1)
117
{
118
GlbRanges<View0>
x0lb(x0);
119
LubRanges<View1>
x1ub(x1);
120
Iter::Ranges::Diff<GlbRanges<View0>
,
LubRanges<View1>
>
d
(x0lb,x1ub);
121
if
(
d
()) {
122
GECODE_ME_CHECK
(
b
.zero_none(home));
123
return
home.
ES_SUBSUMED
(*
this
);
124
}
else
if
(x0.assigned() && x1.assigned()) {
125
GECODE_ME_CHECK
(
b
.one_none(home));
126
return
home.
ES_SUBSUMED
(*
this
);
127
}
128
}
129
130
if
(x0.cardMin() > 0) {
131
LubRanges<View0>
x0ub(x0);
132
LubRanges<View1>
x1ub(x1);
133
Iter::Ranges::Inter<LubRanges<View0>
,
LubRanges<View1>
>
134
i
(x0ub,x1ub);
135
if
(!
i
()) {
136
GECODE_ME_CHECK
(
b
.zero_none(home));
137
return
home.
ES_SUBSUMED
(*
this
);
138
}
139
}
140
141
return
ES_FIX
;
142
}
143
144
}}}
145
146
// STATISTICS: set-prop