46 #ifdef GECODE_HAS_SET_VARS
51 namespace Gecode {
namespace FlatZinc {
60 std::map<std::string,poster>::iterator
i = r.find(ce.
id);
63 std::string(
"Constraint ")+ce.
id+
" not found");
65 i->second(s, ce, ann);
116 inline IntArgs arg2intargs(AST::Node* arg,
int offset = 0) {
117 AST::Array*
a = arg->getArray();
118 IntArgs ia(a->a.size()+offset);
119 for (
int i=offset;
i--;)
121 for (
int i=a->
a.size();
i--;)
122 ia[
i+offset] = a->a[
i]->getInt();
126 inline IntArgs arg2boolargs(AST::Node* arg,
int offset = 0) {
127 AST::Array* a = arg->getArray();
128 IntArgs ia(a->a.size()+offset);
129 for (
int i=offset;
i--;)
131 for (
int i=a->
a.size();
i--;)
132 ia[
i+offset] = a->a[
i]->getBool();
136 inline IntSet arg2intset(FlatZincSpace& s, AST::Node* n) {
137 AST::SetLit* sl = n->getSet();
140 d = IntSet(sl->min, sl->max);
143 int* is = re.alloc<
int>(
static_cast<unsigned long int>(sl->s.size()));
144 for (
int i=sl->s.
size();
i--; )
146 d = IntSet(is, sl->s.size());
151 inline IntSetArgs arg2intsetargs(FlatZincSpace& s,
152 AST::Node* arg,
int offset = 0) {
153 AST::Array* a = arg->getArray();
154 if (a->a.size() == 0) {
159 for (
int i=offset;
i--;)
161 for (
int i=a->
a.size();
i--;) {
162 ia[
i+offset] = arg2intset(s, a->a[
i]);
167 inline IntVarArgs arg2intvarargs(FlatZincSpace& s, AST::Node* arg,
169 AST::Array* a = arg->getArray();
170 if (a->a.size() == 0) {
171 IntVarArgs emptyIa(0);
174 IntVarArgs ia(a->a.size()+offset);
175 for (
int i=offset;
i--;)
176 ia[
i] = IntVar(s, 0, 0);
177 for (
int i=a->
a.size();
i--;) {
178 if (a->a[
i]->isIntVar()) {
179 ia[
i+offset] = s.iv[a->a[
i]->getIntVar()];
181 int value = a->a[
i]->getInt();
182 IntVar iv(s, value, value);
189 inline BoolVarArgs arg2boolvarargs(FlatZincSpace& s, AST::Node* arg,
190 int offset = 0,
int siv=-1) {
191 AST::Array* a = arg->getArray();
192 if (a->a.size() == 0) {
193 BoolVarArgs emptyIa(0);
196 BoolVarArgs ia(a->a.size()+offset-(siv==-1?0:1));
197 for (
int i=offset;
i--;)
198 ia[
i] = BoolVar(s, 0, 0);
199 for (
int i=0; i<static_cast<int>(a->a.size());
i++) {
202 if (a->a[
i]->isBool()) {
203 bool value = a->a[
i]->getBool();
204 BoolVar iv(s, value, value);
206 }
else if (a->a[
i]->isIntVar() &&
207 s.aliasBool2Int(a->a[
i]->getIntVar()) != -1) {
208 ia[offset++] = s.bv[s.aliasBool2Int(a->a[
i]->getIntVar())];
210 ia[offset++] = s.bv[a->a[
i]->getBoolVar()];
216 #ifdef GECODE_HAS_SET_VARS
217 SetVar getSetVar(FlatZincSpace& s, AST::Node* n) {
219 if (!n->isSetVar()) {
220 IntSet d = arg2intset(s,n);
221 x0 = SetVar(s, d, d);
223 x0 = s.sv[n->getSetVar()];
228 inline SetVarArgs arg2setvarargs(FlatZincSpace& s, AST::Node* arg,
229 int offset = 0,
int doffset = 0,
231 AST::Array* a = arg->getArray();
232 SetVarArgs ia(a->a.size()+offset);
233 for (
int i=offset;
i--;) {
235 ia[
i] = SetVar(s, d, d);
237 for (
int i=a->
a.size();
i--;) {
238 ia[
i+offset] = getSetVar(s, a->a[
i]);
244 BoolVar getBoolVar(FlatZincSpace& s, AST::Node* n) {
247 x0 = BoolVar(s, n->getBool(), n->getBool());
250 x0 = s.bv[n->getBoolVar()];
255 IntVar getIntVar(FlatZincSpace& s, AST::Node* n) {
258 x0 = s.iv[n->getIntVar()];
260 x0 = IntVar(s, n->getInt(), n->getInt());
265 bool isBoolArray(FlatZincSpace& s, AST::Node*
b,
int& singleInt) {
266 AST::Array* a = b->getArray();
268 if (a->a.size() == 0)
270 for (
int i=a->
a.size();
i--;) {
271 if (a->a[
i]->isBoolVar() || a->a[
i]->isBool()) {
272 }
else if (a->a[
i]->isIntVar()) {
273 if (s.aliasBool2Int(a->a[
i]->getIntVar()) == -1) {
274 if (singleInt != -1) {
283 return singleInt==-1 || a->
a.size() > 1;
286 void p_distinct(FlatZincSpace& s,
const ConExpr& ce, AST::Node* ann) {
287 IntVarArgs
va = arg2intvarargs(s, ce[0]);
291 void p_distinctOffset(FlatZincSpace& s,
const ConExpr& ce, AST::Node* ann) {
292 IntVarArgs
va = arg2intvarargs(s, ce[1]);
293 AST::Array* offs = ce.args->a[0]->getArray();
294 IntArgs oa(offs->a.size());
295 for (
int i=offs->
a.size();
i--; ) {
296 oa[
i] = offs->a[
i]->getInt();
302 void p_all_equal(FlatZincSpace& s,
const ConExpr& ce, AST::Node* ann) {
303 IntVarArgs va = arg2intvarargs(s, ce[0]);
307 void p_int_CMP(FlatZincSpace& s,
IntRelType irt,
const ConExpr& ce,
309 if (ce[0]->isIntVar()) {
310 if (ce[1]->isIntVar()) {
311 rel(s, getIntVar(s, ce[0]), irt, getIntVar(s, ce[1]),
314 rel(s, getIntVar(s, ce[0]), irt, ce[1]->getInt(), ann2icl(ann));
317 rel(s, getIntVar(s, ce[1]), swap(irt), ce[0]->getInt(),
321 void p_int_eq(FlatZincSpace& s,
const ConExpr& ce, AST::Node* ann) {
322 p_int_CMP(s,
IRT_EQ, ce, ann);
324 void p_int_ne(FlatZincSpace& s,
const ConExpr& ce, AST::Node* ann) {
325 p_int_CMP(s,
IRT_NQ, ce, ann);
327 void p_int_ge(FlatZincSpace& s,
const ConExpr& ce, AST::Node* ann) {
328 p_int_CMP(s,
IRT_GQ, ce, ann);
330 void p_int_gt(FlatZincSpace& s,
const ConExpr& ce, AST::Node* ann) {
331 p_int_CMP(s,
IRT_GR, ce, ann);
333 void p_int_le(FlatZincSpace& s,
const ConExpr& ce, AST::Node* ann) {
334 p_int_CMP(s,
IRT_LQ, ce, ann);
336 void p_int_lt(FlatZincSpace& s,
const ConExpr& ce, AST::Node* ann) {
337 p_int_CMP(s,
IRT_LE, ce, ann);
339 void p_int_CMP_reif(FlatZincSpace& s,
IntRelType irt,
const ConExpr& ce,
341 if (ce[2]->isBool()) {
342 if (ce[2]->getBool()) {
343 p_int_CMP(s, irt, ce, ann);
345 p_int_CMP(s,
neg(irt), ce, ann);
349 if (ce[0]->isIntVar()) {
350 if (ce[1]->isIntVar()) {
351 rel(s, getIntVar(s, ce[0]), irt, getIntVar(s, ce[1]),
352 getBoolVar(s, ce[2]), ann2icl(ann));
354 rel(s, getIntVar(s, ce[0]), irt, ce[1]->getInt(),
355 getBoolVar(s, ce[2]), ann2icl(ann));
358 rel(s, getIntVar(s, ce[1]), swap(irt), ce[0]->getInt(),
359 getBoolVar(s, ce[2]), ann2icl(ann));
364 void p_int_eq_reif(FlatZincSpace& s,
const ConExpr& ce, AST::Node* ann) {
365 p_int_CMP_reif(s,
IRT_EQ, ce, ann);
367 void p_int_ne_reif(FlatZincSpace& s,
const ConExpr& ce, AST::Node* ann) {
368 p_int_CMP_reif(s,
IRT_NQ, ce, ann);
370 void p_int_ge_reif(FlatZincSpace& s,
const ConExpr& ce, AST::Node* ann) {
371 p_int_CMP_reif(s,
IRT_GQ, ce, ann);
373 void p_int_gt_reif(FlatZincSpace& s,
const ConExpr& ce, AST::Node* ann) {
374 p_int_CMP_reif(s,
IRT_GR, ce, ann);
376 void p_int_le_reif(FlatZincSpace& s,
const ConExpr& ce, AST::Node* ann) {
377 p_int_CMP_reif(s,
IRT_LQ, ce, ann);
379 void p_int_lt_reif(FlatZincSpace& s,
const ConExpr& ce, AST::Node* ann) {
380 p_int_CMP_reif(s,
IRT_LE, ce, ann);
384 void p_int_lin_CMP(FlatZincSpace& s,
IntRelType irt,
const ConExpr& ce,
386 IntArgs ia = arg2intargs(ce[0]);
388 if (isBoolArray(s,ce[1],singleIntVar)) {
389 if (singleIntVar != -1) {
390 if (
std::abs(ia[singleIntVar]) == 1 && ce[2]->getInt() == 0) {
391 IntVar siv = getIntVar(s, ce[1]->getArray()->a[singleIntVar]);
392 BoolVarArgs iv = arg2boolvarargs(s, ce[1], 0, singleIntVar);
393 IntArgs ia_tmp(ia.size()-1);
395 for (
int i=0;
i<ia.
size();
i++) {
396 if (
i != singleIntVar)
397 ia_tmp[count++] = ia[singleIntVar] == -1 ? ia[
i] : -ia[
i];
399 IntRelType t = (ia[singleIntVar] == -1 ? irt : swap(irt));
400 linear(s, ia_tmp, iv, t, siv, ann2icl(ann));
402 IntVarArgs iv = arg2intvarargs(s, ce[1]);
403 linear(s, ia, iv, irt, ce[2]->getInt(), ann2icl(ann));
406 BoolVarArgs iv = arg2boolvarargs(s, ce[1]);
407 linear(s, ia, iv, irt, ce[2]->getInt(), ann2icl(ann));
410 IntVarArgs iv = arg2intvarargs(s, ce[1]);
411 linear(s, ia, iv, irt, ce[2]->getInt(), ann2icl(ann));
414 void p_int_lin_CMP_reif(FlatZincSpace& s,
IntRelType irt,
415 const ConExpr& ce, AST::Node* ann) {
416 if (ce[2]->isBool()) {
417 if (ce[2]->getBool()) {
418 p_int_lin_CMP(s, irt, ce, ann);
420 p_int_lin_CMP(s,
neg(irt), ce, ann);
424 IntArgs ia = arg2intargs(ce[0]);
426 if (isBoolArray(s,ce[1],singleIntVar)) {
427 if (singleIntVar != -1) {
428 if (
std::abs(ia[singleIntVar]) == 1 && ce[2]->getInt() == 0) {
429 IntVar siv = getIntVar(s, ce[1]->getArray()->a[singleIntVar]);
430 BoolVarArgs iv = arg2boolvarargs(s, ce[1], 0, singleIntVar);
431 IntArgs ia_tmp(ia.size()-1);
433 for (
int i=0;
i<ia.
size();
i++) {
434 if (
i != singleIntVar)
435 ia_tmp[count++] = ia[singleIntVar] == -1 ? ia[
i] : -ia[
i];
437 IntRelType t = (ia[singleIntVar] == -1 ? irt : swap(irt));
438 linear(s, ia_tmp, iv, t, siv, getBoolVar(s, ce[3]),
441 IntVarArgs iv = arg2intvarargs(s, ce[1]);
442 linear(s, ia, iv, irt, ce[2]->getInt(),
443 getBoolVar(s, ce[3]), ann2icl(ann));
446 BoolVarArgs iv = arg2boolvarargs(s, ce[1]);
447 linear(s, ia, iv, irt, ce[2]->getInt(),
448 getBoolVar(s, ce[3]), ann2icl(ann));
451 IntVarArgs iv = arg2intvarargs(s, ce[1]);
452 linear(s, ia, iv, irt, ce[2]->getInt(), getBoolVar(s, ce[3]),
456 void p_int_lin_eq(FlatZincSpace& s,
const ConExpr& ce, AST::Node* ann) {
457 p_int_lin_CMP(s,
IRT_EQ, ce, ann);
459 void p_int_lin_eq_reif(FlatZincSpace& s,
const ConExpr& ce, AST::Node* ann) {
460 p_int_lin_CMP_reif(s,
IRT_EQ, ce, ann);
462 void p_int_lin_ne(FlatZincSpace& s,
const ConExpr& ce, AST::Node* ann) {
463 p_int_lin_CMP(s,
IRT_NQ, ce, ann);
465 void p_int_lin_ne_reif(FlatZincSpace& s,
const ConExpr& ce, AST::Node* ann) {
466 p_int_lin_CMP_reif(s,
IRT_NQ, ce, ann);
468 void p_int_lin_le(FlatZincSpace& s,
const ConExpr& ce, AST::Node* ann) {
469 p_int_lin_CMP(s,
IRT_LQ, ce, ann);
471 void p_int_lin_le_reif(FlatZincSpace& s,
const ConExpr& ce, AST::Node* ann) {
472 p_int_lin_CMP_reif(s,
IRT_LQ, ce, ann);
474 void p_int_lin_lt(FlatZincSpace& s,
const ConExpr& ce, AST::Node* ann) {
475 p_int_lin_CMP(s,
IRT_LE, ce, ann);
477 void p_int_lin_lt_reif(FlatZincSpace& s,
const ConExpr& ce, AST::Node* ann) {
478 p_int_lin_CMP_reif(s,
IRT_LE, ce, ann);
480 void p_int_lin_ge(FlatZincSpace& s,
const ConExpr& ce, AST::Node* ann) {
481 p_int_lin_CMP(s,
IRT_GQ, ce, ann);
483 void p_int_lin_ge_reif(FlatZincSpace& s,
const ConExpr& ce, AST::Node* ann) {
484 p_int_lin_CMP_reif(s,
IRT_GQ, ce, ann);
486 void p_int_lin_gt(FlatZincSpace& s,
const ConExpr& ce, AST::Node* ann) {
487 p_int_lin_CMP(s,
IRT_GR, ce, ann);
489 void p_int_lin_gt_reif(FlatZincSpace& s,
const ConExpr& ce, AST::Node* ann) {
490 p_int_lin_CMP_reif(s,
IRT_GR, ce, ann);
493 void p_bool_lin_CMP(FlatZincSpace& s,
IntRelType irt,
const ConExpr& ce,
495 IntArgs ia = arg2intargs(ce[0]);
496 BoolVarArgs iv = arg2boolvarargs(s, ce[1]);
497 if (ce[2]->isIntVar())
498 linear(s, ia, iv, irt, s.iv[ce[2]->getIntVar()], ann2icl(ann));
500 linear(s, ia, iv, irt, ce[2]->getInt(), ann2icl(ann));
502 void p_bool_lin_CMP_reif(FlatZincSpace& s,
IntRelType irt,
503 const ConExpr& ce, AST::Node* ann) {
504 if (ce[2]->isBool()) {
505 if (ce[2]->getBool()) {
506 p_bool_lin_CMP(s, irt, ce, ann);
508 p_bool_lin_CMP(s,
neg(irt), ce, ann);
512 IntArgs ia = arg2intargs(ce[0]);
513 BoolVarArgs iv = arg2boolvarargs(s, ce[1]);
514 if (ce[2]->isIntVar())
515 linear(s, ia, iv, irt, s.iv[ce[2]->getIntVar()], getBoolVar(s, ce[3]),
518 linear(s, ia, iv, irt, ce[2]->getInt(), getBoolVar(s, ce[3]),
521 void p_bool_lin_eq(FlatZincSpace& s,
const ConExpr& ce, AST::Node* ann) {
522 p_bool_lin_CMP(s,
IRT_EQ, ce, ann);
524 void p_bool_lin_eq_reif(FlatZincSpace& s,
const ConExpr& ce, AST::Node* ann)
526 p_bool_lin_CMP_reif(s,
IRT_EQ, ce, ann);
528 void p_bool_lin_ne(FlatZincSpace& s,
const ConExpr& ce, AST::Node* ann) {
529 p_bool_lin_CMP(s,
IRT_NQ, ce, ann);
531 void p_bool_lin_ne_reif(FlatZincSpace& s,
const ConExpr& ce, AST::Node* ann)
533 p_bool_lin_CMP_reif(s,
IRT_NQ, ce, ann);
535 void p_bool_lin_le(FlatZincSpace& s,
const ConExpr& ce, AST::Node* ann) {
536 p_bool_lin_CMP(s,
IRT_LQ, ce, ann);
538 void p_bool_lin_le_reif(FlatZincSpace& s,
const ConExpr& ce, AST::Node* ann)
540 p_bool_lin_CMP_reif(s,
IRT_LQ, ce, ann);
542 void p_bool_lin_lt(FlatZincSpace& s,
const ConExpr& ce, AST::Node* ann)
544 p_bool_lin_CMP(s,
IRT_LE, ce, ann);
546 void p_bool_lin_lt_reif(FlatZincSpace& s,
const ConExpr& ce, AST::Node* ann)
548 p_bool_lin_CMP_reif(s,
IRT_LE, ce, ann);
550 void p_bool_lin_ge(FlatZincSpace& s,
const ConExpr& ce, AST::Node* ann) {
551 p_bool_lin_CMP(s,
IRT_GQ, ce, ann);
553 void p_bool_lin_ge_reif(FlatZincSpace& s,
const ConExpr& ce, AST::Node* ann)
555 p_bool_lin_CMP_reif(s,
IRT_GQ, ce, ann);
557 void p_bool_lin_gt(FlatZincSpace& s,
const ConExpr& ce, AST::Node* ann) {
558 p_bool_lin_CMP(s,
IRT_GR, ce, ann);
560 void p_bool_lin_gt_reif(FlatZincSpace& s,
const ConExpr& ce, AST::Node* ann)
562 p_bool_lin_CMP_reif(s,
IRT_GR, ce, ann);
567 void p_int_plus(FlatZincSpace& s,
const ConExpr& ce, AST::Node* ann) {
568 if (!ce[0]->isIntVar()) {
569 rel(s, ce[0]->getInt() + getIntVar(s, ce[1])
570 == getIntVar(s,ce[2]), ann2icl(ann));
571 }
else if (!ce[1]->isIntVar()) {
572 rel(s, getIntVar(s,ce[0]) + ce[1]->getInt()
573 == getIntVar(s,ce[2]), ann2icl(ann));
574 }
else if (!ce[2]->isIntVar()) {
575 rel(s, getIntVar(s,ce[0]) + getIntVar(s,ce[1])
576 == ce[2]->getInt(), ann2icl(ann));
578 rel(s, getIntVar(s,ce[0]) + getIntVar(s,ce[1])
579 == getIntVar(s,ce[2]), ann2icl(ann));
583 void p_int_minus(FlatZincSpace& s,
const ConExpr& ce, AST::Node* ann) {
584 if (!ce[0]->isIntVar()) {
585 rel(s, ce[0]->getInt() - getIntVar(s, ce[1])
586 == getIntVar(s,ce[2]), ann2icl(ann));
587 }
else if (!ce[1]->isIntVar()) {
588 rel(s, getIntVar(s,ce[0]) - ce[1]->getInt()
589 == getIntVar(s,ce[2]), ann2icl(ann));
590 }
else if (!ce[2]->isIntVar()) {
591 rel(s, getIntVar(s,ce[0]) - getIntVar(s,ce[1])
592 == ce[2]->getInt(), ann2icl(ann));
594 rel(s, getIntVar(s,ce[0]) - getIntVar(s,ce[1])
595 == getIntVar(s,ce[2]), ann2icl(ann));
599 void p_int_times(FlatZincSpace& s,
const ConExpr& ce, AST::Node* ann) {
600 IntVar x0 = getIntVar(s, ce[0]);
601 IntVar x1 = getIntVar(s, ce[1]);
602 IntVar x2 = getIntVar(s, ce[2]);
603 mult(s, x0, x1, x2, ann2icl(ann));
605 void p_int_div(FlatZincSpace& s,
const ConExpr& ce, AST::Node* ann) {
606 IntVar x0 = getIntVar(s, ce[0]);
607 IntVar x1 = getIntVar(s, ce[1]);
608 IntVar x2 = getIntVar(s, ce[2]);
609 div(s,x0,x1,x2, ann2icl(ann));
611 void p_int_mod(FlatZincSpace& s,
const ConExpr& ce, AST::Node* ann) {
612 IntVar x0 = getIntVar(s, ce[0]);
613 IntVar x1 = getIntVar(s, ce[1]);
614 IntVar x2 = getIntVar(s, ce[2]);
615 mod(s,x0,x1,x2, ann2icl(ann));
618 void p_int_min(FlatZincSpace& s,
const ConExpr& ce, AST::Node* ann) {
619 IntVar x0 = getIntVar(s, ce[0]);
620 IntVar x1 = getIntVar(s, ce[1]);
621 IntVar x2 = getIntVar(s, ce[2]);
622 min(s, x0, x1, x2, ann2icl(ann));
624 void p_int_max(FlatZincSpace& s,
const ConExpr& ce, AST::Node* ann) {
625 IntVar x0 = getIntVar(s, ce[0]);
626 IntVar x1 = getIntVar(s, ce[1]);
627 IntVar x2 = getIntVar(s, ce[2]);
628 max(s, x0, x1, x2, ann2icl(ann));
630 void p_int_negate(FlatZincSpace& s,
const ConExpr& ce, AST::Node* ann) {
631 IntVar x0 = getIntVar(s, ce[0]);
632 IntVar x1 = getIntVar(s, ce[1]);
633 rel(s, x0 == -x1, ann2icl(ann));
637 void p_bool_CMP(FlatZincSpace& s,
IntRelType irt,
const ConExpr& ce,
639 rel(s, getBoolVar(s, ce[0]), irt, getBoolVar(s, ce[1]),
642 void p_bool_CMP_reif(FlatZincSpace& s,
IntRelType irt,
const ConExpr& ce,
644 rel(s, getBoolVar(s, ce[0]), irt, getBoolVar(s, ce[1]),
645 getBoolVar(s, ce[2]), ann2icl(ann));
647 void p_bool_eq(FlatZincSpace& s,
const ConExpr& ce, AST::Node* ann) {
648 p_bool_CMP(s,
IRT_EQ, ce, ann);
650 void p_bool_eq_reif(FlatZincSpace& s,
const ConExpr& ce, AST::Node* ann) {
651 p_bool_CMP_reif(s,
IRT_EQ, ce, ann);
653 void p_bool_ne(FlatZincSpace& s,
const ConExpr& ce, AST::Node* ann) {
654 p_bool_CMP(s,
IRT_NQ, ce, ann);
656 void p_bool_ne_reif(FlatZincSpace& s,
const ConExpr& ce, AST::Node* ann) {
657 p_bool_CMP_reif(s,
IRT_NQ, ce, ann);
659 void p_bool_ge(FlatZincSpace& s,
const ConExpr& ce, AST::Node* ann) {
660 p_bool_CMP(s,
IRT_GQ, ce, ann);
662 void p_bool_ge_reif(FlatZincSpace& s,
const ConExpr& ce, AST::Node* ann) {
663 p_bool_CMP_reif(s,
IRT_GQ, ce, ann);
665 void p_bool_le(FlatZincSpace& s,
const ConExpr& ce, AST::Node* ann) {
666 p_bool_CMP(s,
IRT_LQ, ce, ann);
668 void p_bool_le_reif(FlatZincSpace& s,
const ConExpr& ce, AST::Node* ann) {
669 p_bool_CMP_reif(s,
IRT_LQ, ce, ann);
671 void p_bool_gt(FlatZincSpace& s,
const ConExpr& ce, AST::Node* ann) {
672 p_bool_CMP(s,
IRT_GR, ce, ann);
674 void p_bool_gt_reif(FlatZincSpace& s,
const ConExpr& ce, AST::Node* ann) {
675 p_bool_CMP_reif(s,
IRT_GR, ce, ann);
677 void p_bool_lt(FlatZincSpace& s,
const ConExpr& ce, AST::Node* ann) {
678 p_bool_CMP(s,
IRT_LE, ce, ann);
680 void p_bool_lt_reif(FlatZincSpace& s,
const ConExpr& ce, AST::Node* ann) {
681 p_bool_CMP_reif(s,
IRT_LE, ce, ann);
684 #define BOOL_OP(op) \
685 BoolVar b0 = getBoolVar(s, ce[0]); \
686 BoolVar b1 = getBoolVar(s, ce[1]); \
687 if (ce[2]->isBool()) { \
688 rel(s, b0, op, b1, ce[2]->getBool(), ann2icl(ann)); \
690 rel(s, b0, op, b1, s.bv[ce[2]->getBoolVar()], ann2icl(ann)); \
693 #define BOOL_ARRAY_OP(op) \
694 BoolVarArgs bv = arg2boolvarargs(s, ce[0]); \
695 if (ce.size()==1) { \
696 rel(s, op, bv, 1, ann2icl(ann)); \
697 } else if (ce[1]->isBool()) { \
698 rel(s, op, bv, ce[1]->getBool(), ann2icl(ann)); \
700 rel(s, op, bv, s.bv[ce[1]->getBoolVar()], ann2icl(ann)); \
703 void p_bool_or(FlatZincSpace& s,
const ConExpr& ce, AST::Node* ann) {
706 void p_bool_and(FlatZincSpace& s,
const ConExpr& ce, AST::Node* ann) {
709 void p_array_bool_and(FlatZincSpace& s,
const ConExpr& ce, AST::Node* ann)
713 void p_array_bool_or(FlatZincSpace& s,
const ConExpr& ce, AST::Node* ann)
717 void p_array_bool_xor(FlatZincSpace& s,
const ConExpr& ce, AST::Node* ann)
721 void p_array_bool_clause(FlatZincSpace& s,
const ConExpr& ce,
723 BoolVarArgs bvp = arg2boolvarargs(s, ce[0]);
724 BoolVarArgs bvn = arg2boolvarargs(s, ce[1]);
727 void p_array_bool_clause_reif(FlatZincSpace& s,
const ConExpr& ce,
729 BoolVarArgs bvp = arg2boolvarargs(s, ce[0]);
730 BoolVarArgs bvn = arg2boolvarargs(s, ce[1]);
731 BoolVar b0 = getBoolVar(s, ce[2]);
734 void p_bool_xor(FlatZincSpace& s,
const ConExpr& ce, AST::Node* ann) {
737 void p_bool_l_imp(FlatZincSpace& s,
const ConExpr& ce, AST::Node* ann) {
738 BoolVar b0 = getBoolVar(s, ce[0]);
739 BoolVar
b1 = getBoolVar(s, ce[1]);
740 if (ce[2]->isBool()) {
741 rel(s, b1,
BOT_IMP, b0, ce[2]->getBool(), ann2icl(ann));
743 rel(s, b1,
BOT_IMP, b0, s.bv[ce[2]->getBoolVar()], ann2icl(ann));
746 void p_bool_r_imp(FlatZincSpace& s,
const ConExpr& ce, AST::Node* ann) {
749 void p_bool_not(FlatZincSpace& s,
const ConExpr& ce, AST::Node* ann) {
750 BoolVar x0 = getBoolVar(s, ce[0]);
751 BoolVar x1 = getBoolVar(s, ce[1]);
756 void p_array_int_element(FlatZincSpace& s,
const ConExpr& ce,
758 bool isConstant =
true;
759 AST::Array* a = ce[1]->getArray();
760 for (
int i=a->
a.size();
i--;) {
761 if (!a->a[
i]->isInt()) {
766 IntVar selector = getIntVar(s, ce[0]);
767 rel(s, selector > 0);
769 IntArgs ia = arg2intargs(ce[1], 1);
770 element(s, ia, selector, getIntVar(s, ce[2]), ann2icl(ann));
772 IntVarArgs iv = arg2intvarargs(s, ce[1], 1);
773 element(s, iv, selector, getIntVar(s, ce[2]), ann2icl(ann));
776 void p_array_bool_element(FlatZincSpace& s,
const ConExpr& ce,
778 bool isConstant =
true;
779 AST::Array* a = ce[1]->getArray();
780 for (
int i=a->
a.size();
i--;) {
781 if (!a->a[
i]->isBool()) {
786 IntVar selector = getIntVar(s, ce[0]);
787 rel(s, selector > 0);
789 IntArgs ia = arg2boolargs(ce[1], 1);
790 element(s, ia, selector, getBoolVar(s, ce[2]), ann2icl(ann));
792 BoolVarArgs iv = arg2boolvarargs(s, ce[1], 1);
793 element(s, iv, selector, getBoolVar(s, ce[2]), ann2icl(ann));
798 void p_bool2int(FlatZincSpace& s,
const ConExpr& ce, AST::Node* ann) {
799 BoolVar x0 = getBoolVar(s, ce[0]);
800 IntVar x1 = getIntVar(s, ce[1]);
801 if (ce[0]->isBoolVar() && ce[1]->isIntVar()) {
802 s.aliasBool2Int(ce[1]->getIntVar(), ce[0]->getBoolVar());
804 channel(s, x0, x1, ann2icl(ann));
807 void p_int_in(FlatZincSpace& s,
const ConExpr& ce, AST::Node *) {
808 IntSet d = arg2intset(s,ce[1]);
809 if (ce[0]->isBoolVar()) {
811 Iter::Ranges::Singleton sr(0,1);
812 Iter::Ranges::Inter<IntSetRanges,Iter::Ranges::Singleton>
i(dr,sr);
814 if (d01.size() == 0) {
817 rel(s, getBoolVar(s, ce[0]),
IRT_GQ, d01.min());
818 rel(s, getBoolVar(s, ce[0]),
IRT_LQ, d01.max());
821 dom(s, getIntVar(s, ce[0]), d);
824 void p_int_in_reif(FlatZincSpace& s,
const ConExpr& ce, AST::Node *) {
825 IntSet d = arg2intset(s,ce[1]);
826 if (ce[0]->isBoolVar()) {
828 Iter::Ranges::Singleton sr(0,1);
829 Iter::Ranges::Inter<IntSetRanges,Iter::Ranges::Singleton>
i(dr,sr);
831 if (d01.size() == 0) {
832 rel(s, getBoolVar(s, ce[2]) == 0);
833 }
else if (d01.max() == 0) {
834 rel(s, getBoolVar(s, ce[2]) == !getBoolVar(s, ce[0]));
835 }
else if (d01.min() == 1) {
836 rel(s, getBoolVar(s, ce[2]) == getBoolVar(s, ce[0]));
838 rel(s, getBoolVar(s, ce[2]) == 1);
841 std::cerr <<
"in_in_reif("<<getIntVar(s, ce[0])<<
","<<d<<
","<<getBoolVar(s, ce[2])<<
")\n";
842 dom(s, getIntVar(s, ce[0]), d, getBoolVar(s, ce[2]));
848 void p_abs(FlatZincSpace& s,
const ConExpr& ce, AST::Node* ann) {
849 IntVar x0 = getIntVar(s, ce[0]);
850 IntVar x1 = getIntVar(s, ce[1]);
851 abs(s, x0, x1, ann2icl(ann));
854 void p_array_int_lt(FlatZincSpace& s,
const ConExpr& ce, AST::Node* ann) {
855 IntVarArgs iv0 = arg2intvarargs(s, ce[0]);
856 IntVarArgs iv1 = arg2intvarargs(s, ce[1]);
860 void p_array_int_lq(FlatZincSpace& s,
const ConExpr& ce, AST::Node* ann) {
861 IntVarArgs iv0 = arg2intvarargs(s, ce[0]);
862 IntVarArgs iv1 = arg2intvarargs(s, ce[1]);
866 void p_count(FlatZincSpace& s,
const ConExpr& ce, AST::Node* ann) {
867 IntVarArgs iv = arg2intvarargs(s, ce[0]);
868 if (!ce[1]->isIntVar()) {
869 if (!ce[2]->isIntVar()) {
870 count(s, iv, ce[1]->getInt(),
IRT_EQ, ce[2]->getInt(),
873 count(s, iv, ce[1]->getInt(),
IRT_EQ, getIntVar(s, ce[2]),
876 }
else if (!ce[2]->isIntVar()) {
877 count(s, iv, getIntVar(s, ce[1]),
IRT_EQ, ce[2]->getInt(),
880 count(s, iv, getIntVar(s, ce[1]),
IRT_EQ, getIntVar(s, ce[2]),
886 FlatZincSpace& s,
const ConExpr& ce, AST::Node* ann) {
887 IntVarArgs iv = arg2intvarargs(s, ce[1]);
888 count(s, iv, ce[2]->getInt(), irt, ce[0]->getInt(), ann2icl(ann));
891 void p_at_most(FlatZincSpace& s,
const ConExpr& ce, AST::Node* ann) {
892 count_rel(
IRT_LQ, s, ce, ann);
895 void p_at_least(FlatZincSpace& s,
const ConExpr& ce, AST::Node* ann) {
896 count_rel(
IRT_GQ, s, ce, ann);
899 void p_bin_packing_load(FlatZincSpace& s,
const ConExpr& ce,
901 int minIdx = ce[3]->getInt();
902 IntVarArgs load = arg2intvarargs(s, ce[0]);
904 IntVarArgs bin = arg2intvarargs(s, ce[1]);
905 for (
int i=bin.
size();
i--;)
906 rel(s, bin[
i] >= minIdx);
908 for (
int i=minIdx;
i--;)
910 }
else if (minIdx < 0) {
911 IntVarArgs bin2(bin.size());
912 for (
int i=bin.
size();
i--;)
913 bin2[
i] =
expr(s, bin[
i]-minIdx, ann2icl(ann));
917 IntArgs sizes = arg2intargs(ce[2]);
921 void p_global_cardinality(FlatZincSpace& s,
const ConExpr& ce,
923 IntVarArgs iv0 = arg2intvarargs(s, ce[0]);
924 IntArgs cover = arg2intargs(ce[1]);
925 IntVarArgs iv1 = arg2intvarargs(s, ce[2]);
928 IntSet cover_s(cover);
929 IntSetRanges cover_r(cover_s);
930 IntVarRanges* iv0_ri = re.alloc<IntVarRanges>(iv0.size());
931 for (
int i=iv0.
size();
i--;)
932 iv0_ri[
i] = IntVarRanges(iv0[
i]);
933 Iter::Ranges::NaryUnion iv0_r(re,iv0_ri,iv0.size());
934 Iter::Ranges::Diff<Iter::Ranges::NaryUnion,IntSetRanges>
935 extra_r(iv0_r,cover_r);
936 Iter::Ranges::ToValues<Iter::Ranges::Diff<
937 Iter::Ranges::NaryUnion,IntSetRanges> > extra(extra_r);
938 for (; extra(); ++extra) {
939 cover << extra.val();
940 iv1 << IntVar(s,0,iv0.size());
942 count(s, iv0, iv1, cover, ann2icl(ann));
945 void p_global_cardinality_closed(FlatZincSpace& s,
const ConExpr& ce,
947 IntVarArgs iv0 = arg2intvarargs(s, ce[0]);
948 IntArgs cover = arg2intargs(ce[1]);
949 IntVarArgs iv1 = arg2intvarargs(s, ce[2]);
950 count(s, iv0, iv1, cover, ann2icl(ann));
953 void p_global_cardinality_low_up(FlatZincSpace& s,
const ConExpr& ce,
955 IntVarArgs x = arg2intvarargs(s, ce[0]);
956 IntArgs cover = arg2intargs(ce[1]);
958 IntArgs lbound = arg2intargs(ce[2]);
959 IntArgs ubound = arg2intargs(ce[3]);
961 for (
int i=cover.size(); i--;)
962 y[i] = IntSet(lbound[i],ubound[i]);
964 IntSet cover_s(cover);
966 IntVarRanges* xrs = re.alloc<IntVarRanges>(x.size());
967 for (
int i=x.size(); i--;)
969 Iter::Ranges::NaryUnion u(re, xrs, x.size());
970 Iter::Ranges::ToValues<Iter::Ranges::NaryUnion> uv(u);
972 if (!cover_s.in(uv.val())) {
974 y << IntSet(0,x.size());
978 count(s, x, y, cover, ann2icl(ann));
981 void p_global_cardinality_low_up_closed(FlatZincSpace& s,
984 IntVarArgs x = arg2intvarargs(s, ce[0]);
985 IntArgs cover = arg2intargs(ce[1]);
987 IntArgs lbound = arg2intargs(ce[2]);
988 IntArgs ubound = arg2intargs(ce[3]);
990 for (
int i=cover.size(); i--;)
991 y[i] = IntSet(lbound[i],ubound[i]);
993 count(s, x, y, cover, ann2icl(ann));
996 void p_minimum(FlatZincSpace& s,
const ConExpr& ce, AST::Node* ann) {
997 IntVarArgs iv = arg2intvarargs(s, ce[1]);
998 min(s, iv, getIntVar(s, ce[0]), ann2icl(ann));
1001 void p_maximum(FlatZincSpace& s,
const ConExpr& ce, AST::Node* ann) {
1002 IntVarArgs iv = arg2intvarargs(s, ce[1]);
1003 max(s, iv, getIntVar(s, ce[0]), ann2icl(ann));
1006 void p_regular(FlatZincSpace& s,
const ConExpr& ce, AST::Node* ann) {
1007 IntVarArgs iv = arg2intvarargs(s, ce[0]);
1008 int q = ce[1]->getInt();
1009 int symbols = ce[2]->getInt();
1010 IntArgs d = arg2intargs(ce[3]);
1011 int q0 = ce[4]->getInt();
1014 for (
int i=1; i<=q; i++) {
1015 for (
int j=1; j<=symbols; j++) {
1016 if (d[(i-1)*symbols+(j-1)] > 0)
1022 DFA::Transition* t = re.alloc<DFA::Transition>(noOfTrans+1);
1024 for (
int i=1; i<=q; i++) {
1025 for (
int j=1; j<=symbols; j++) {
1026 if (d[(i-1)*symbols+(j-1)] > 0) {
1027 t[noOfTrans].i_state =
i;
1028 t[noOfTrans].symbol = j;
1029 t[noOfTrans].o_state = d[(i-1)*symbols+(j-1)];
1034 t[noOfTrans].i_state = -1;
1037 AST::SetLit* sl = ce[5]->getSet();
1040 f =
static_cast<int*
>(malloc(
sizeof(
int)*(sl->max-sl->min+2)));
1041 for (
int i=sl->min; i<=sl->
max; i++)
1043 f[sl->max-sl->min+1] = -1;
1045 f =
static_cast<int*
>(malloc(
sizeof(
int)*(sl->s.size()+1)));
1046 for (
int j=sl->s.size(); j--; )
1048 f[sl->s.size()] = -1;
1057 p_sort(FlatZincSpace& s,
const ConExpr& ce, AST::Node* ann) {
1058 IntVarArgs x = arg2intvarargs(s, ce[0]);
1059 IntVarArgs y = arg2intvarargs(s, ce[1]);
1060 IntVarArgs xy(x.size()+y.size());
1061 for (
int i=x.size(); i--;)
1063 for (
int i=y.size(); i--;)
1064 xy[i+x.size()] = y[
i];
1066 for (
int i=x.size(); i--;)
1068 for (
int i=y.size(); i--;)
1069 y[i] = xy[i+x.size()];
1070 sorted(s, x, y, ann2icl(ann));
1074 p_inverse_offsets(FlatZincSpace& s,
const ConExpr& ce, AST::Node* ann) {
1075 IntVarArgs x = arg2intvarargs(s, ce[0]);
1076 int xoff = ce[1]->getInt();
1077 IntVarArgs y = arg2intvarargs(s, ce[2]);
1078 int yoff = ce[3]->getInt();
1079 channel(s, x, xoff, y, yoff, ann2icl(ann));
1083 p_increasing_int(FlatZincSpace& s,
const ConExpr& ce, AST::Node* ann) {
1084 IntVarArgs x = arg2intvarargs(s, ce[0]);
1089 p_increasing_bool(FlatZincSpace& s,
const ConExpr& ce, AST::Node* ann) {
1090 BoolVarArgs x = arg2boolvarargs(s, ce[0]);
1095 p_decreasing_int(FlatZincSpace& s,
const ConExpr& ce, AST::Node* ann) {
1096 IntVarArgs x = arg2intvarargs(s, ce[0]);
1101 p_decreasing_bool(FlatZincSpace& s,
const ConExpr& ce, AST::Node* ann) {
1102 BoolVarArgs x = arg2boolvarargs(s, ce[0]);
1107 p_table_int(FlatZincSpace& s,
const ConExpr& ce, AST::Node* ann) {
1108 IntVarArgs x = arg2intvarargs(s, ce[0]);
1109 IntArgs tuples = arg2intargs(ce[1]);
1110 int noOfVars = x.size();
1111 int noOfTuples = tuples.size()/noOfVars;
1113 for (
int i=0; i<noOfTuples; i++) {
1114 IntArgs t(noOfVars);
1115 for (
int j=0; j<x.size(); j++) {
1116 t[j] = tuples[i*noOfVars+j];
1124 p_table_bool(FlatZincSpace& s,
const ConExpr& ce, AST::Node* ann) {
1125 BoolVarArgs x = arg2boolvarargs(s, ce[0]);
1126 IntArgs tuples = arg2boolargs(ce[1]);
1127 int noOfVars = x.size();
1128 int noOfTuples = tuples.size()/noOfVars;
1130 for (
int i=0; i<noOfTuples; i++) {
1131 IntArgs t(noOfVars);
1132 for (
int j=0; j<x.size(); j++) {
1133 t[j] = tuples[i*noOfVars+j];
1141 void p_cumulatives(FlatZincSpace& s,
const ConExpr& ce,
1143 IntVarArgs start = arg2intvarargs(s, ce[0]);
1144 IntVarArgs duration = arg2intvarargs(s, ce[1]);
1145 IntVarArgs height = arg2intvarargs(s, ce[2]);
1146 int n = start.size();
1147 IntVar bound = getIntVar(s, ce[3]);
1149 int minHeight = INT_MAX;
int minHeight2 = INT_MAX;
1151 if (height[i].
min() < minHeight)
1152 minHeight = height[
i].min();
1153 else if (height[i].
min() < minHeight2)
1154 minHeight2 = height[
i].min();
1156 (minHeight > bound.max()/2) ||
1157 (minHeight2 > bound.max()/2 && minHeight+minHeight2>bound.max());
1159 rel(s, bound >=
max(height));
1161 if (duration.assigned()) {
1162 IntArgs durationI(n);
1164 durationI[i] = duration[i].val();
1165 unary(s,start,durationI);
1169 end[i] =
expr(s,start[i]+duration[i]);
1170 unary(s,start,duration,end);
1172 }
else if (height.assigned()) {
1175 heightI[i] = height[i].val();
1176 if (duration.assigned()) {
1177 IntArgs durationI(n);
1179 durationI[i] = duration[i].val();
1180 cumulative(s, bound, start, durationI, heightI);
1183 for (
int i = n; i--; )
1184 end[i] =
expr(s,start[i]+duration[i]);
1185 cumulative(s, bound, start, duration, end, heightI);
1187 }
else if (bound.assigned()) {
1189 IntArgs limit(1, bound.val());
1192 end[i] =
expr(s,start[i]+duration[i]);
1193 cumulatives(s, machine, start, duration, end, height, limit,
true,
1198 IntVarArgs end(start.size());
1199 for (
int i = start.size(); i--; ) {
1202 end[
i] =
expr(s, start[i] + duration[i]);
1204 for (
int time = min; time <
max; ++time) {
1205 IntVarArgs x(start.size());
1206 for (
int i = start.size(); i--; ) {
1207 IntVar overlaps =
channel(s,
expr(s, (start[i] <= time) &&
1209 x[
i] =
expr(s, overlaps * height[i]);
1216 void p_among_seq_int(FlatZincSpace& s,
const ConExpr& ce,
1218 IntVarArgs x = arg2intvarargs(s, ce[0]);
1219 IntSet S = arg2intset(s, ce[1]);
1220 int q = ce[2]->getInt();
1221 int l = ce[3]->getInt();
1222 int u = ce[4]->getInt();
1223 sequence(s, x, S, q, l, u, ann2icl(ann));
1226 void p_among_seq_bool(FlatZincSpace& s,
const ConExpr& ce,
1228 BoolVarArgs x = arg2boolvarargs(s, ce[0]);
1229 bool val = ce[1]->getBool();
1230 int q = ce[2]->getInt();
1231 int l = ce[3]->getInt();
1232 int u = ce[4]->getInt();
1234 sequence(s, x, S, q, l, u, ann2icl(ann));
1237 void p_schedule_unary(FlatZincSpace& s,
const ConExpr& ce, AST::Node*) {
1238 IntVarArgs x = arg2intvarargs(s, ce[0]);
1239 IntArgs p = arg2intargs(ce[1]);
1243 void p_schedule_unary_optional(FlatZincSpace& s,
const ConExpr& ce,
1245 IntVarArgs x = arg2intvarargs(s, ce[0]);
1246 IntArgs p = arg2intargs(ce[1]);
1247 BoolVarArgs
m = arg2boolvarargs(s, ce[2]);
1251 void p_circuit(FlatZincSpace& s,
const ConExpr& ce, AST::Node *ann) {
1252 IntVarArgs xv = arg2intvarargs(s, ce[0]);
1255 void p_circuit_cost_array(FlatZincSpace& s,
const ConExpr& ce,
1257 IntArgs
c = arg2intargs(ce[0]);
1258 IntVarArgs xv = arg2intvarargs(s, ce[1]);
1259 IntVarArgs yv = arg2intvarargs(s, ce[2]);
1260 IntVar z = getIntVar(s, ce[3]);
1261 circuit(s,c,xv,yv,z,ann2icl(ann));
1263 void p_circuit_cost(FlatZincSpace& s,
const ConExpr& ce, AST::Node *ann) {
1264 IntArgs c = arg2intargs(ce[0]);
1265 IntVarArgs xv = arg2intvarargs(s, ce[1]);
1266 IntVar z = getIntVar(s, ce[2]);
1267 circuit(s,c,xv,z,ann2icl(ann));
1270 void p_nooverlap(FlatZincSpace& s,
const ConExpr& ce, AST::Node *ann) {
1271 IntVarArgs x0 = arg2intvarargs(s, ce[0]);
1272 IntVarArgs w = arg2intvarargs(s, ce[1]);
1273 IntVarArgs y0 = arg2intvarargs(s, ce[2]);
1274 IntVarArgs h = arg2intvarargs(s, ce[3]);
1275 IntVarArgs x1(x0.size()), y1(y0.size());
1276 for (
int i=x0.size(); i--; )
1277 x1[i] =
expr(s, x0[i] + w[i]);
1278 for (
int i=y0.size(); i--; )
1279 y1[i] =
expr(s, y0[i] + h[i]);
1280 nooverlap(s,x0,w,x1,y0,h,y1,ann2icl(ann));
1283 void p_precede(FlatZincSpace& s,
const ConExpr& ce, AST::Node* ann) {
1284 IntVarArgs x = arg2intvarargs(s, ce[0]);
1285 IntArgs c = arg2intargs(ce[1]);
1289 void p_nvalue(FlatZincSpace& s,
const ConExpr& ce, AST::Node* ann) {
1290 IntVarArgs x = arg2intvarargs(s, ce[1]);
1291 if (ce[0]->isIntVar()) {
1292 IntVar y = getIntVar(s,ce[0]);
1299 void p_among(FlatZincSpace& s,
const ConExpr& ce, AST::Node* ann) {
1300 IntVarArgs x = arg2intvarargs(s, ce[1]);
1301 IntSet
v = arg2intset(s, ce[2]);
1302 if (ce[0]->isIntVar()) {
1303 IntVar n = getIntVar(s,ce[0]);
1304 std::cerr <<
"count " << n << std::endl;
1307 std::cerr <<
"count i " << x <<
" " << v <<
" " << ce[0]->getInt() << std::endl;
1312 void p_member_int(FlatZincSpace& s,
const ConExpr& ce, AST::Node* ann) {
1313 IntVarArgs x = arg2intvarargs(s, ce[0]);
1314 IntVar y = getIntVar(s, ce[1]);
1315 member(s,x,y,ann2icl(ann));
1317 void p_member_int_reif(FlatZincSpace& s,
const ConExpr& ce,
1319 IntVarArgs x = arg2intvarargs(s, ce[0]);
1320 IntVar y = getIntVar(s, ce[1]);
1321 BoolVar b = getBoolVar(s, ce[2]);
1322 member(s,x,y,b,ann2icl(ann));
1324 void p_member_bool(FlatZincSpace& s,
const ConExpr& ce, AST::Node* ann) {
1325 BoolVarArgs x = arg2boolvarargs(s, ce[0]);
1326 BoolVar y = getBoolVar(s, ce[1]);
1327 member(s,x,y,ann2icl(ann));
1329 void p_member_bool_reif(FlatZincSpace& s,
const ConExpr& ce,
1331 BoolVarArgs x = arg2boolvarargs(s, ce[0]);
1332 BoolVar y = getBoolVar(s, ce[1]);
1333 member(s,x,y,getBoolVar(s, ce[2]),ann2icl(ann));
1340 registry().
add(
"all_different_offset", &p_distinctOffset);
1355 registry().
add(
"int_lin_eq_reif", &p_int_lin_eq_reif);
1357 registry().
add(
"int_lin_ne_reif", &p_int_lin_ne_reif);
1359 registry().
add(
"int_lin_le_reif", &p_int_lin_le_reif);
1361 registry().
add(
"int_lin_lt_reif", &p_int_lin_lt_reif);
1363 registry().
add(
"int_lin_ge_reif", &p_int_lin_ge_reif);
1365 registry().
add(
"int_lin_gt_reif", &p_int_lin_gt_reif);
1390 registry().
add(
"array_bool_and", &p_array_bool_and);
1391 registry().
add(
"array_bool_or", &p_array_bool_or);
1392 registry().
add(
"array_bool_xor", &p_array_bool_xor);
1393 registry().
add(
"bool_clause", &p_array_bool_clause);
1394 registry().
add(
"bool_clause_reif", &p_array_bool_clause_reif);
1398 registry().
add(
"array_int_element", &p_array_int_element);
1399 registry().
add(
"array_var_int_element", &p_array_int_element);
1400 registry().
add(
"array_bool_element", &p_array_bool_element);
1401 registry().
add(
"array_var_bool_element", &p_array_bool_element);
1405 #ifndef GECODE_HAS_SET_VARS
1415 registry().
add(
"gecode_bin_packing_load", &p_bin_packing_load);
1416 registry().
add(
"global_cardinality", &p_global_cardinality);
1418 &p_global_cardinality_closed);
1420 &p_global_cardinality_low_up);
1421 registry().
add(
"global_cardinality_low_up_closed",
1422 &p_global_cardinality_low_up_closed);
1427 registry().
add(
"inverse_offsets", &p_inverse_offsets);
1428 registry().
add(
"increasing_int", &p_increasing_int);
1429 registry().
add(
"increasing_bool", &p_increasing_bool);
1430 registry().
add(
"decreasing_int", &p_decreasing_int);
1431 registry().
add(
"decreasing_bool", &p_decreasing_bool);
1435 registry().
add(
"gecode_among_seq_int", &p_among_seq_int);
1436 registry().
add(
"gecode_among_seq_bool", &p_among_seq_bool);
1445 registry().
add(
"bool_lin_eq_reif", &p_bool_lin_eq_reif);
1446 registry().
add(
"bool_lin_ne_reif", &p_bool_lin_ne_reif);
1447 registry().
add(
"bool_lin_le_reif", &p_bool_lin_le_reif);
1448 registry().
add(
"bool_lin_lt_reif", &p_bool_lin_lt_reif);
1449 registry().
add(
"bool_lin_ge_reif", &p_bool_lin_ge_reif);
1450 registry().
add(
"bool_lin_gt_reif", &p_bool_lin_gt_reif);
1452 registry().
add(
"gecode_schedule_unary", &p_schedule_unary);
1453 registry().
add(
"gecode_schedule_unary_optional", &p_schedule_unary_optional);
1456 registry().
add(
"gecode_circuit_cost_array", &p_circuit_cost_array);
1457 registry().
add(
"gecode_circuit_cost", &p_circuit_cost);
1463 registry().
add(
"gecode_member_int_reif",&p_member_int_reif);
1465 registry().
add(
"gecode_member_bool_reif",&p_member_bool_reif);
1468 IntPoster __int_poster;
1470 #ifdef GECODE_HAS_SET_VARS
1471 void p_set_OP(FlatZincSpace& s,
SetOpType op,
1472 const ConExpr& ce, AST::Node *) {
1473 rel(s, getSetVar(s, ce[0]), op, getSetVar(s, ce[1]),
1474 SRT_EQ, getSetVar(s, ce[2]));
1476 void p_set_union(FlatZincSpace& s,
const ConExpr& ce, AST::Node *ann) {
1479 void p_set_intersect(FlatZincSpace& s,
const ConExpr& ce, AST::Node *ann) {
1482 void p_set_diff(FlatZincSpace& s,
const ConExpr& ce, AST::Node *ann) {
1486 void p_set_symdiff(FlatZincSpace& s,
const ConExpr& ce, AST::Node*) {
1487 SetVar x = getSetVar(s, ce[0]);
1488 SetVar y = getSetVar(s, ce[1]);
1490 SetVarLubRanges xub(x);
1495 SetVarLubRanges yub(y);
1503 void p_array_set_OP(FlatZincSpace& s,
SetOpType op,
1504 const ConExpr& ce, AST::Node *) {
1505 SetVarArgs xs = arg2setvarargs(s, ce[0]);
1506 rel(s, op, xs, getSetVar(s, ce[1]));
1508 void p_array_set_union(FlatZincSpace& s,
const ConExpr& ce, AST::Node *ann) {
1511 void p_array_set_partition(FlatZincSpace& s,
const ConExpr& ce, AST::Node *ann) {
1516 void p_set_rel(FlatZincSpace& s,
SetRelType srt,
const ConExpr& ce) {
1517 rel(s, getSetVar(s, ce[0]), srt, getSetVar(s, ce[1]));
1520 void p_set_eq(FlatZincSpace& s,
const ConExpr& ce, AST::Node *) {
1521 p_set_rel(s,
SRT_EQ, ce);
1523 void p_set_ne(FlatZincSpace& s,
const ConExpr& ce, AST::Node *) {
1524 p_set_rel(s,
SRT_NQ, ce);
1526 void p_set_subset(FlatZincSpace& s,
const ConExpr& ce, AST::Node *) {
1529 void p_set_superset(FlatZincSpace& s,
const ConExpr& ce, AST::Node *) {
1532 void p_set_le(FlatZincSpace& s,
const ConExpr& ce, AST::Node *) {
1533 p_set_rel(s,
SRT_LQ, ce);
1535 void p_set_lt(FlatZincSpace& s,
const ConExpr& ce, AST::Node *) {
1536 p_set_rel(s,
SRT_LE, ce);
1538 void p_set_card(FlatZincSpace& s,
const ConExpr& ce, AST::Node *) {
1539 if (!ce[1]->isIntVar()) {
1540 cardinality(s, getSetVar(s, ce[0]), ce[1]->getInt(),
1543 cardinality(s, getSetVar(s, ce[0]), getIntVar(s, ce[1]));
1546 void p_set_in(FlatZincSpace& s,
const ConExpr& ce, AST::Node *) {
1547 if (!ce[1]->isSetVar()) {
1548 IntSet d = arg2intset(s,ce[1]);
1549 if (ce[0]->isBoolVar()) {
1551 Iter::Ranges::Singleton sr(0,1);
1552 Iter::Ranges::Inter<IntSetRanges,Iter::Ranges::Singleton>
i(dr,sr);
1554 if (d01.size() == 0) {
1557 rel(s, getBoolVar(s, ce[0]),
IRT_GQ, d01.min());
1558 rel(s, getBoolVar(s, ce[0]),
IRT_LQ, d01.max());
1561 dom(s, getIntVar(s, ce[0]), d);
1564 if (!ce[0]->isIntVar()) {
1565 dom(s, getSetVar(s, ce[1]),
SRT_SUP, ce[0]->getInt());
1567 rel(s, getSetVar(s, ce[1]),
SRT_SUP, getIntVar(s, ce[0]));
1571 void p_set_rel_reif(FlatZincSpace& s,
SetRelType srt,
const ConExpr& ce) {
1572 rel(s, getSetVar(s, ce[0]), srt, getSetVar(s, ce[1]),
1573 getBoolVar(s, ce[2]));
1576 void p_set_eq_reif(FlatZincSpace& s,
const ConExpr& ce, AST::Node *) {
1577 p_set_rel_reif(s,
SRT_EQ,ce);
1579 void p_set_le_reif(FlatZincSpace& s,
const ConExpr& ce, AST::Node *) {
1580 p_set_rel_reif(s,
SRT_LQ,ce);
1582 void p_set_lt_reif(FlatZincSpace& s,
const ConExpr& ce, AST::Node *) {
1583 p_set_rel_reif(s,
SRT_LE,ce);
1585 void p_set_ne_reif(FlatZincSpace& s,
const ConExpr& ce, AST::Node *) {
1586 p_set_rel_reif(s,
SRT_NQ,ce);
1588 void p_set_subset_reif(FlatZincSpace& s,
const ConExpr& ce,
1592 void p_set_superset_reif(FlatZincSpace& s,
const ConExpr& ce,
1596 void p_set_in_reif(FlatZincSpace& s,
const ConExpr& ce, AST::Node *) {
1597 if (!ce[1]->isSetVar()) {
1598 IntSet d = arg2intset(s,ce[1]);
1599 if (ce[0]->isBoolVar()) {
1601 Iter::Ranges::Singleton sr(0,1);
1602 Iter::Ranges::Inter<IntSetRanges,Iter::Ranges::Singleton>
i(dr,sr);
1604 if (d01.size() == 0) {
1605 rel(s, getBoolVar(s, ce[2]) == 0);
1606 }
else if (d01.max() == 0) {
1607 rel(s, getBoolVar(s, ce[2]) == !getBoolVar(s, ce[0]));
1608 }
else if (d01.min() == 1) {
1609 rel(s, getBoolVar(s, ce[2]) == getBoolVar(s, ce[0]));
1611 rel(s, getBoolVar(s, ce[2]) == 1);
1614 dom(s, getIntVar(s, ce[0]), d, getBoolVar(s, ce[2]));
1617 if (!ce[0]->isIntVar()) {
1618 dom(s, getSetVar(s, ce[1]),
SRT_SUP, ce[0]->getInt(),
1619 getBoolVar(s, ce[2]));
1621 rel(s, getSetVar(s, ce[1]),
SRT_SUP, getIntVar(s, ce[0]),
1622 getBoolVar(s, ce[2]));
1626 void p_set_disjoint(FlatZincSpace& s,
const ConExpr& ce, AST::Node *) {
1627 rel(s, getSetVar(s, ce[0]),
SRT_DISJ, getSetVar(s, ce[1]));
1630 void p_link_set_to_booleans(FlatZincSpace& s,
const ConExpr& ce,
1632 SetVar x = getSetVar(s, ce[0]);
1633 int idx = ce[2]->getInt();
1636 BoolVarArgs y = arg2boolvarargs(s,ce[1],idx);
1640 void p_array_set_element(FlatZincSpace& s,
const ConExpr& ce,
1642 bool isConstant =
true;
1643 AST::Array* a = ce[1]->getArray();
1644 for (
int i=a->a.size(); i--;) {
1645 if (a->a[i]->isSetVar()) {
1650 IntVar selector = getIntVar(s, ce[0]);
1651 rel(s, selector > 0);
1654 element(s, sv, selector, getSetVar(s, ce[2]));
1656 SetVarArgs sv = arg2setvarargs(s, ce[1], 1);
1657 element(s, sv, selector, getSetVar(s, ce[2]));
1661 void p_array_set_element_op(FlatZincSpace& s,
const ConExpr& ce,
1663 const IntSet& universe =
1665 bool isConstant =
true;
1666 AST::Array* a = ce[1]->getArray();
1667 for (
int i=a->a.size(); i--;) {
1668 if (a->a[i]->isSetVar()) {
1673 SetVar selector = getSetVar(s, ce[0]);
1677 element(s, op, sv, selector, getSetVar(s, ce[2]), universe);
1679 SetVarArgs sv = arg2setvarargs(s, ce[1], 1);
1680 element(s, op, sv, selector, getSetVar(s, ce[2]), universe);
1684 void p_array_set_element_union(FlatZincSpace& s,
const ConExpr& ce,
1686 p_array_set_element_op(s, ce, ann,
SOT_UNION);
1689 void p_array_set_element_intersect(FlatZincSpace& s,
const ConExpr& ce,
1691 p_array_set_element_op(s, ce, ann,
SOT_INTER);
1694 void p_array_set_element_intersect_in(FlatZincSpace& s,
1697 IntSet d = arg2intset(s, ce[3]);
1698 p_array_set_element_op(s, ce, ann,
SOT_INTER, d);
1701 void p_array_set_element_partition(FlatZincSpace& s,
const ConExpr& ce,
1703 p_array_set_element_op(s, ce, ann,
SOT_DUNION);
1706 void p_set_convex(FlatZincSpace& s,
const ConExpr& ce, AST::Node *) {
1707 convex(s, getSetVar(s, ce[0]));
1710 void p_array_set_seq(FlatZincSpace& s,
const ConExpr& ce, AST::Node *) {
1711 SetVarArgs sv = arg2setvarargs(s, ce[0]);
1715 void p_array_set_seq_union(FlatZincSpace& s,
const ConExpr& ce,
1717 SetVarArgs sv = arg2setvarargs(s, ce[0]);
1718 sequence(s, sv, getSetVar(s, ce[1]));
1721 void p_int_set_channel(FlatZincSpace& s,
const ConExpr& ce,
1723 int xoff=ce[1]->getInt();
1725 int yoff=ce[3]->getInt();
1727 IntVarArgs xv = arg2intvarargs(s, ce[0], xoff);
1728 SetVarArgs yv = arg2setvarargs(s, ce[2], yoff, 1, IntSet(0, xoff-1));
1729 IntSet xd(yoff,yv.size()-1);
1730 for (
int i=xoff; i<xv.size(); i++) {
1733 IntSet yd(xoff,xv.size()-1);
1734 for (
int i=yoff; i<yv.size(); i++) {
1740 void p_range(FlatZincSpace& s,
const ConExpr& ce, AST::Node*) {
1741 int xoff=ce[1]->getInt();
1743 IntVarArgs xv = arg2intvarargs(s,ce[0],xoff);
1747 void p_weights(FlatZincSpace& s,
const ConExpr& ce, AST::Node*) {
1748 IntArgs e = arg2intargs(ce[0]);
1749 IntArgs w = arg2intargs(ce[1]);
1750 SetVar x = getSetVar(s,ce[2]);
1751 IntVar y = getIntVar(s,ce[3]);
1764 registry().
add(
"array_set_element", &p_array_set_element);
1765 registry().
add(
"array_var_set_element", &p_array_set_element);
1766 registry().
add(
"set_intersect", &p_set_intersect);
1778 registry().
add(
"set_subset_reif", &p_set_subset_reif);
1779 registry().
add(
"set_superset_reif", &p_set_superset_reif);
1783 &p_link_set_to_booleans);
1785 registry().
add(
"array_set_union", &p_array_set_union);
1786 registry().
add(
"array_set_partition", &p_array_set_partition);
1788 registry().
add(
"array_set_seq", &p_array_set_seq);
1789 registry().
add(
"array_set_seq_union", &p_array_set_seq_union);
1791 &p_array_set_element_union);
1792 registry().
add(
"gecode_array_set_element_intersect",
1793 &p_array_set_element_intersect);
1794 registry().
add(
"gecode_array_set_element_intersect_in",
1795 &p_array_set_element_intersect_in);
1796 registry().
add(
"gecode_array_set_element_partition",
1797 &p_array_set_element_partition);
1799 &p_int_set_channel);
1806 SetPoster __set_poster;