this repo has no description
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 * Contributing authors:
8 * Gabor Szokoli <szokoli@gecode.org>
9 *
10 * Copyright:
11 * Guido Tack, 2004
12 * Christian Schulte, 2004
13 * Gabor Szokoli, 2004
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#ifndef GECODE_SET_RELOP_HH
41#define GECODE_SET_RELOP_HH
42
43#include <gecode/set.hh>
44#include <gecode/set/rel.hh>
45
46namespace Gecode { namespace Set { namespace RelOp {
47
48 /**
49 * \namespace Gecode::Set::RelOp
50 * \brief Standard set operation propagators
51 */
52
53 /**
54 * \brief %Propagator for the superset of intersection
55 *
56 * Requires \code #include <gecode/set/rel-op.hh> \endcode
57 * \ingroup FuncSetProp
58 */
59
60 template<class View0, class View1, class View2>
61 class SuperOfInter :
62 public MixTernaryPropagator<View0,PC_SET_ANY,View1,PC_SET_ANY,
63 View2,PC_SET_CLUB> {
64 protected:
65 using MixTernaryPropagator<View0,PC_SET_ANY,View1,PC_SET_ANY,
66 View2,PC_SET_CLUB>::x0;
67 using MixTernaryPropagator<View0,PC_SET_ANY,View1,PC_SET_ANY,
68 View2,PC_SET_CLUB>::x1;
69 using MixTernaryPropagator<View0,PC_SET_ANY,View1,PC_SET_ANY,
70 View2,PC_SET_CLUB>::x2;
71 /// Constructor for cloning \a p
72 SuperOfInter(Space& home, SuperOfInter& p);
73 /// Constructor for posting
74 SuperOfInter(Home home, View0, View1, View2);
75 public:
76 /// Copy propagator during cloning
77 virtual Actor* copy(Space& home);
78 /// Perform propagation
79 virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
80 /// Post propagator \f$ z \supseteq x \cap y\f$
81 static ExecStatus post(Home home, View0 x, View1 y, View2 z);
82 };
83
84 /**
85 * \brief %Propagator for the subset of union
86 *
87 * Requires \code #include <gecode/set/rel-op.hh> \endcode
88 * \ingroup FuncSetProp
89 */
90 template<class View0, class View1, class View2>
91 class SubOfUnion :
92 public MixTernaryPropagator<View0,PC_SET_ANY,View1,PC_SET_ANY,
93 View2,PC_SET_ANY> {
94 protected:
95 using MixTernaryPropagator<View0,PC_SET_ANY,View1,PC_SET_ANY,
96 View2,PC_SET_ANY>::x0;
97 using MixTernaryPropagator<View0,PC_SET_ANY,View1,PC_SET_ANY,
98 View2,PC_SET_ANY>::x1;
99 using MixTernaryPropagator<View0,PC_SET_ANY,View1,PC_SET_ANY,
100 View2,PC_SET_ANY>::x2;
101 /// Constructor for cloning \a p
102 SubOfUnion(Space& home, SubOfUnion& p);
103 /// Constructor for posting
104 SubOfUnion(Home home, View0, View1, View2);
105 public:
106 /// Copy propagator during cloning
107 virtual Actor* copy(Space& home);
108 /// Perform propagation
109 virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
110 /// Post propagator \f$ z \subseteq x \cap y\f$
111 static ExecStatus post(Home home,View0 x,View1 y,View2 z);
112 };
113
114
115 /**
116 * \brief %Propagator for ternary intersection
117 *
118 * Requires \code #include <gecode/set/rel-op.hh> \endcode
119 * \ingroup FuncSetProp
120 */
121 template<class View0, class View1, class View2>
122 class Intersection:
123 public MixTernaryPropagator<View0,PC_SET_ANY,View1,PC_SET_ANY,
124 View2,PC_SET_ANY> {
125 protected:
126 using MixTernaryPropagator<View0,PC_SET_ANY,View1,PC_SET_ANY,
127 View2,PC_SET_ANY>::x0;
128 using MixTernaryPropagator<View0,PC_SET_ANY,View1,PC_SET_ANY,
129 View2,PC_SET_ANY>::x1;
130 using MixTernaryPropagator<View0,PC_SET_ANY,View1,PC_SET_ANY,
131 View2,PC_SET_ANY>::x2;
132 /// Constructor for cloning \a p
133 Intersection(Space& home, Intersection& p);
134 /// Constructor for posting
135 Intersection(Home home,View0,View1,View2);
136 public:
137 /// Copy propagator during cloning
138 virtual Actor* copy(Space& home);
139 /// Perform propagation
140 virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
141 /// Post propagator \f$ z=x\cap y\f$
142 static ExecStatus post(Home home,View0 x,View1 y,View2 z);
143 };
144
145 /**
146 * \brief %Propagator for ternary union
147 *
148 * Requires \code #include <gecode/set/rel-op.hh> \endcode
149 * \ingroup FuncSetProp
150 */
151 template<class View0, class View1, class View2>
152 class Union:
153 public MixTernaryPropagator<View0,PC_SET_ANY,View1,PC_SET_ANY,
154 View2,PC_SET_ANY> {
155 protected:
156 using MixTernaryPropagator<View0,PC_SET_ANY,View1,PC_SET_ANY,
157 View2,PC_SET_ANY>::x0;
158 using MixTernaryPropagator<View0,PC_SET_ANY,View1,PC_SET_ANY,
159 View2,PC_SET_ANY>::x1;
160 using MixTernaryPropagator<View0,PC_SET_ANY,View1,PC_SET_ANY,
161 View2,PC_SET_ANY>::x2;
162 /// Constructor for cloning \a p
163 Union(Space& home, Union& p);
164 /// Constructor for posting
165 Union(Home home, View0, View1, View2);
166 public:
167 /// Copy propagator during cloning
168 virtual Actor* copy(Space& home);
169 /// Perform propagation
170 virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
171 /// Post propagator \f$ z=x\cup y\f$
172 static ExecStatus post(Home home,View0 x,View1 y,View2 z);
173 };
174
175 /**
176 * \brief %Propagator for nary intersection
177 *
178 * Requires \code #include <gecode/set/rel-op.hh> \endcode
179 * \ingroup FuncSetProp
180 */
181 template<class View0, class View1>
182 class IntersectionN :
183 public MixNaryOnePropagator<View0,PC_SET_ANY,View1,PC_SET_ANY> {
184 protected:
185 using MixNaryOnePropagator<View0,PC_SET_ANY,View1,PC_SET_ANY>::x;
186 using MixNaryOnePropagator<View0,PC_SET_ANY,View1,PC_SET_ANY>::y;
187 /// Whether the any views share a variable implementation
188 bool shared;
189 /// Intersection of the determined \f$x_i\f$ (which are dropped)
190 LUBndSet intOfDets;
191 /// Constructor for cloning \a p
192 IntersectionN(Space& home, IntersectionN& p);
193 /// Constructor for posting
194 IntersectionN(Home home, ViewArray<View0>&, View1);
195 /// Constructor for posting
196 IntersectionN(Home home, ViewArray<View0>&, const IntSet&, View1);
197 public:
198 /// Cost function
199 virtual PropCost cost(const Space& home, const ModEventDelta& med) const;
200 /// Copy propagator during cloning
201 virtual Actor* copy(Space& home);
202 /// Perform propagation
203 virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
204 /// Post propagator \f$ x = \bigcap_{i\in\{0,\dots,n-1\}} y_i \f$
205 static ExecStatus post(Home home,ViewArray<View0>& y,View1 x);
206 /// Post propagator \f$ x = z\cap\bigcap_{i\in\{0,\dots,n-1\}} y_i \f$
207 static ExecStatus post(Home home,ViewArray<View0>& y,
208 const IntSet& z,View1 x);
209 };
210
211 /**
212 * \brief %Propagator for nary union
213 *
214 * Requires \code #include <gecode/set/rel-op.hh> \endcode
215 * \ingroup FuncSetProp
216 */
217 template<class View0, class View1>
218 class UnionN : public MixNaryOnePropagator<View0,PC_SET_ANY,
219 View1,PC_SET_ANY> {
220 protected:
221 using MixNaryOnePropagator<View0,PC_SET_ANY,View1,PC_SET_ANY>::x;
222 using MixNaryOnePropagator<View0,PC_SET_ANY,View1,PC_SET_ANY>::y;
223 /// Whether the any views share a variable implementation
224 bool shared;
225 /// Union of the determined \f$x_i\f$ (which are dropped)
226 GLBndSet unionOfDets;
227 /// Constructor for cloning \a p
228 UnionN(Space& home, UnionN& p);
229 /// Constructor for posting
230 UnionN(Home home,ViewArray<View0>&,View1);
231 /// Constructor for posting
232 UnionN(Home home,ViewArray<View0>&,const IntSet&,View1);
233 public:
234 /// Copy propagator during cloning
235 virtual Actor* copy(Space& home);
236 /// Perform propagation
237 virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
238 /// Cost function
239 virtual PropCost cost(const Space& home, const ModEventDelta& med) const;
240 /// Post propagator \f$ x = \bigcup_{i\in\{0,\dots,n-1\}} y_i \f$
241 static ExecStatus post(Home home,ViewArray<View0>& y,View1 x);
242 /// Post propagator \f$ x = z\cup\bigcup_{i\in\{0,\dots,n-1\}} y_i \f$
243 static ExecStatus post(Home home,ViewArray<View0>& y,
244 const IntSet& z,View1 x);
245 };
246
247
248 /**
249 * \brief %Propagator for nary partition
250 *
251 * Requires \code #include <gecode/set/rel-op.hh> \endcode
252 * \ingroup FuncSetProp
253 */
254 template<class View0, class View1>
255 class PartitionN : public MixNaryOnePropagator<View0,PC_SET_ANY,
256 View1,PC_SET_ANY> {
257 protected:
258 using MixNaryOnePropagator<View0,PC_SET_ANY,View1,PC_SET_ANY>::x;
259 using MixNaryOnePropagator<View0,PC_SET_ANY,View1,PC_SET_ANY>::y;
260 /// Whether the any views share a variable implementation
261 bool shared;
262 /// Union of the determined \f$x_i\f$ (which are dropped)
263 GLBndSet unionOfDets;
264 /// Constructor for cloning \a p
265 PartitionN(Space& home, PartitionN& p);
266 /// Constructor for posting
267 PartitionN(Home home, ViewArray<View0>&, View1);
268 /// Constructor for posting
269 PartitionN(Home home, ViewArray<View0>&, const IntSet&, View1);
270 public:
271 /// Copy propagator during cloning
272 virtual Actor* copy(Space& home);
273 /// Perform propagation
274 virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
275 /// Cost function
276 virtual PropCost cost(const Space& home, const ModEventDelta& med) const;
277 /// Post propagator \f$ x = \biguplus_{i\in\{0,\dots,n-1\}} y_i \f$
278 static ExecStatus post(Home home,ViewArray<View0>& y,View1 x);
279 /// Post propagator \f$ x = z\uplus\biguplus_{i\in\{0,\dots,n-1\}} y_i \f$
280 static ExecStatus post(Home home,ViewArray<View0>& y,
281 const IntSet& z,View1 x);
282 };
283
284}}}
285
286#include <gecode/set/rel-op/common.hpp>
287#include <gecode/set/rel-op/superofinter.hpp>
288#include <gecode/set/rel-op/subofunion.hpp>
289#include <gecode/set/rel-op/inter.hpp>
290#include <gecode/set/rel-op/union.hpp>
291#include <gecode/set/rel-op/partition.hpp>
292#include <gecode/set/rel-op/post.hpp>
293
294#endif
295
296// STATISTICS: set-prop