Generated on for Gecode by doxygen 1.15.0
element.cpp
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.dev>
5 *
6 * Copyright:
7 * Christian Schulte, 2004
8 *
9 * This file is part of Gecode, the generic constraint
10 * development environment:
11 * http://www.gecode.dev
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/element.hh>
35
36namespace Gecode {
37
38 void
41 using namespace Int;
42 if (c.size() == 0)
43 throw TooFewArguments("Int::element");
45 for (int i=0; i<c.size(); i++)
46 Limits::check(c[i],"Int::element");
48 }
49
50 void
51 element(Home home, IntSharedArray c, IntVar x0, int offset, IntVar x1,
53 using namespace Int;
54 if (c.size() == 0)
55 throw TooFewArguments("Int::element");
57 for (int i=0; i<c.size(); i++)
58 Limits::check(c[i],"Int::element");
59 if (offset==0) {
61 } else {
62 OffsetView ov(x0,offset);
64 }
65 }
66
67 void
70 using namespace Int;
71 if (c.size() == 0)
72 throw TooFewArguments("Int::element");
74 for (int i=0; i<c.size(); i++)
75 Limits::check(c[i],"Int::element");
77 }
78
79 void
80 element(Home home, IntSharedArray c, IntVar x0, int offset, BoolVar x1,
82 using namespace Int;
83 if (c.size() == 0)
84 throw TooFewArguments("Int::element");
86 for (int i=0; i<c.size(); i++)
87 Limits::check(c[i],"Int::element");
88 if (offset==0) {
90 } else {
91 OffsetView ov(x0,offset);
93 }
94 }
95
96 void
97 element(Home home, IntSharedArray c, IntVar x0, int x1,
99 using namespace Int;
100 if (c.size() == 0)
101 throw TooFewArguments("Int::element");
102 Limits::check(x1,"Int::element");
104 for (int i=0; i<c.size(); i++)
105 Limits::check(c[i],"Int::element");
106 ConstIntView cx1(x1);
108 }
109
110 void
111 element(Home home, IntSharedArray c, IntVar x0, int offset, int x1,
112 IntPropLevel) {
113 using namespace Int;
114 if (c.size() == 0)
115 throw TooFewArguments("Int::element");
116 Limits::check(x1,"Int::element");
118 for (int i=0; i<c.size(); i++)
119 Limits::check(c[i],"Int::element");
120 ConstIntView cx1(x1);
121 if (offset==0) {
123 } else {
124 OffsetView ov(x0,offset);
126 }
127 }
128
129 void
130 element(Home home, const IntVarArgs& c, IntVar x0, IntVar x1,
131 IntPropLevel ipl) {
132 using namespace Int;
133 if (c.size() == 0)
134 throw TooFewArguments("Int::element");
136 IdxViewArray<IntView> iv(home,c);
137 if ((vbd(ipl) == IPL_DOM) || (vbd(ipl) == IPL_DEF)) {
139 ::post(home,iv,x0,x1)));
140 } else {
142 ::post(home,iv,x0,x1)));
143 }
144 }
145
146 void
147 element(Home home, const IntVarArgs& c, IntVar x0, int offset, IntVar x1,
148 IntPropLevel ipl) {
149 using namespace Int;
150 if (c.size() == 0)
151 throw TooFewArguments("Int::element");
153 IdxViewArray<IntView> iv(home,c);
154 if ((vbd(ipl) == IPL_DOM) || (vbd(ipl) == IPL_DEF)) {
155 if (offset==0) {
157 ::post(home,iv,x0,x1)));
158 } else {
159 OffsetView ov(x0,offset);
161 ::post(home,iv,ov,x1)));
162 }
163 } else {
164 if (offset==0) {
166 ::post(home,iv,x0,x1)));
167 } else {
168 OffsetView ov(x0,offset);
170 ::post(home,iv,ov,x1)));
171 }
172 }
173 }
174
175 void
176 element(Home home, const IntVarArgs& c, IntVar x0, int x1,
177 IntPropLevel ipl) {
178 using namespace Int;
179 if (c.size() == 0)
180 throw TooFewArguments("Int::element");
181 Limits::check(x1,"Int::element");
183 IdxViewArray<IntView> iv(home,c);
184 ConstIntView v1(x1);
185 if ((vbd(ipl) == IPL_DOM) || (vbd(ipl) == IPL_DEF)) {
187 ::post(home,iv,x0,v1)));
188 } else {
190 ::post(home,iv,x0,v1)));
191 }
192 }
193
194 void
195 element(Home home, const IntVarArgs& c, IntVar x0, int offset, int x1,
196 IntPropLevel ipl) {
197 using namespace Int;
198 if (c.size() == 0)
199 throw TooFewArguments("Int::element");
200 Limits::check(x1,"Int::element");
202 IdxViewArray<IntView> iv(home,c);
203 ConstIntView v1(x1);
204 if ((vbd(ipl) == IPL_DOM) || (vbd(ipl) == IPL_DEF)) {
205 if (offset==0) {
207 ::post(home,iv,x0,v1)));
208 } else {
209 OffsetView ov(x0,offset);
211 ::post(home,iv,ov,v1)));
212 }
213 } else {
214 if (offset==0) {
216 ::post(home,iv,x0,v1)));
217 } else {
218 OffsetView ov(x0,offset);
220 ::post(home,iv,ov,v1)));
221 }
222 }
223 }
224
225 void
226 element(Home home, const BoolVarArgs& c, IntVar x0, BoolVar x1,
227 IntPropLevel) {
228 using namespace Int;
229 if (c.size() == 0)
230 throw TooFewArguments("Int::element");
232 IdxViewArray<BoolView> iv(home,c);
234 ::post(home,iv,x0,x1)));
235 }
236
237 void
238 element(Home home, const BoolVarArgs& c, IntVar x0, int offset, BoolVar x1,
239 IntPropLevel) {
240 using namespace Int;
241 if (c.size() == 0)
242 throw TooFewArguments("Int::element");
244 IdxViewArray<BoolView> iv(home,c);
245 if (offset==0) {
247 ::post(home,iv,x0,x1)));
248 } else {
249 OffsetView ov(x0,offset);
251 ::post(home,iv,ov,x1)));
252 }
253 }
254
255 void
256 element(Home home, const BoolVarArgs& c, IntVar x0, int x1,
257 IntPropLevel) {
258 using namespace Int;
259 if (c.size() == 0)
260 throw TooFewArguments("Int::element");
261 Limits::check(x1,"Int::element");
263 IdxViewArray<BoolView> iv(home,c);
264 ConstIntView v1(x1);
266 ::post(home,iv,x0,v1)));
267 }
268
269 void
270 element(Home home, const BoolVarArgs& c, IntVar x0, int offset, int x1,
271 IntPropLevel) {
272 using namespace Int;
273 if (c.size() == 0)
274 throw TooFewArguments("Int::element");
275 Limits::check(x1,"Int::element");
277 IdxViewArray<BoolView> iv(home,c);
278 ConstIntView v1(x1);
279 if (offset==0) {
281 ::post(home,iv,x0,v1)));
282 } else {
283 OffsetView ov(x0,offset);
285 ::post(home,iv,ov,v1)));
286
287 }
288 }
289
290 namespace {
291 IntVar
292 pair(Home home, IntVar x, int w, IntVar y, int h) {
293 IntVar xy(home,0,w*h-1);
294 if (Int::Element::Pair::post(home,x,y,xy,w,h) != ES_OK)
295 home.fail();
296 return xy;
297 }
298
299 IntVar
300 pairWithOffsets(Home home, IntVar x, int xoff, int w, IntVar y, int yoff, int h) {
301 IntVar xy(home,0,w*h-1);
302 if (xoff==0 && yoff==0) {
303 if (Int::Element::Pair::post(home,x,y,xy,w,h) != ES_OK)
304 home.fail();
305 } else {
306 Int::OffsetView xo(x,xoff);
307 Int::OffsetView yo(y,yoff);
308 if (Int::Element::PairWithOffsets::post(home,xo,yo,xy,w,h) != ES_OK)
309 home.fail();
310 }
311 return xy;
312 }
313 }
314
315 void
317 IntVar x, int w, IntVar y, int h, IntVar z,
318 IntPropLevel ipl) {
319 using namespace Int;
320 if (a.size() != w*h)
321 throw Int::ArgumentSizeMismatch("Int::element");
323 element(home, a, pair(home,x,w,y,h), z, ipl);
324 }
325
326 void
328 IntVar x, int xoff, int w,
329 IntVar y, int yoff, int h,
330 IntVar z, IntPropLevel ipl) {
331 using namespace Int;
332 if (a.size() != w*h)
333 throw Int::ArgumentSizeMismatch("Int::element");
335 element(home, a, pairWithOffsets(home,x,xoff,w,y,yoff,h), z, ipl);
336 }
337
338 void
340 IntVar x, int w, IntVar y, int h, BoolVar z,
341 IntPropLevel ipl) {
342 using namespace Int;
343 if (a.size() != w*h)
344 throw Int::ArgumentSizeMismatch("Int::element");
346 element(home, a, pair(home,x,w,y,h), z, ipl);
347 }
348
349 void
351 IntVar x, int xoff, int w, IntVar y, int yoff, int h,
352 BoolVar z, IntPropLevel ipl) {
353 using namespace Int;
354 if (a.size() != w*h)
355 throw Int::ArgumentSizeMismatch("Int::element");
357 element(home, a, pairWithOffsets(home,x,xoff,w,y,yoff,h), z, ipl);
358 }
359
360 void
361 element(Home home, const IntVarArgs& a,
362 IntVar x, int w, IntVar y, int h, IntVar z,
363 IntPropLevel ipl) {
364 using namespace Int;
365 if (a.size() != w*h)
366 throw Int::ArgumentSizeMismatch("Int::element");
368 element(home, a, pair(home,x,w,y,h), z, ipl);
369 }
370
371 void
372 element(Home home, const IntVarArgs& a,
373 IntVar x, int xoff, int w,
374 IntVar y, int yoff, int h,
375 IntVar z, IntPropLevel ipl) {
376 using namespace Int;
377 if (a.size() != w*h)
378 throw Int::ArgumentSizeMismatch("Int::element");
380 element(home, a, pairWithOffsets(home,x,xoff,w,y,yoff,h), z, ipl);
381 }
382
383 void
384 element(Home home, const BoolVarArgs& a,
385 IntVar x, int w, IntVar y, int h, BoolVar z,
386 IntPropLevel ipl) {
387 using namespace Int;
388 if (a.size() != w*h)
389 throw Int::ArgumentSizeMismatch("Int::element");
391 element(home, a, pair(home,x,w,y,h), z, ipl);
392 }
393
394 void
395 element(Home home, const BoolVarArgs& a,
396 IntVar x, int xoff, int w,
397 IntVar y, int yoff, int h,
398 BoolVar z, IntPropLevel ipl) {
399 using namespace Int;
400 if (a.size() != w*h)
401 throw Int::ArgumentSizeMismatch("Int::element");
403 element(home, a, pairWithOffsets(home,x,xoff,w,y,yoff,h), z, ipl);
404 }
405
406}
407
408// STATISTICS: int-post
Passing Boolean variables.
Definition int.hh:738
Boolean integer variables.
Definition int.hh:533
FloatNum size(void) const
Return size of float value (distance between maximum and minimum).
Definition val.hpp:78
Home class for posting propagators
Definition core.hpp:863
Passing integer variables.
Definition int.hh:680
Integer variables.
Definition int.hh:389
Exception: Arguments are of different size
Definition exception.hpp:73
Constant integer view.
Definition view.hpp:851
static ExecStatus post(Home home, OffsetView x0, OffsetView x1, IntView x2, int w, int h)
Post propagator .
Definition pair.hpp:74
static ExecStatus post(Home home, IntView x0, IntView x1, IntView x2, int w, int h)
Post propagator .
Definition pair.hpp:43
Bounds consistent element propagator for array of views.
Definition element.hh:232
Domain consistent element propagator for array of views.
Definition element.hh:262
An array of IdxView pairs.
Definition idx-view.hh:67
Offset integer view.
Definition view.hpp:443
Exception: Too few arguments available in argument array
Definition exception.hpp:66
#define GECODE_POST
Check for failure in a constraint post function.
Definition macros.hpp:40
#define GECODE_ES_FAIL(es)
Check whether execution status es is failed, and fail space home.
Definition macros.hpp:103
IntPropLevel
Propagation levels for integer propagators.
Definition int.hh:1008
@ IPL_DOM
Domain propagation Options: basic versus advanced propagation.
Definition int.hh:1013
@ IPL_DEF
Simple propagation levels.
Definition int.hh:1010
ExecStatus post_int(Home home, IntSharedArray &c, V0 x0, V1 x1)
Post propagator with appropriate index and value types.
Definition int.hpp:405
void check(int n, const char *l)
Check whether n is in range, otherwise throw out of limits with information l.
Definition limits.hpp:46
Finite domain integers.
Definition lastval.hh:52
Gecode toplevel namespace
SharedArray< int > IntSharedArray
Arrays of integers that can be shared among several element constraints.
Definition int.hh:1512
IntPropLevel vbd(IntPropLevel ipl)
Extract value, bounds, or domain propagation from propagation level.
Definition ipl.hpp:37
void element(Home home, IntSharedArray n, IntVar x0, IntVar x1, IntPropLevel ipl=IPL_DEF)
Post domain consistent propagator for .
Definition element.cpp:39
TFE post(PropagatorGroup g)
Only post functions (but not propagators) from g are considered.
Definition filter.cpp:138
@ ES_OK
Execution is okay.
Definition core.hpp:483