Generated on Sat Feb 7 2015 02:01:22 for Gecode by doxygen 1.8.9.1
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  * Last modified:
12  * $Date: 2015-01-18 16:50:03 +0100 (Sun, 18 Jan 2015) $ by $Author: schulte $
13  * $Revision: 14365 $
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 #include <gecode/set/element.hh>
41 
42 namespace Gecode {
43 
44  namespace Int {
45  template<>
48  public:
50  };
51  }
52 
53  using namespace Gecode::Set;
54 
55  void
56  element(Home home, SetOpType op, const SetVarArgs& x, SetVar y, SetVar z,
57  const IntSet& universe) {
58  if (home.failed()) return;
59 
60  switch (op) {
61  case SOT_DUNION:
62  {
64  iv(home, x);
66  post(home,iv,y)));
67  }
68  // fall through
69  case SOT_UNION:
70  {
72  iv(home, x);
75  post(home,iv,y,z)));
76  }
77  break;
78  case SOT_INTER:
79  {
81  iv(home, x);
84  post(home,iv,y,z,universe)));
85  }
86  break;
87  case SOT_MINUS:
88  throw IllegalOperation("Set::element");
89  break;
90  default:
91  throw UnknownOperation("Set::element");
92  }
93  }
94 
95  void
96  element(Home home, SetOpType op, const IntVarArgs& x, SetVar y, SetVar z,
97  const IntSet& universe) {
98  if (home.failed()) return;
99 
100  switch (op) {
101  case SOT_DUNION:
102  {
104  iv(home, x);
106  ::post(home,iv,y)));
107  }
108  // fall through
109  case SOT_UNION:
110  {
112  iv(home, x);
115  post(home,iv,y,z)));
116  }
117  break;
118  case SOT_INTER:
119  {
121  SetView>::IdxViewArray iv(home, x);
123  (Element::ElementIntersection<SingletonView,SetView,
124  SetView>::post(home,iv,y,z,universe)));
125  }
126  break;
127  case SOT_MINUS:
128  throw IllegalOperation("Set::element");
129  break;
130  default:
131  throw UnknownOperation("Set::element");
132  }
133  }
134 
135  void
136  element(Home home, SetOpType op, const IntSetArgs& x, SetVar y, SetVar z,
137  const IntSet& universe) {
138  if (home.failed()) return;
139 
140  switch (op) {
141  case SOT_DUNION:
142  {
144  iv(home, x.size());
145  for (int i=x.size(); i--;) {
146  iv[i].idx = i; iv[i].view = ConstSetView(home, x[i]);
147  }
149  post(home,iv,y)));
150  }
151  // fall through
152  case SOT_UNION:
153  {
156  post(home,z,x,y)));
157  }
158  break;
159  case SOT_INTER:
160  {
162  SetView,SetView>::IdxViewArray iv(home, x.size());
163  for (int i=x.size(); i--;) {
164  iv[i].idx = i; iv[i].view = ConstSetView(home, x[i]);
165  }
168  post(home,iv,y,z,universe)));
169  }
170  break;
171  case SOT_MINUS:
172  throw IllegalOperation("Set::element");
173  break;
174  default:
175  throw UnknownOperation("Set::element");
176  }
177 
178  }
179 
180  void
181  element(Home home, SetOpType op, const IntArgs& x, SetVar y, SetVar z,
182  const IntSet& universe) {
183  IntSetArgs xs(x.size());
184  for (int i=x.size(); i--;)
185  xs[i]=IntSet(x[i],x[i]);
186  element(home,op,xs,y,z,universe);
187  }
188 
189  void
190  element(Home home, const SetVarArgs& x, IntVar y, SetVar z) {
191  if (x.size() == 0)
192  throw Set::TooFewArguments("Set::element");
193  if (home.failed()) return;
195  iv(home, x);
196  SetView zv(z);
197 
198  Int::IntView yv(y);
199  SingletonView single(yv);
201  ::post(home, iv, single,zv)));
202  }
203 
204  void
205  element(Home home, const IntSetArgs& x, IntVar y, SetVar z) {
206  if (x.size() == 0)
207  throw Set::TooFewArguments("Set::element");
208  for (int i=x.size(); i--;)
209  Set::Limits::check(x[i], "Set::element");
210  if (home.failed()) return;
211  SetView zv(z);
212 
213  Int::IntView yv(y);
214  SingletonView single(yv);
216  SingletonView>::post(home, z, x, single)));
217  }
218 
219 
220  namespace {
221  IntVar
222  pair(Home home, IntVar x, int w, IntVar y, int h) {
223  IntVar xy(home,0,w*h-1);
224  if (Int::Element::Pair::post(home,x,y,xy,w,h) != ES_OK)
225  home.fail();
226  return xy;
227  }
228  }
229 
230  void
231  element(Home home, const IntSetArgs& a,
232  IntVar x, int w, IntVar y, int h, SetVar z) {
233  if (a.size() == 0)
234  throw Set::TooFewArguments("Set::element");
235  if (a.size() != w*h)
236  throw Set::ArgumentSizeMismatch("Set::element");
237  if (home.failed()) return;
238  element(home, a, pair(home,x,w,y,h), z);
239  }
240 
241  void
242  element(Home home, const SetVarArgs& a,
243  IntVar x, int w, IntVar y, int h, SetVar z) {
244  if (a.size() == 0)
245  throw Set::TooFewArguments("Set::element");
246  if (a.size() != w*h)
247  throw Set::ArgumentSizeMismatch("Set::element");
248  if (home.failed()) return;
249  element(home, a, pair(home,x,w,y,h), z);
250  }
251 
252 }
253 
254 // STATISTICS: set-post
255 
bool failed(void) const
Check whether corresponding space is failed.
Definition: core.hpp:3446
void check(int n, const char *l)
Check whether integer n is in range, otherwise throw overflow exception with information l...
Definition: limits.hpp:41
void post(Home home, Term *t, int n, FloatRelType frt, FloatVal c)
Post propagator for linear constraint over floats.
Definition: post.cpp:228
static ExecStatus post(Home home, IntView x0, IntView x1, IntView x2, int w, int h)
Post propagator .
Definition: pair.hpp:47
int size(void) const
Return size of array (number of elements)
Definition: array.hpp:1662
Exception: Too few arguments available in argument array
Definition: exception.hpp:70
Exception: Unknown operation passed as argument
Definition: exception.hpp:98
SetOpType
Common operations for sets.
Definition: set.hh:661
Propagator for element with disjointness
Definition: element.hh:186
Propagator for element with union of constant sets
Definition: element.hh:152
Difference.
Definition: set.hh:665
Gecode::IntArgs i(4, 1, 2, 3, 4)
Exception: Illegal operation passed as argument
Definition: exception.hpp:105
Intersection
Definition: set.hh:664
Integer sets.
Definition: int.hh:171
void element(Home home, IntSharedArray c, IntVar x0, IntVar x1, IntConLevel)
Post domain consistent propagator for .
Definition: element.cpp:43
Passing integer variables.
Definition: int.hh:636
Passing integer arguments.
Definition: int.hh:607
Singleton set view.
Definition: view.hpp:589
Propagator for element with intersection
Definition: element.hh:79
Set view for set variables
Definition: view.hpp:60
Union.
Definition: set.hh:662
Passing set variables.
Definition: set.hh:490
Integer view for integer variables.
Definition: view.hpp:129
Constant view.
Definition: view.hpp:190
Node * x
Pointer to corresponding Boolean expression node.
Definition: bool-expr.cpp:253
Set variables
Definition: set.hh:129
Propagator for element with union
Definition: element.hh:117
Disjoint union.
Definition: set.hh:663
Integer variables.
Definition: int.hh:350
Execution is okay.
Definition: core.hpp:527
Finite integer sets.
Definition: var-imp.hpp:115
Gecode toplevel namespace
Home class for posting propagators
Definition: core.hpp:717
Exception: Arguments are of different size
Definition: exception.hpp:77
#define GECODE_ES_FAIL(es)
Check whether execution status es is failed, and fail space home.
Definition: macros.hpp:96
Class to map VarArg type to view.
Definition: idx-view.hh:64
struct Gecode::@518::NNF::@57::@59 a
For atomic nodes.