main page
modules
namespaces
classes
files
Gecode home
Generated on Tue Mar 5 2013 22:37:18 for Gecode by
doxygen
1.8.3.1
gecode
int
count
rel.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, 2003
8
*
9
* Last modified:
10
* $Date: 2011-08-25 18:41:47 +1000 (Thu, 25 Aug 2011) $ by $Author: tack $
11
* $Revision: 12351 $
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
Count {
41
42
/*
43
* Counting domain consistent equality
44
*
45
*/
46
47
template
<
class
VY>
48
forceinline
ViewTypeDesc
49
vtd
(VY y) {
50
(void) y;
51
return
VTD_VARVIEW
;
52
}
53
template
<>
54
forceinline
ViewTypeDesc
55
vtd
(
const
IntSet
& y) {
56
(void) y;
57
return
VTD_INTSET
;
58
}
59
template
<>
60
forceinline
ViewTypeDesc
61
vtd
(
ConstIntView
y) {
62
(void) y;
63
return
VTD_CONSTVIEW
;
64
}
65
template
<>
66
forceinline
ViewTypeDesc
67
vtd
(
ZeroIntView
y) {
68
(void) y;
69
return
VTD_CONSTVIEW
;
70
}
71
72
73
forceinline
void
74
subscribe
(
Space
& home,
Propagator
& p,
IntSet
& y) {
75
(void) home; (void) p; (void) y;
76
}
77
template
<
class
VY>
78
forceinline
void
79
subscribe
(
Space
& home,
Propagator
& p, VY y) {
80
y.subscribe(home, p,
PC_INT_DOM
);
81
}
82
83
forceinline
void
84
cancel
(
Space
& home,
Propagator
& p,
IntSet
& y) {
85
(void) home; (void) p;
86
y.~IntSet();
87
}
88
template
<
class
VY>
89
forceinline
void
90
cancel
(
Space
& home,
Propagator
& p, VY y) {
91
y.cancel(home, p,
PC_INT_DOM
);
92
}
93
94
template
<
class
VX>
95
forceinline
RelTest
96
holds
(VX x,
ConstIntView
y) {
97
return
rtest_eq_dom
(x,y.
val
());
98
}
99
template
<
class
VX>
100
forceinline
RelTest
101
holds
(VX x,
ZeroIntView
) {
102
return
rtest_eq_dom
(x,0);
103
}
104
template
<
class
VX>
105
forceinline
RelTest
106
holds
(VX x,
const
IntSet
& y) {
107
if
((x.max() < y.
min
()) || (y.
max
() < x.min()))
108
return
RT_FALSE
;
109
ViewRanges<VX>
rx(x);
110
IntSetRanges
ry(y);
111
switch
(
Iter::Ranges::compare
(rx,ry)) {
112
case
Iter::Ranges::CS_SUBSET
:
113
return
RT_TRUE
;
114
case
Iter::Ranges::CS_DISJOINT
:
115
return
RT_FALSE
;
116
case
Iter::Ranges::CS_NONE
:
117
return
RT_MAYBE
;
118
default
:
119
GECODE_NEVER
;
120
}
121
GECODE_NEVER
;
122
return
RT_MAYBE
;
123
}
124
template
<
class
VX>
125
forceinline
RelTest
126
holds
(VX x, VX y) {
127
return
rtest_eq_dom
(x,y);
128
}
129
130
template
<
class
VX>
131
forceinline
ExecStatus
132
post_true
(
Home
home, VX x,
ConstIntView
y) {
133
GECODE_ME_CHECK
(x.eq(home,y.
val
()));
134
return
ES_OK
;
135
}
136
template
<
class
VX>
137
forceinline
ExecStatus
138
post_true
(
Home
home, VX x,
ZeroIntView
) {
139
GECODE_ME_CHECK
(x.eq(home,0));
140
return
ES_OK
;
141
}
142
template
<
class
VX>
143
forceinline
ExecStatus
144
post_true
(
Home
home, VX x,
const
IntSet
& y) {
145
IntSetRanges
ry(y);
146
GECODE_ME_CHECK
(x.inter_r(home,ry,
false
));
147
return
ES_OK
;
148
}
149
template
<
class
VX>
150
forceinline
ExecStatus
151
post_true
(
Home
home,
ViewArray<VX>
& x,
ConstIntView
y) {
152
for
(
int
i
= x.
size
();
i
--; )
153
GECODE_ME_CHECK
(x[
i
].eq(home,y.
val
()));
154
return
ES_OK
;
155
}
156
template
<
class
VX>
157
forceinline
ExecStatus
158
post_true
(
Home
home,
ViewArray<VX>
& x,
ZeroIntView
) {
159
for
(
int
i
= x.
size
();
i
--; )
160
GECODE_ME_CHECK
(x[
i
].eq(home,0));
161
return
ES_OK
;
162
}
163
template
<
class
VX>
164
forceinline
ExecStatus
165
post_true
(
Home
home,
ViewArray<VX>
& x,
const
IntSet
& y) {
166
for
(
int
i
= x.
size
();
i
--; ) {
167
IntSetRanges
ry(y);
168
GECODE_ME_CHECK
(x[
i
].inter_r(home,ry,
false
));
169
}
170
return
ES_OK
;
171
}
172
173
template
<
class
VX>
174
forceinline
ExecStatus
175
post_false
(
Home
home, VX x,
ConstIntView
y) {
176
GECODE_ME_CHECK
(x.nq(home,y.
val
()));
177
return
ES_OK
;
178
}
179
template
<
class
VX>
180
forceinline
ExecStatus
181
post_false
(
Home
home, VX x,
ZeroIntView
) {
182
GECODE_ME_CHECK
(x.nq(home,0));
183
return
ES_OK
;
184
}
185
template
<
class
VX>
186
forceinline
ExecStatus
187
post_false
(
Home
home, VX x,
const
IntSet
& y) {
188
IntSetRanges
ry(y);
189
GECODE_ME_CHECK
(x.minus_r(home,ry,
false
));
190
return
ES_OK
;
191
}
192
template
<
class
VX>
193
forceinline
ExecStatus
194
post_false
(
Home
home,
ViewArray<VX>
& x,
ConstIntView
y) {
195
for
(
int
i
= x.
size
();
i
--; )
196
GECODE_ME_CHECK
(x[
i
].nq(home,y.
val
()));
197
return
ES_OK
;
198
}
199
template
<
class
VX>
200
forceinline
ExecStatus
201
post_false
(
Home
home,
ViewArray<VX>
& x,
ZeroIntView
) {
202
for
(
int
i
= x.
size
();
i
--; )
203
GECODE_ME_CHECK
(x[
i
].nq(home,0));
204
return
ES_OK
;
205
}
206
template
<
class
VX>
207
forceinline
ExecStatus
208
post_false
(
Home
home,
ViewArray<VX>
& x,
const
IntSet
& y) {
209
for
(
int
i
= x.
size
();
i
--; ) {
210
IntSetRanges
ry(y);
211
GECODE_ME_CHECK
(x[
i
].minus_r(home,ry,
false
));
212
}
213
return
ES_OK
;
214
}
215
216
template
<
class
VX>
217
forceinline
ExecStatus
218
post_true
(
Home
home,
ViewArray<VX>
& x, VX y) {
219
ViewArray<VX>
z(home,x.
size
()+1);
220
z[x.
size
()] = y;
221
for
(
int
i
= x.
size
();
i
--; )
222
z[
i
] = x[
i
];
223
return
Rel::NaryEqDom<VX>::post
(home,z);
224
}
225
template
<
class
VX>
226
forceinline
ExecStatus
227
post_true
(
Home
home, VX x, VX y) {
228
return
Rel::EqDom<VX,VX>::post
(home,x,y);
229
}
230
template
<
class
VX>
231
forceinline
ExecStatus
232
post_false
(
Home
home,
ViewArray<VX>
& x, VX y) {
233
for
(
int
i
= x.
size
();
i
--; )
234
GECODE_ES_CHECK
(
Rel::Nq<VX>::post
(home,x[
i
],y));
235
return
ES_OK
;
236
}
237
template
<
class
VX>
238
forceinline
ExecStatus
239
post_false
(
Home
home, VX x, VX y) {
240
return
Rel::Nq<VX>::post
(home,x,y);
241
}
242
243
template
<
class
VX>
244
forceinline
ExecStatus
245
prune
(
Space
& home,
ViewArray<VX>
& x,
ConstIntView
) {
246
(void) home;
247
(void) x;
248
return
ES_OK
;
249
}
250
template
<
class
VX>
251
forceinline
ExecStatus
252
prune
(
Space
& home,
ViewArray<VX>
& x,
ZeroIntView
) {
253
(void) home;
254
(void) x;
255
return
ES_OK
;
256
}
257
template
<
class
VX>
258
forceinline
ExecStatus
259
prune
(
Space
& home,
ViewArray<VX>
& x,
const
IntSet
& y) {
260
(void) home;
261
(void) x;
262
(void) y;
263
return
ES_OK
;
264
}
265
template
<
class
VX>
266
forceinline
ExecStatus
267
prune
(
Space
& home,
ViewArray<VX>
& x, VX y) {
268
if
(x.
size
() == 0)
269
return
ES_OK
;
270
Region
r
(home);
271
ViewRanges<VX>
* rx = r.
alloc
<
ViewRanges<VX>
>(x.
size
());
272
for
(
int
i
=x.
size
();
i
--; )
273
rx[
i
] =
ViewRanges<VX>
(x[
i
]);
274
Iter::Ranges::NaryUnion
u(r, rx, x.
size
());
275
GECODE_ME_CHECK
(y.inter_r(home, u,
false
));
276
return
ES_OK
;
277
}
278
279
}}}
280
281
// STATISTICS: int-prop