this repo has no description
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 * This file is part of Gecode, the generic constraint
10 * development environment:
11 * http://www.gecode.org
12 *
13 * Permission is hereby granted, free of charge, to any person obtaining
14 * a copy of this software and associated documentation files (the
15 * "Software"), to deal in the Software without restriction, including
16 * without limitation the rights to use, copy, modify, merge, publish,
17 * distribute, sublicense, and/or sell copies of the Software, and to
18 * permit persons to whom the Software is furnished to do so, subject to
19 * the following conditions:
20 *
21 * The above copyright notice and this permission notice shall be
22 * included in all copies or substantial portions of the Software.
23 *
24 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
28 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
29 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
30 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 *
32 */
33
34#include <gecode/int/rel.hh>
35
36namespace Gecode { namespace Int { namespace Count {
37
38 /*
39 * Counting domain consistent equality
40 *
41 */
42
43 template<class VY>
44 forceinline bool
45 isintset(VY y) {
46 (void) y;
47 return false;
48 }
49 template<>
50 forceinline bool
51 isintset(IntSet y) {
52 (void) y;
53 return true;
54 }
55
56
57 template<class VY>
58 forceinline bool
59 isval(VY y) {
60 return y.assigned();
61 }
62 template<>
63 forceinline bool
64 isval(IntSet y) {
65 (void) y;
66 return true;
67 }
68
69
70 forceinline void
71 subscribe(Space& home, Propagator& p, IntSet& y) {
72 (void) home; (void) p; (void) y;
73 }
74 template<class VY>
75 forceinline void
76 subscribe(Space& home, Propagator& p, VY y) {
77 y.subscribe(home, p, PC_INT_DOM);
78 }
79
80 forceinline void
81 cancel(Space& home, Propagator& p, IntSet& y) {
82 (void) home; (void) p;
83 y.~IntSet();
84 }
85 template<class VY>
86 forceinline void
87 cancel(Space& home, Propagator& p, VY y) {
88 y.cancel(home, p, PC_INT_DOM);
89 }
90
91 forceinline void
92 reschedule(Space& home, Propagator& p, IntSet& y) {
93 (void) home; (void) p; (void) y;
94 }
95 template<class VY>
96 forceinline void
97 reschedule(Space& home, Propagator& p, VY y) {
98 (void) y; // To satisy MSVC
99 y.schedule(home, p, PC_INT_DOM);
100 }
101
102 forceinline void
103 update(IntSet& y, Space& home, IntSet& py) {
104 (void) home;
105 y=py;
106 }
107 template<class VY>
108 forceinline void
109 update(VY& y, Space& home, VY py) {
110 y.update(home, py);
111 }
112
113 template<class VX>
114 forceinline RelTest
115 holds(VX x, ConstIntView y) {
116 return rtest_eq_dom(x,y.val());
117 }
118 template<class VX>
119 forceinline RelTest
120 holds(VX x, ZeroIntView) {
121 return rtest_eq_dom(x,0);
122 }
123 template<class VX>
124 forceinline RelTest
125 holds(VX x, const IntSet& y) {
126 if ((x.max() < y.min()) || (y.max() < x.min()))
127 return RT_FALSE;
128 ViewRanges<VX> rx(x);
129 IntSetRanges ry(y);
130 switch (Iter::Ranges::compare(rx,ry)) {
131 case Iter::Ranges::CS_SUBSET:
132 return RT_TRUE;
133 case Iter::Ranges::CS_DISJOINT:
134 return RT_FALSE;
135 case Iter::Ranges::CS_NONE:
136 return RT_MAYBE;
137 default:
138 GECODE_NEVER;
139 }
140 GECODE_NEVER;
141 return RT_MAYBE;
142 }
143 template<class VX>
144 forceinline RelTest
145 holds(VX x, VX y) {
146 return rtest_eq_dom(x,y);
147 }
148
149 template<class VX>
150 forceinline ExecStatus
151 post_true(Home home, VX x, ConstIntView y) {
152 GECODE_ME_CHECK(x.eq(home,y.val()));
153 return ES_OK;
154 }
155 template<class VX>
156 forceinline ExecStatus
157 post_true(Home home, VX x, ZeroIntView) {
158 GECODE_ME_CHECK(x.eq(home,0));
159 return ES_OK;
160 }
161 template<class VX>
162 forceinline ExecStatus
163 post_true(Home home, VX x, const IntSet& y) {
164 IntSetRanges ry(y);
165 GECODE_ME_CHECK(x.inter_r(home,ry,false));
166 return ES_OK;
167 }
168 template<class VX>
169 forceinline ExecStatus
170 post_true(Home home, ViewArray<VX>& x, ConstIntView y) {
171 for (int i=0; i<x.size(); i++)
172 GECODE_ME_CHECK(x[i].eq(home,y.val()));
173 return ES_OK;
174 }
175 template<class VX>
176 forceinline ExecStatus
177 post_true(Home home, ViewArray<VX>& x, ZeroIntView) {
178 for (int i=0; i<x.size(); i++)
179 GECODE_ME_CHECK(x[i].eq(home,0));
180 return ES_OK;
181 }
182 template<class VX>
183 forceinline ExecStatus
184 post_true(Home home, ViewArray<VX>& x, const IntSet& y) {
185 for (int i=0; i<x.size(); i++) {
186 IntSetRanges ry(y);
187 GECODE_ME_CHECK(x[i].inter_r(home,ry,false));
188 }
189 return ES_OK;
190 }
191
192 template<class VX>
193 forceinline ExecStatus
194 post_false(Home home, VX x, ConstIntView y) {
195 GECODE_ME_CHECK(x.nq(home,y.val()));
196 return ES_OK;
197 }
198 template<class VX>
199 forceinline ExecStatus
200 post_false(Home home, VX x, ZeroIntView) {
201 GECODE_ME_CHECK(x.nq(home,0));
202 return ES_OK;
203 }
204 template<class VX>
205 forceinline ExecStatus
206 post_false(Home home, VX x, const IntSet& y) {
207 IntSetRanges ry(y);
208 GECODE_ME_CHECK(x.minus_r(home,ry,false));
209 return ES_OK;
210 }
211 template<class VX>
212 forceinline ExecStatus
213 post_false(Home home, ViewArray<VX>& x, ConstIntView y) {
214 for (int i=0; i<x.size(); i++)
215 GECODE_ME_CHECK(x[i].nq(home,y.val()));
216 return ES_OK;
217 }
218 template<class VX>
219 forceinline ExecStatus
220 post_false(Home home, ViewArray<VX>& x, ZeroIntView) {
221 for (int i=0; i<x.size(); i++)
222 GECODE_ME_CHECK(x[i].nq(home,0));
223 return ES_OK;
224 }
225 template<class VX>
226 forceinline ExecStatus
227 post_false(Home home, ViewArray<VX>& x, const IntSet& y) {
228 for (int i=0; i<x.size(); i++) {
229 IntSetRanges ry(y);
230 GECODE_ME_CHECK(x[i].minus_r(home,ry,false));
231 }
232 return ES_OK;
233 }
234
235 template<class VX>
236 forceinline ExecStatus
237 post_true(Home home, ViewArray<VX>& x, VX y) {
238 ViewArray<VX> z(home,x.size()+1);
239 z[x.size()] = y;
240 for (int i=0; i<x.size(); i++)
241 z[i] = x[i];
242 return Rel::NaryEqDom<VX>::post(home,z);
243 }
244 template<class VX>
245 forceinline ExecStatus
246 post_true(Home home, VX x, VX y) {
247 return Rel::EqDom<VX,VX>::post(home,x,y);
248 }
249 template<class VX>
250 forceinline ExecStatus
251 post_false(Home home, ViewArray<VX>& x, VX y) {
252 for (int i=0; i<x.size(); i++)
253 GECODE_ES_CHECK((Rel::Nq<VX,VX>::post(home,x[i],y)));
254 return ES_OK;
255 }
256 template<class VX>
257 forceinline ExecStatus
258 post_false(Home home, VX x, VX y) {
259 return Rel::Nq<VX,VX>::post(home,x,y);
260 }
261
262 template<class VX>
263 forceinline ExecStatus
264 prune(Space& home, ViewArray<VX>& x, ConstIntView) {
265 (void) home;
266 (void) x;
267 return ES_OK;
268 }
269 template<class VX>
270 forceinline ExecStatus
271 prune(Space& home, ViewArray<VX>& x, ZeroIntView) {
272 (void) home;
273 (void) x;
274 return ES_OK;
275 }
276 template<class VX>
277 forceinline ExecStatus
278 prune(Space& home, ViewArray<VX>& x, const IntSet& y) {
279 (void) home;
280 (void) x;
281 (void) y;
282 return ES_OK;
283 }
284 template<class VX>
285 forceinline ExecStatus
286 prune(Space& home, ViewArray<VX>& x, VX y) {
287 if (x.size() == 0)
288 return ES_OK;
289 Region r;
290 ViewRanges<VX>* rx = r.alloc<ViewRanges<VX> >(x.size());
291 for (int i=0; i<x.size(); i++)
292 rx[i] = ViewRanges<VX>(x[i]);
293 Iter::Ranges::NaryUnion u(r, rx, x.size());
294 GECODE_ME_CHECK(y.inter_r(home, u, false));
295 return ES_OK;
296 }
297
298}}}
299
300// STATISTICS: int-prop