Generated on Sat Oct 20 2018 12:43:45 for Gecode by doxygen 1.8.13
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 
38 namespace 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);
119  (Element::ElementIntersection<SingletonView,SetView,
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) {
134  GECODE_POST;
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
186  element(Home home, const SetVarArgs& x, IntVar y, SetVar z) {
187  if (x.size() == 0)
188  throw Set::TooFewArguments("Set::element");
189  GECODE_POST;
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
201  element(Home home, const IntSetArgs& x, IntVar y, SetVar z) {
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");
206  GECODE_POST;
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");
233  GECODE_POST;
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");
244  GECODE_POST;
245  element(home, a, pair(home,x,w,y,h), z);
246  }
247 
248 }
249 
250 // STATISTICS: set-post
251 
Post propagator for SetVar SetOpType op
Definition: set.hh:767
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
int size(void) const
Return size of array (number of elements)
Definition: array.hpp:1569
static ExecStatus post(Home home, IntView x0, IntView x1, IntView x2, int w, int h)
Post propagator .
Definition: pair.hpp:43
Exception: Too few arguments available in argument array
Definition: exception.hpp:66
Exception: Unknown operation passed as argument
Definition: exception.hpp:94
SetOpType
Common operations for sets.
Definition: set.hh:660
Propagator for element with disjointness
Definition: element.hh:194
Propagator for element with union of constant sets
Definition: element.hh:157
Difference.
Definition: set.hh:664
Gecode::IntArgs i({1, 2, 3, 4})
Exception: Illegal operation passed as argument
Definition: exception.hpp:101
Intersection
Definition: set.hh:663
Integer sets.
Definition: int.hh:174
Post propagator for SetVar SetOpType SetVar SetRelType SetVar z
Definition: set.hh:767
Passing integer variables.
Definition: int.hh:656
Passing integer arguments.
Definition: int.hh:628
Singleton set view.
Definition: view.hpp:594
Propagator for element with intersection
Definition: element.hh:78
Set view for set variables
Definition: view.hpp:56
Union.
Definition: set.hh:661
Passing set variables.
Definition: set.hh:488
Integer view for integer variables.
Definition: view.hpp:129
Post propagator for SetVar SetOpType SetVar y
Definition: set.hh:767
Constant view.
Definition: view.hpp:186
Set variables
Definition: set.hh:127
Propagator for element with union
Definition: element.hh:119
Disjoint union.
Definition: set.hh:662
Integer variables.
Definition: int.hh:371
Post propagator for SetVar x
Definition: set.hh:767
Execution is okay.
Definition: core.hpp:475
Finite integer sets.
Definition: var-imp.hpp:137
void fail(void)
Mark space as failed.
Definition: core.hpp:3966
Gecode toplevel namespace
#define GECODE_POST
Check for failure in a constraint post function.
Definition: macros.hpp:40
Home class for posting propagators
Definition: core.hpp:853
Exception: Arguments are of different size
Definition: exception.hpp:73
#define GECODE_ES_FAIL(es)
Check whether execution status es is failed, and fail space home.
Definition: macros.hpp:103
Class to map VarArg type to view.
Definition: idx-view.hh:60
struct Gecode::@593::NNF::@62::@64 a
For atomic nodes.
void element(Home home, IntSharedArray c, IntVar x0, IntVar x1, IntPropLevel)
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