40#ifdef GECODE_HAS_SET_VARS
46#ifdef GECODE_HAS_SET_VARS
50 rel(s, s.arg2SetVar(ce[0]), op, s.arg2SetVar(ce[1]),
51 SRT_EQ, s.arg2SetVar(ce[2]));
64 SetVar x = s.arg2SetVar(ce[0]);
65 SetVar y = s.arg2SetVar(ce[1]);
67 SetVarLubRanges xub(x);
72 SetVarLubRanges yub(y);
82 SetVarArgs xs = s.arg2setvarargs(ce[0]);
83 rel(s, op, xs, s.arg2SetVar(ce[1]));
94 rel(s, s.arg2SetVar(ce[0]), srt, s.arg2SetVar(ce[1]));
116 if (!ce[1]->isIntVar()) {
117 cardinality(s, s.arg2SetVar(ce[0]), ce[1]->getInt(),
120 cardinality(s, s.arg2SetVar(ce[0]), s.arg2IntVar(ce[1]));
124 if (!ce[1]->isSetVar()) {
125 IntSet
d = s.arg2intset(ce[1]);
126 if (ce[0]->isBoolVar()) {
128 Iter::Ranges::Singleton sr(0,1);
129 Iter::Ranges::Inter<IntSetRanges,Iter::Ranges::Singleton>
i(dr,sr);
131 if (d01.size() == 0) {
134 rel(s, s.arg2BoolVar(ce[0]),
IRT_GQ, d01.min());
135 rel(s, s.arg2BoolVar(ce[0]),
IRT_LQ, d01.max());
138 dom(s, s.arg2IntVar(ce[0]), d);
141 if (!ce[0]->isIntVar()) {
142 dom(s, s.arg2SetVar(ce[1]),
SRT_SUP, ce[0]->getInt());
144 rel(s, s.arg2SetVar(ce[1]),
SRT_SUP, s.arg2IntVar(ce[0]));
149 rel(s, s.arg2SetVar(ce[0]), srt, s.arg2SetVar(ce[1]),
150 s.arg2BoolVar(ce[2]));
154 p_set_rel_reif(s,
SRT_EQ,ce);
157 p_set_rel_reif(s,
SRT_LQ,ce);
160 p_set_rel_reif(s,
SRT_LE,ce);
163 p_set_rel_reif(s,
SRT_NQ,ce);
174 if (!ce[1]->isSetVar()) {
182 if (!ce[0]->isIntVar()) {
183 dom(s, s.arg2SetVar(ce[1]),
SRT_SUP, ce[0]->getInt(),
184 Reify(s.arg2BoolVar(ce[2]),rm));
186 rel(s, s.arg2SetVar(ce[1]),
SRT_SUP, s.arg2IntVar(ce[0]),
187 Reify(s.arg2BoolVar(ce[2]),rm));
192 p_set_in_reif(s,ce,ann,
RM_EQV);
195 p_set_in_reif(s,ce,ann,
RM_IMP);
198 rel(s, s.arg2SetVar(ce[0]),
SRT_DISJ, s.arg2SetVar(ce[1]));
203 SetVar x = s.arg2SetVar(ce[0]);
204 int idx = ce[2]->getInt();
207 BoolVarArgs y = s.arg2boolvarargs(ce[1],idx);
214 bool isConstant =
true;
216 for (
int i=
a->a.
size(); i--;) {
217 if (
a->a[i]->isSetVar()) {
222 IntVar selector = s.arg2IntVar(ce[0]);
223 rel(s, selector > 0);
226 element(s, sv, selector, s.arg2SetVar(ce[2]));
228 SetVarArgs sv = s.arg2setvarargs(ce[1], 1);
229 element(s, sv, selector, s.arg2SetVar(ce[2]));
235 const IntSet& universe =
237 bool isConstant =
true;
239 for (
int i=
a->a.
size(); i--;) {
240 if (
a->a[i]->isSetVar()) {
245 SetVar selector = s.arg2SetVar(ce[0]);
249 element(s, op, sv, selector, s.arg2SetVar(ce[2]), universe);
251 SetVarArgs sv = s.arg2setvarargs(ce[1], 1);
252 element(s, op, sv, selector, s.arg2SetVar(ce[2]), universe);
258 p_array_set_element_op(s, ce, ann,
SOT_UNION);
263 p_array_set_element_op(s, ce, ann,
SOT_INTER);
269 IntSet
d = s.arg2intset(ce[3]);
270 p_array_set_element_op(s, ce, ann,
SOT_INTER, d);
275 p_array_set_element_op(s, ce, ann,
SOT_DUNION);
279 convex(s, s.arg2SetVar(ce[0]));
283 SetVarArgs sv = s.arg2setvarargs(ce[0]);
290 SetVarArgs sv = s.arg2setvarargs(ce[0]);
291 sequence(s, sv, s.arg2SetVar(ce[1]));
296 int xoff=ce[1]->getInt();
298 int yoff=ce[3]->getInt();
300 IntVarArgs xv = s.arg2intvarargs(ce[0], xoff);
301 SetVarArgs yv = s.arg2setvarargs(ce[2], yoff, 1, IntSet(0, xoff-1));
302 IntSet xd(yoff,yv.size()-1);
303 for (
int i=xoff;
i<xv.
size();
i++) {
306 IntSet yd(xoff,xv.size()-1);
307 for (
int i=yoff;
i<yv.
size();
i++) {
314 int xoff=ce[1]->getInt();
316 IntVarArgs xv = s.arg2intvarargs(ce[0],xoff);
321 IntArgs e = s.arg2intargs(ce[0]);
322 IntArgs w = s.arg2intargs(ce[1]);
323 SetVar x = s.arg2SetVar(ce[2]);
324 IntVar y = s.arg2IntVar(ce[3]);
329 int xoff = ce[2]->getInt();
330 int yoff = ce[3]->getInt();
331 SetVarArgs x = s.arg2setvarargs(ce[0],xoff);
332 SetVarArgs y = s.arg2setvarargs(ce[1],yoff);
337 SetVarArgs x = s.arg2setvarargs(ce[0]);
338 int p_s = ce[1]->getInt();
339 int p_t = ce[2]->getInt();
345 switch (arg->getInt()) {
356 default:
throw FlatZinc::Error(
"Registry",
"invalid set relation");
360 ite(s, s.arg2BoolVar(ce[0]), s.arg2SetVar(ce[1]), s.arg2SetVar(ce[2]),
361 s.arg2SetVar(ce[3]));
364 convex(s, s.arg2SetVar(ce[0]), s.arg2SetVar(ce[1]));
369 throw FlatZinc::Error(
"Registry",
"set cardinality must be nonnegative");
370 SetVarArgs x = s.arg2setvarargs(ce[0]);
374 for (
int i=0;
i<x.
size();
i++)
381 channelSorted(s, s.arg2intvarargs(ce[0]), s.arg2SetVar(ce[1]));
384 rel(s,
SOT_INTER, s.arg2setvarargs(ce[0]), s.arg2SetVar(ce[1]));
387 SetVarArgs x = s.arg2setvarargs(ce[0]);
388 int width = ce[2]->getInt(), height = ce[4]->getInt();
389 if ((width <= 0) || (height <= 0) ||
390 (
static_cast<long long>(width)*height != x.size()))
391 throw FlatZinc::Error(
"Registry",
"invalid set matrix dimensions");
392 element(s, x, s.arg2IntVar(ce[1]), width,
393 s.arg2IntVar(ce[3]), height, s.arg2SetVar(ce[5]));
397 min(s, s.arg2SetVar(ce[0]), s.arg2IntVar(ce[1]));
399 template<ReifyMode mode>
401 min(s, s.arg2SetVar(ce[0]), s.arg2IntVar(ce[1]),
402 Reify(s.arg2BoolVar(ce[2]), mode));
406 max(s, s.arg2SetVar(ce[0]), s.arg2IntVar(ce[1]));
408 template<ReifyMode mode>
410 max(s, s.arg2SetVar(ce[0]), s.arg2IntVar(ce[1]),
411 Reify(s.arg2BoolVar(ce[2]), mode));
417 rel(s, s.arg2SetVar(ce[0]), set_relation(ce[1]), s.arg2SetVar(ce[2]),
418 Reify(s.arg2BoolVar(ce[3]),
RM_IMP));
426 r.add(
"set_eq", &p_set_eq);
427 r.add(
"set_le", &p_set_le);
428 r.add(
"set_lt", &p_set_lt);
429 r.add(
"equal", &p_set_eq);
430 r.add(
"set_ne", &p_set_ne);
431 r.add(
"set_union", &p_set_union);
432 r.add(
"array_set_element", &p_array_set_element);
433 r.add(
"array_var_set_element", &p_array_set_element);
434 r.add(
"set_intersect", &p_set_intersect);
435 r.add(
"set_diff", &p_set_diff);
436 r.add(
"set_symdiff", &p_set_symdiff);
437 r.add(
"set_subset", &p_set_subset);
438 r.add(
"set_superset", &p_set_superset);
439 r.add(
"set_card", &p_set_card);
440 r.add(
"set_in", &p_set_in);
441 r.add(
"set_eq_reif", &p_set_eq_reif);
442 r.add(
"set_le_reif", &p_set_le_reif);
443 r.add(
"set_lt_reif", &p_set_lt_reif);
444 r.add(
"equal_reif", &p_set_eq_reif);
445 r.add(
"set_ne_reif", &p_set_ne_reif);
446 r.add(
"set_subset_reif", &p_set_subset_reif);
447 r.add(
"set_superset_reif", &p_set_superset_reif);
448 r.add(
"set_in_reif", &p_set_in_reif);
449 r.add(
"set_in_imp", &p_set_in_imp);
450 r.add(
"disjoint", &p_set_disjoint);
451 r.add(
"gecode_link_set_to_booleans",
452 &p_link_set_to_booleans);
454 r.add(
"array_set_union", &p_array_set_union);
455 r.add(
"array_set_partition", &p_array_set_partition);
456 r.add(
"set_convex", &p_set_convex);
457 r.add(
"array_set_seq", &p_array_set_seq);
458 r.add(
"array_set_seq_union", &p_array_set_seq_union);
459 r.add(
"gecode_array_set_element_union",
460 &p_array_set_element_union);
461 r.add(
"gecode_array_set_element_intersect",
462 &p_array_set_element_intersect);
463 r.add(
"gecode_array_set_element_intersect_in",
464 &p_array_set_element_intersect_in);
465 r.add(
"gecode_array_set_element_partition",
466 &p_array_set_element_partition);
467 r.add(
"gecode_int_set_channel",
469 r.add(
"gecode_range",
471 r.add(
"gecode_set_weights",
473 r.add(
"gecode_inverse_set", &p_inverse_set);
474 r.add(
"gecode_precede_set", &p_precede_set);
475 r.add(
"gecode_set_rel_imp_fzn", &p_set_rel_imp);
476 r.add(
"gecode_set_ite", &p_set_ite);
477 r.add(
"gecode_set_convex_hull", &p_set_convex_hull);
478 r.add(
"gecode_set_atmost_one", &p_set_atmost_one);
479 r.add(
"gecode_set_channel_sorted", &p_set_channel_sorted);
480 r.add(
"gecode_array_set_intersect", &p_array_set_intersect);
481 r.add(
"gecode_set_element2d", &p_set_element2d);
482 r.add(
"gecode_set_min", &p_set_min);
483 r.add(
"gecode_set_min_reif", &p_set_min_reif<RM_EQV>);
484 r.add(
"gecode_set_min_imp", &p_set_min_reif<RM_IMP>);
485 r.add(
"gecode_set_max", &p_set_max);
486 r.add(
"gecode_set_max_reif", &p_set_max_reif<RM_EQV>);
487 r.add(
"gecode_set_max_imp", &p_set_max_reif<RM_IMP>);
int size(void) const
Return size of array (number of elements).
A node in a FlatZinc abstract syntax tree.
Abstract representation of a constraint.
A space that can be initialized with a FlatZinc model.
Map from constraint identifier to constraint posting functions.
FloatNum size(void) const
Return size of float value (distance between maximum and minimum).
static const IntSet empty
Empty set.
void rel(Home home, FloatVar x0, FloatRelType frt, FloatVar x1)
Post propagator for .
void ite(Home home, BoolVar b, FloatVar x, FloatVar y, FloatVar z)
Post propagator for if-then-else constraint.
void precede(Home home, const IntVarArgs &x, int s, int t, IntPropLevel=IPL_DEF)
Post propagator that s precedes t in x.
ReifyMode
Mode for reification.
@ IRT_GQ
Greater or equal ( ).
@ IRT_LQ
Less or equal ( ).
@ RM_IMP
Implication for reification.
@ RM_EQV
Equivalence for reification (default).
void weights(Home home, IntSharedArray elements, IntSharedArray weights, SetVar x, IntVar y)
Post propagator for .
SetOpType
Common operations for sets.
SetRelType
Common relation types for sets.
@ SOT_DUNION
Disjoint union.
@ SRT_GQ
Greater or equal ( ).
@ SRT_LQ
Less or equal ( ).
void post_int_in_imp(FlatZincSpace &s, const ConExpr &ce, AST::Node *ann)
void register_set(Registry &r)
void post_int_in_reif(FlatZincSpace &s, const ConExpr &ce, AST::Node *ann)
Interpreter for the FlatZinc language.
const int min
Smallest allowed integer in integer set.
const int max
Largest allowed integer in integer set.
Gecode toplevel namespace
ArgArray< IntSet > IntSetArgs
Passing set arguments.
void atmostOne(Home home, const SetVarArgs &x, unsigned int c)
Post propagator for and .
void channel(Home home, FloatVar x0, IntVar x1)
Post propagator for channeling a float and an integer variable .
void sequence(Home home, const IntVarArgs &x, const IntSet &s, int q, int l, int u, IntPropLevel ipl=IPL_DEF)
Post propagator for .
void channelSorted(Home home, const IntVarArgs &x, SetVar y)
Post propagator for and .
void min(Home home, FloatVar x0, FloatVar x1, FloatVar x2)
Post propagator for .
void dom(Home home, FloatVar x, FloatVal n)
Propagates .
void element(Home home, IntSharedArray n, IntVar x0, IntVar x1, IntPropLevel ipl=IPL_DEF)
Post domain consistent propagator for .
void convex(Home home, SetVar x)
Post propagator that propagates that x is convex.
void unshare(Home home, IntVarArgs &x, IntPropLevel ipl=IPL_DEF)
Replace multiple variable occurrences in x by fresh variables.
void max(Home home, FloatVar x0, FloatVar x1, FloatVar x2)
Post propagator for .
LinIntExpr cardinality(const SetExpr &)
Cardinality of set expression.
Gecode::FloatVal a(-8, 5)
Gecode::IntArgs i({1, 2, 3, 4})