Generated on Thu Jan 16 2025 00:00:00 for Gecode by doxygen 1.14.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 * Guido Tack <tack@gecode.org>
5 * Christian Schulte <schulte@gecode.org>
6 *
7 * Copyright:
8 * Guido Tack, 2004
9 * Christian Schulte, 2004
10 *
11 * This file is part of Gecode, the generic constraint
12 * development environment:
13 * http://www.gecode.org
14 *
15 * Permission is hereby granted, free of charge, to any person obtaining
16 * a copy of this software and associated documentation files (the
17 * "Software"), to deal in the Software without restriction, including
18 * without limitation the rights to use, copy, modify, merge, publish,
19 * distribute, sublicense, and/or sell copies of the Software, and to
20 * permit persons to whom the Software is furnished to do so, subject to
21 * the following conditions:
22 *
23 * The above copyright notice and this permission notice shall be
24 * included in all copies or substantial portions of the Software.
25 *
26 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
27 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
28 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
29 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
30 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
31 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
32 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
33 *
34 */
35
36#include <gecode/set/element.hh>
37
38namespace Gecode {
39
40 namespace Int {
41 template<>
44 public:
46 };
47 }
48
49 using namespace Gecode::Set;
50
51 void
53 const IntSet& universe) {
55
56 switch (op) {
57 case SOT_DUNION:
58 {
60 iv(home, x);
62 post(home,iv,y)));
63 }
64 // fall through
65 case SOT_UNION:
66 {
68 iv(home, x);
71 post(home,iv,y,z)));
72 }
73 break;
74 case SOT_INTER:
75 {
77 iv(home, x);
80 post(home,iv,y,z,universe)));
81 }
82 break;
83 case SOT_MINUS:
84 throw IllegalOperation("Set::element");
85 break;
86 default:
87 throw UnknownOperation("Set::element");
88 }
89 }
90
91 void
93 const IntSet& universe) {
95
96 switch (op) {
97 case SOT_DUNION:
98 {
100 iv(home, x);
102 ::post(home,iv,y)));
103 }
104 // fall through
105 case SOT_UNION:
106 {
108 iv(home, x);
111 post(home,iv,y,z)));
112 }
113 break;
114 case SOT_INTER:
115 {
117 SetView>::IdxViewArray iv(home, x);
120 SetView>::post(home,iv,y,z,universe)));
121 }
122 break;
123 case SOT_MINUS:
124 throw IllegalOperation("Set::element");
125 break;
126 default:
127 throw UnknownOperation("Set::element");
128 }
129 }
130
131 void
133 const IntSet& universe) {
135
136 switch (op) {
137 case SOT_DUNION:
138 {
140 iv(home, x.size());
141 for (int i=x.size(); i--;) {
142 iv[i].idx = i; iv[i].view = ConstSetView(home, x[i]);
143 }
145 post(home,iv,y)));
146 }
147 // fall through
148 case SOT_UNION:
149 {
152 post(home,z,x,y)));
153 }
154 break;
155 case SOT_INTER:
156 {
158 SetView,SetView>::IdxViewArray iv(home, x.size());
159 for (int i=x.size(); i--;) {
160 iv[i].idx = i; iv[i].view = ConstSetView(home, x[i]);
161 }
164 post(home,iv,y,z,universe)));
165 }
166 break;
167 case SOT_MINUS:
168 throw IllegalOperation("Set::element");
169 break;
170 default:
171 throw UnknownOperation("Set::element");
172 }
173
174 }
175
176 void
178 const IntSet& universe) {
179 IntSetArgs xs(x.size());
180 for (int i=x.size(); i--;)
181 xs[i]=IntSet(x[i],x[i]);
182 element(home,op,xs,y,z,universe);
183 }
184
185 void
187 if (x.size() == 0)
188 throw Set::TooFewArguments("Set::element");
191 iv(home, x);
192 SetView zv(z);
193
194 Int::IntView yv(y);
195 SingletonView single(yv);
197 ::post(home, iv, single,zv)));
198 }
199
200 void
202 if (x.size() == 0)
203 throw Set::TooFewArguments("Set::element");
204 for (int i=x.size(); i--;)
205 Set::Limits::check(x[i], "Set::element");
207 SetView zv(z);
208
209 Int::IntView yv(y);
210 SingletonView single(yv);
212 SingletonView>::post(home, z, x, single)));
213 }
214
215
216 namespace {
217 IntVar
218 pair(Home home, IntVar x, int w, IntVar y, int h) {
219 IntVar xy(home,0,w*h-1);
220 if (Int::Element::Pair::post(home,x,y,xy,w,h) != ES_OK)
221 home.fail();
222 return xy;
223 }
224 }
225
226 void
227 element(Home home, const IntSetArgs& a,
228 IntVar x, int w, IntVar y, int h, SetVar z) {
229 if (a.size() == 0)
230 throw Set::TooFewArguments("Set::element");
231 if (a.size() != w*h)
232 throw Set::ArgumentSizeMismatch("Set::element");
234 element(home, a, pair(home,x,w,y,h), z);
235 }
236
237 void
238 element(Home home, const SetVarArgs& a,
239 IntVar x, int w, IntVar y, int h, SetVar z) {
240 if (a.size() == 0)
241 throw Set::TooFewArguments("Set::element");
242 if (a.size() != w*h)
243 throw Set::ArgumentSizeMismatch("Set::element");
245 element(home, a, pair(home,x,w,y,h), z);
246 }
247
248}
249
250// STATISTICS: set-post
251
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:856
void fail(void)
Mark space as failed.
Definition core.hpp:4046
Passing integer arguments.
Definition int.hh:634
Integer sets.
Definition int.hh:174
Passing integer variables.
Definition int.hh:662
Integer variables.
Definition int.hh:371
Exception: Arguments are of different size
Definition exception.hpp:73
static ExecStatus post(Home home, IntView x0, IntView x1, IntView x2, int w, int h)
Post propagator .
Definition pair.hpp:43
An array of IdxView pairs.
Definition idx-view.hh:67
Exception: Illegal operation passed as argument
Integer view for integer variables.
Definition view.hpp:129
Exception: Too few arguments available in argument array
Definition exception.hpp:66
Exception: Unknown operation passed as argument
Definition exception.hpp:94
Class to map VarArg type to view.
Definition idx-view.hh:60
Passing set variables.
Definition set.hh:491
Set variables
Definition set.hh:127
Constant view.
Definition view.hpp:186
Propagator for element with disjointness
Definition element.hh:194
Gecode::Int::IdxViewArray< SView > IdxViewArray
Definition element.hh:196
Propagator for element with intersection
Definition element.hh:78
Gecode::Int::IdxViewArray< View > IdxViewArray
Definition element.hh:80
Propagator for element with union of constant sets
Definition element.hh:157
Propagator for element with union
Definition element.hh:119
Gecode::Int::IdxViewArray< View > IdxViewArray
Definition element.hh:121
Set view for set variables
Definition view.hpp:56
Singleton set view.
Definition view.hpp:594
#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
SetOpType
Common operations for sets.
Definition set.hh:666
@ SOT_MINUS
Difference.
Definition set.hh:670
@ SOT_DUNION
Disjoint union.
Definition set.hh:668
@ SOT_UNION
Union.
Definition set.hh:667
@ SOT_INTER
Intersection
Definition set.hh:669
Finite domain integers.
void check(int n, const char *l)
Check whether integer n is in range, otherwise throw overflow exception with information l.
Definition limits.hpp:37
Finite integer sets.
Definition var-imp.hpp:137
Gecode toplevel namespace
ArgArray< IntSet > IntSetArgs
Passing set arguments.
Definition int.hh:625
void element(Home home, IntSharedArray n, IntVar x0, IntVar x1, IntPropLevel ipl=IPL_DEF)
Post domain consistent propagator for .
Definition element.cpp:39
Post propagator for SetVar SetOpType SetVar SetRelType SetVar z
Definition set.hh:773
Post propagator for SetVar SetOpType SetVar y
Definition set.hh:773
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:476
Post propagator for SetVar x
Definition set.hh:773
Post propagator for SetVar SetOpType op
Definition set.hh:773