Generated on for Gecode by doxygen 1.17.0
flatzinc.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.dev>
5 *
6 * Contributing authors:
7 * Gabriel Hjort Blindell <gabriel.hjort.blindell@gmail.com>
8 * Nathan Tran <kieron.qtran@gmail.com>
9 *
10 * Copyright:
11 * Guido Tack, 2007-2012
12 * Gabriel Hjort Blindell, 2012
13 * Nathan Tran, 2025
14 *
15 * This file is part of Gecode, the generic constraint
16 * development environment:
17 * http://www.gecode.dev
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/flatzinc.hh>
45
46#include <gecode/search.hh>
47
48#include <vector>
49#include <string>
50#include <sstream>
51#include <limits>
52#include <cmath>
53#include <memory>
54#include <unordered_set>
55
56
57namespace std {
58
60 template<> struct hash<Gecode::TupleSet> {
62 forceinline size_t
63 operator()(const Gecode::TupleSet& x) const {
64 return x.hash();
65 }
66 };
67
69 template<> struct hash<Gecode::SharedArray<int> > {
71 forceinline size_t
73 size_t seed = static_cast<size_t>(x.size());
74 for (int i=x.size(); i--; )
75 Gecode::cmb_hash(seed, x[i]);
76 return seed;
77 }
78 };
79
81 template<> struct hash<Gecode::DFA> {
83 forceinline size_t operator()(const Gecode::DFA& d) const {
84 return d.hash();
85 }
86 };
87
88}
89
90namespace Gecode { namespace FlatZinc {
91
92 // Default random number generator
94
107 class AuxVarBrancher : public Brancher {
108 protected:
110 bool done;
113 IntValBranch int_valsel0,
114 TieBreak<BoolVarBranch> bool_varsel0,
115 BoolValBranch bool_valsel0
117 ,
118 SetVarBranch set_varsel0,
119 SetValBranch set_valsel0
120#endif
122 ,
123 TieBreak<FloatVarBranch> float_varsel0,
124 FloatValBranch float_valsel0
125#endif
126 )
127 : Brancher(home), done(false),
128 int_varsel(int_varsel0), int_valsel(int_valsel0),
129 bool_varsel(bool_varsel0), bool_valsel(bool_valsel0)
131 , set_varsel(set_varsel0), set_valsel(set_valsel0)
132#endif
134 , float_varsel(float_varsel0), float_valsel(float_valsel0)
135#endif
136 {}
137
139 : Brancher(home, b), done(b.done) {}
140
142 class Choice : public Gecode::Choice {
143 public:
145 bool fail;
147 Choice(const Brancher& b, bool fail0)
148 : Gecode::Choice(b,1), fail(fail0) {}
149
150 virtual size_t size(void) const {
151 return sizeof(Choice);
152 }
153
154 virtual void archive(Archive& e) const {
156 e.put(fail);
157 }
158 };
159
164#ifdef GECODE_HAS_SET_VARS
167#endif
168#ifdef GECODE_HAS_FLOAT_VARS
171#endif
172
173 public:
175 virtual bool status(const Space& _home) const {
176 if (done) return false;
177 const FlatZincSpace& home = static_cast<const FlatZincSpace&>(_home);
178 for (int i=0; i<home.iv_aux.size(); i++)
179 if (!home.iv_aux[i].assigned()) return true;
180 for (int i=0; i<home.bv_aux.size(); i++)
181 if (!home.bv_aux[i].assigned()) return true;
182#ifdef GECODE_HAS_SET_VARS
183 for (int i=0; i<home.sv_aux.size(); i++)
184 if (!home.sv_aux[i].assigned()) return true;
185#endif
186#ifdef GECODE_HAS_FLOAT_VARS
187 for (int i=0; i<home.fv_aux.size(); i++)
188 if (!home.fv_aux[i].assigned()) return true;
189#endif
190 // No non-assigned variables left
191 return false;
192 }
193
194 virtual Choice* choice(Space& home) {
195 done = true;
196 FlatZincSpace& fzs = static_cast<FlatZincSpace&>(*home.clone());
197 fzs.needAuxVars = false;
200#ifdef GECODE_HAS_SET_VARS
202#endif
203#ifdef GECODE_HAS_FLOAT_VARS
205#endif
206 Search::Options opt; opt.clone = false;
207 FlatZincSpace* sol = dfs(&fzs, opt);
208 if (sol) {
209 delete sol;
210 return new Choice(*this,false);
211 } else {
212 return new Choice(*this,true);
213 }
214 }
215
216 virtual Choice* choice(const Space&, Archive& e) {
217 bool fail; e >> fail;
218 return new Choice(*this, fail);
219 }
220
221 virtual ExecStatus commit(Space&, const Gecode::Choice& c, unsigned int) {
222 return static_cast<const Choice&>(c).fail ? ES_FAILED : ES_OK;
223 }
224
225 virtual void print(const Space&, const Gecode::Choice& c,
226 unsigned int,
227 std::ostream& o) const {
228 o << "FlatZinc("
229 << (static_cast<const Choice&>(c).fail ? "fail" : "ok")
230 << ")";
231 }
232
233 virtual Actor* copy(Space& home) {
234 return new (home) AuxVarBrancher(home, *this);
235 }
236
263
264 virtual size_t dispose(Space&) {
265 return sizeof(*this);
266 }
267 };
268
269 class BranchInformationO : public SharedHandle::Object {
270 private:
271 struct BI {
272 std::string r0;
273 std::string r1;
274 std::vector<std::string> n;
275 BI(void) : r0(""), r1(""), n(0) {}
276 BI(const std::string& r00, const std::string& r10,
277 const std::vector<std::string>& n0)
278 : r0(r00), r1(r10), n(n0) {}
279 };
280 std::vector<BI> v;
281 BranchInformationO(std::vector<BI> v0) : v(v0) {}
282 public:
284 virtual ~BranchInformationO(void) {}
285 virtual SharedHandle::Object* copy(void) const {
286 return new BranchInformationO(v);
287 }
288
290 const std::string& rel0,
291 const std::string& rel1,
292 const std::vector<std::string>& n) {
293 v.resize(std::max(static_cast<unsigned int>(v.size()),bg.id()+1));
294 v[bg.id()] = BI(rel0,rel1,n);
295 }
296
297 void print(const Brancher& b,
298 unsigned int a, int i, int n, std::ostream& o) const {
299 const BI& bi = v[b.group().id()];
300 o << bi.n[i] << " " << (a==0 ? bi.r0 : bi.r1) << " " << n;
301 }
302#ifdef GECODE_HAS_FLOAT_VARS
303 void print(const Brancher& b,
304 unsigned int a, int i, const FloatNumBranch& nl,
305 std::ostream& o) const {
306 const BI& bi = v[b.group().id()];
307 o << bi.n[i] << " "
308 << (((a == 0) == nl.l) ? "<=" : ">=") << nl.n;
309 }
310#endif
311 };
312
315
318
319 void
321 assert(object() == nullptr);
323 }
324
325 void
327 const std::string& rel0,
328 const std::string& rel1,
329 const std::vector<std::string>& n) {
330 static_cast<BranchInformationO*>(object())->add(bg,rel0,rel1,n);
331 }
332 void
333 BranchInformation::print(const Brancher& b, unsigned int a, int i,
334 int n, std::ostream& o) const {
335 static_cast<const BranchInformationO*>(object())->print(b,a,i,n,o);
336 }
337#ifdef GECODE_HAS_FLOAT_VARS
338 void
339 BranchInformation::print(const Brancher& b, unsigned int a, int i,
340 const FloatNumBranch& nl, std::ostream& o) const {
341 static_cast<const BranchInformationO*>(object())->print(b,a,i,nl,o);
342 }
343#endif
344 template<class Var>
345 void varValPrint(const Space &home, const Brancher& b,
346 unsigned int a,
347 Var, int i, const int& n,
348 std::ostream& o) {
349 static_cast<const FlatZincSpace&>(home).branchInfo.print(b,a,i,n,o);
350 }
351
352#ifdef GECODE_HAS_FLOAT_VARS
353 void varValPrintF(const Space &home, const Brancher& b,
354 unsigned int a,
355 FloatVar, int i, const FloatNumBranch& nl,
356 std::ostream& o) {
357 static_cast<const FlatZincSpace&>(home).branchInfo.print(b,a,i,nl,o);
358 }
359#endif
360
362 if (vs->assigned) {
363 return IntSet(vs->i,vs->i);
364 }
365 if (vs->domain()) {
366 AST::SetLit* sl = vs->domain.some();
367 if (sl->interval) {
368 return IntSet(sl->min, sl->max);
369 } else {
370 int* newdom = heap.alloc<int>(static_cast<unsigned long int>(sl->s.size()));
371 for (int i=sl->s.size(); i--;)
372 newdom[i] = sl->s[i];
373 IntSet ret(newdom, sl->s.size());
374 heap.free(newdom, static_cast<unsigned long int>(sl->s.size()));
375 return ret;
376 }
377 }
379 }
380
382 if (bs->assigned) {
383 return bs->i;
384 }
385 if (bs->domain()) {
386 AST::SetLit* sl = bs->domain.some();
387 assert(sl->interval);
388 return std::min(1, std::max(0, sl->min));
389 }
390 return 0;
391 }
392
394 if (bs->assigned) {
395 return bs->i;
396 }
397 if (bs->domain()) {
398 AST::SetLit* sl = bs->domain.some();
399 assert(sl->interval);
400 return std::max(0, std::min(1, sl->max));
401 }
402 return 1;
403 }
404
406 if (AST::Atom* s = dynamic_cast<AST::Atom*>(ann)) {
407 if (s->id == "input_order")
409 if (s->id == "first_fail")
411 if (s->id == "anti_first_fail")
413 if (s->id == "smallest")
415 if (s->id == "largest")
417 if (s->id == "occurrence")
419 if (s->id == "max_regret")
421 if (s->id == "most_constrained")
424 if (s->id == "random") {
426 }
427 if (s->id == "dom_w_deg") {
429 }
430 if (s->id == "afc_min")
432 if (s->id == "afc_max")
434 if (s->id == "afc_size_min")
436 if (s->id == "afc_size_max") {
438 }
439 if (s->id == "action_min")
441 if (s->id == "action_max")
443 if (s->id == "action_size_min")
445 if (s->id == "action_size_max")
447 }
448 std::cerr << "Warning, ignored search annotation: ";
449 ann->print(std::cerr);
450 std::cerr << std::endl;
452 }
453
454 IntValBranch ann2ivalsel(AST::Node* ann, std::string& r0, std::string& r1,
455 Rnd rnd) {
456 if (AST::Atom* s = dynamic_cast<AST::Atom*>(ann)) {
457 if (s->id == "indomain_min") {
458 r0 = "="; r1 = "!=";
459 return INT_VAL_MIN();
460 }
461 if (s->id == "indomain_max") {
462 r0 = "="; r1 = "!=";
463 return INT_VAL_MAX();
464 }
465 if (s->id == "indomain_median") {
466 r0 = "="; r1 = "!=";
467 return INT_VAL_MED();
468 }
469 if (s->id == "indomain_split") {
470 r0 = "<="; r1 = ">";
471 return INT_VAL_SPLIT_MIN();
472 }
473 if (s->id == "indomain_reverse_split") {
474 r0 = ">"; r1 = "<=";
475 return INT_VAL_SPLIT_MAX();
476 }
477 if (s->id == "indomain_random") {
478 r0 = "="; r1 = "!=";
479 return INT_VAL_RND(rnd);
480 }
481 if (s->id == "indomain") {
482 r0 = "="; r1 = "=";
483 return INT_VALUES_MIN();
484 }
485 if (s->id == "indomain_middle") {
486 std::cerr << "Warning, replacing unsupported annotation "
487 << "indomain_middle with indomain_median" << std::endl;
488 r0 = "="; r1 = "!=";
489 return INT_VAL_MED();
490 }
491 if (s->id == "indomain_interval") {
492 std::cerr << "Warning, replacing unsupported annotation "
493 << "indomain_interval with indomain_split" << std::endl;
494 r0 = "<="; r1 = ">";
495 return INT_VAL_SPLIT_MIN();
496 }
497 }
498 std::cerr << "Warning, ignored search annotation: ";
499 ann->print(std::cerr);
500 std::cerr << std::endl;
501 r0 = "="; r1 = "!=";
502 return INT_VAL_MIN();
503 }
504
506 if (AST::Atom* s = dynamic_cast<AST::Atom*>(ann)) {
507 if (s->id == "indomain_min")
508 return INT_ASSIGN_MIN();
509 if (s->id == "indomain_max")
510 return INT_ASSIGN_MAX();
511 if (s->id == "indomain_median")
512 return INT_ASSIGN_MED();
513 if (s->id == "indomain_random") {
514 return INT_ASSIGN_RND(rnd);
515 }
516 }
517 std::cerr << "Warning, ignored search annotation: ";
518 ann->print(std::cerr);
519 std::cerr << std::endl;
520 return INT_ASSIGN_MIN();
521 }
522
524 if (AST::Atom* s = dynamic_cast<AST::Atom*>(ann)) {
525 if ((s->id == "input_order") ||
526 (s->id == "first_fail") ||
527 (s->id == "anti_first_fail") ||
528 (s->id == "smallest") ||
529 (s->id == "largest") ||
530 (s->id == "max_regret"))
532 if ((s->id == "occurrence") ||
533 (s->id == "most_constrained"))
535 if (s->id == "random")
537 if ((s->id == "afc_min") ||
538 (s->id == "afc_size_min"))
540 if ((s->id == "afc_max") ||
541 (s->id == "afc_size_max") ||
542 (s->id == "dom_w_deg"))
544 if ((s->id == "action_min") &&
545 (s->id == "action_size_min"))
547 if ((s->id == "action_max") ||
548 (s->id == "action_size_max"))
550 }
551 std::cerr << "Warning, ignored search annotation: ";
552 ann->print(std::cerr);
553 std::cerr << std::endl;
555 }
556
557 BoolValBranch ann2bvalsel(AST::Node* ann, std::string& r0, std::string& r1,
558 Rnd rnd) {
559 if (AST::Atom* s = dynamic_cast<AST::Atom*>(ann)) {
560 if (s->id == "indomain_min") {
561 r0 = "="; r1 = "!=";
562 return BOOL_VAL_MIN();
563 }
564 if (s->id == "indomain_max") {
565 r0 = "="; r1 = "!=";
566 return BOOL_VAL_MAX();
567 }
568 if (s->id == "indomain_median") {
569 r0 = "="; r1 = "!=";
570 return BOOL_VAL_MIN();
571 }
572 if (s->id == "indomain_split") {
573 r0 = "<="; r1 = ">";
574 return BOOL_VAL_MIN();
575 }
576 if (s->id == "indomain_reverse_split") {
577 r0 = ">"; r1 = "<=";
578 return BOOL_VAL_MAX();
579 }
580 if (s->id == "indomain_random") {
581 r0 = "="; r1 = "!=";
582 return BOOL_VAL_RND(rnd);
583 }
584 if (s->id == "indomain") {
585 r0 = "="; r1 = "=";
586 return BOOL_VAL_MIN();
587 }
588 if (s->id == "indomain_middle") {
589 std::cerr << "Warning, replacing unsupported annotation "
590 << "indomain_middle with indomain_median" << std::endl;
591 r0 = "="; r1 = "!=";
592 return BOOL_VAL_MIN();
593 }
594 if (s->id == "indomain_interval") {
595 std::cerr << "Warning, replacing unsupported annotation "
596 << "indomain_interval with indomain_split" << std::endl;
597 r0 = "<="; r1 = ">";
598 return BOOL_VAL_MIN();
599 }
600 }
601 std::cerr << "Warning, ignored search annotation: ";
602 ann->print(std::cerr);
603 std::cerr << std::endl;
604 r0 = "="; r1 = "!=";
605 return BOOL_VAL_MIN();
606 }
607
609 if (AST::Atom* s = dynamic_cast<AST::Atom*>(ann)) {
610 if ((s->id == "indomain_min") ||
611 (s->id == "indomain_median"))
612 return BOOL_ASSIGN_MIN();
613 if (s->id == "indomain_max")
614 return BOOL_ASSIGN_MAX();
615 if (s->id == "indomain_random") {
616 return BOOL_ASSIGN_RND(rnd);
617 }
618 }
619 std::cerr << "Warning, ignored search annotation: ";
620 ann->print(std::cerr);
621 std::cerr << std::endl;
622 return BOOL_ASSIGN_MIN();
623 }
624
625#ifdef GECODE_HAS_SET_VARS
626 SetVarBranch ann2svarsel(AST::Node* ann, Rnd rnd, double decay) {
627 if (AST::Atom* s = dynamic_cast<AST::Atom*>(ann)) {
628 if (s->id == "input_order")
629 return SET_VAR_NONE();
630 if (s->id == "first_fail")
631 return SET_VAR_SIZE_MIN();
632 if (s->id == "anti_first_fail")
633 return SET_VAR_SIZE_MAX();
634 if (s->id == "smallest")
635 return SET_VAR_MIN_MIN();
636 if (s->id == "largest")
637 return SET_VAR_MAX_MAX();
638 if (s->id == "afc_min")
639 return SET_VAR_AFC_MIN(decay);
640 if (s->id == "afc_max")
641 return SET_VAR_AFC_MAX(decay);
642 if (s->id == "afc_size_min")
643 return SET_VAR_AFC_SIZE_MIN(decay);
644 if (s->id == "afc_size_max")
645 return SET_VAR_AFC_SIZE_MAX(decay);
646 if (s->id == "action_min")
647 return SET_VAR_ACTION_MIN(decay);
648 if (s->id == "action_max")
649 return SET_VAR_ACTION_MAX(decay);
650 if (s->id == "action_size_min")
651 return SET_VAR_ACTION_SIZE_MIN(decay);
652 if (s->id == "action_size_max")
653 return SET_VAR_ACTION_SIZE_MAX(decay);
654 if (s->id == "random") {
655 return SET_VAR_RND(rnd);
656 }
657 }
658 std::cerr << "Warning, ignored search annotation: ";
659 ann->print(std::cerr);
660 std::cerr << std::endl;
661 return SET_VAR_NONE();
662 }
663
664 SetValBranch ann2svalsel(AST::Node* ann, std::string r0, std::string r1,
665 Rnd rnd) {
666 (void) rnd;
667 if (AST::Atom* s = dynamic_cast<AST::Atom*>(ann)) {
668 if (s->id == "indomain_min") {
669 r0 = "in"; r1 = "not in";
670 return SET_VAL_MIN_INC();
671 }
672 if (s->id == "indomain_max") {
673 r0 = "in"; r1 = "not in";
674 return SET_VAL_MAX_INC();
675 }
676 if (s->id == "outdomain_min") {
677 r1 = "in"; r0 = "not in";
678 return SET_VAL_MIN_EXC();
679 }
680 if (s->id == "outdomain_max") {
681 r1 = "in"; r0 = "not in";
682 return SET_VAL_MAX_EXC();
683 }
684 }
685 std::cerr << "Warning, ignored search annotation: ";
686 ann->print(std::cerr);
687 std::cerr << std::endl;
688 r0 = "in"; r1 = "not in";
689 return SET_VAL_MIN_INC();
690 }
691#endif
692
693#ifdef GECODE_HAS_FLOAT_VARS
695 double decay) {
696 if (AST::Atom* s = dynamic_cast<AST::Atom*>(ann)) {
697 if (s->id == "input_order")
699 if (s->id == "first_fail")
701 if (s->id == "anti_first_fail")
703 if (s->id == "smallest")
705 if (s->id == "largest")
707 if (s->id == "occurrence")
709 if (s->id == "most_constrained")
712 if (s->id == "random") {
714 }
715 if (s->id == "afc_min")
717 if (s->id == "afc_max")
719 if (s->id == "afc_size_min")
721 if (s->id == "afc_size_max")
723 if (s->id == "action_min")
725 if (s->id == "action_max")
727 if (s->id == "action_size_min")
729 if (s->id == "action_size_max")
731 }
732 std::cerr << "Warning, ignored search annotation: ";
733 ann->print(std::cerr);
734 std::cerr << std::endl;
736 }
737
738 FloatValBranch ann2fvalsel(AST::Node* ann, std::string r0, std::string r1) {
739 if (AST::Atom* s = dynamic_cast<AST::Atom*>(ann)) {
740 if (s->id == "indomain_split") {
741 r0 = "<="; r1 = ">";
742 return FLOAT_VAL_SPLIT_MIN();
743 }
744 if (s->id == "indomain_reverse_split") {
745 r1 = "<="; r0 = ">";
746 return FLOAT_VAL_SPLIT_MAX();
747 }
748 }
749 std::cerr << "Warning, ignored search annotation: ";
750 ann->print(std::cerr);
751 std::cerr << std::endl;
752 r0 = "<="; r1 = ">";
753 return FLOAT_VAL_SPLIT_MIN();
754 }
755
756#endif
757
759 public:
761 typedef std::unordered_set<TupleSet> TupleSetSet;
764
766 typedef std::unordered_set<SharedArray<int> > IntSharedArraySet;
769
771 typedef std::unordered_set<DFA> DFASet;
774
777
780 };
781
783 : Space(f),
784 _initData(nullptr), _random(f._random),
785 _solveAnnotations(nullptr),
787 iv_boolalias(nullptr),
789 step(f.step),
790#endif
792 _optVar = f._optVar;
793 _optVarIsInt = f._optVarIsInt;
794 _method = f._method;
795 _lns = f._lns;
796 _lnsInitialSolution = f._lnsInitialSolution;
797 branchInfo = f.branchInfo;
798 iv.update(*this, f.iv);
799 iv_lns.update(*this, f.iv_lns);
800 intVarCount = f.intVarCount;
801
802 on_restart_iv.update(*this, f.on_restart_iv);
803 on_restart_bv.update(*this, f.on_restart_bv);
805 on_restart_sv.update(*this, f.on_restart_sv);
806#endif
808 on_restart_fv.update(*this, f.on_restart_fv);
809#endif
810 if (needAuxVars) {
811 IntVarArgs iva;
812 for (int i=0; i<f.iv_aux.size(); i++) {
813 if (!f.iv_aux[i].assigned()) {
814 iva << IntVar();
815 iva[iva.size()-1].update(*this, f.iv_aux[i]);
816 }
817 }
818 iv_aux = IntVarArray(*this, iva);
819 }
820
821 bv.update(*this, f.bv);
822 boolVarCount = f.boolVarCount;
823 if (needAuxVars) {
824 BoolVarArgs bva;
825 for (int i=0; i<f.bv_aux.size(); i++) {
826 if (!f.bv_aux[i].assigned()) {
827 bva << BoolVar();
828 bva[bva.size()-1].update(*this, f.bv_aux[i]);
829 }
830 }
831 bv_aux = BoolVarArray(*this, bva);
832 }
833
834#ifdef GECODE_HAS_SET_VARS
835 sv.update(*this, f.sv);
836 setVarCount = f.setVarCount;
837 if (needAuxVars) {
838 SetVarArgs sva;
839 for (int i=0; i<f.sv_aux.size(); i++) {
840 if (!f.sv_aux[i].assigned()) {
841 sva << SetVar();
842 sva[sva.size()-1].update(*this, f.sv_aux[i]);
843 }
844 }
845 sv_aux = SetVarArray(*this, sva);
846 }
847#endif
848#ifdef GECODE_HAS_FLOAT_VARS
849 fv.update(*this, f.fv);
850 floatVarCount = f.floatVarCount;
851 if (needAuxVars) {
852 FloatVarArgs fva;
853 for (int i=0; i<f.fv_aux.size(); i++) {
854 if (!f.fv_aux[i].assigned()) {
855 fva << FloatVar();
856 fva[fva.size()-1].update(*this, f.fv_aux[i]);
857 }
858 }
859 fv_aux = FloatVarArray(*this, fva);
860 }
861#endif
862 }
863
867 _optVar(-1), _optVarIsInt(true), _lns(0), _lnsInitialSolution(0),
868 _random(random),
869 _solveAnnotations(nullptr),
871 step(0.0),
872#endif
873 needAuxVars(true) {
874 branchInfo.init();
875 }
876
879 assert(s._initData != nullptr);
880 return s._initData->blackBoxContext;
881 }
882
883 void
884 FlatZincSpace::init(int intVars, int boolVars,
885 int setVars, int floatVars) {
886 (void) setVars;
887 (void) floatVars;
888
889 intVarCount = 0;
890 iv = IntVarArray(*this, intVars);
891 iv_introduced = std::vector<bool>(2*intVars);
892 iv_boolalias = alloc<int>(intVars+(intVars==0?1:0));
893 boolVarCount = 0;
894 bv = BoolVarArray(*this, boolVars);
895 bv_introduced = std::vector<bool>(2*boolVars);
896#ifdef GECODE_HAS_SET_VARS
897 setVarCount = 0;
898 sv = SetVarArray(*this, setVars);
899 sv_introduced = std::vector<bool>(2*setVars);
900#endif
901#ifdef GECODE_HAS_FLOAT_VARS
902 floatVarCount = 0;
903 fv = FloatVarArray(*this, floatVars);
904 fv_introduced = std::vector<bool>(2*floatVars);
905#endif
906 }
907
908 void
910 if (vs->alias) {
911 iv[intVarCount++] = iv[vs->i];
912 } else {
913 IntSet dom(vs2is(vs));
914 if (dom.size()==0) {
915 fail();
916 return;
917 } else {
918 iv[intVarCount++] = IntVar(*this, dom);
919 }
920 }
922 iv_introduced[2*(intVarCount-1)+1] = vs->funcDep;
924 }
925
926 void
930 int
934
935 void
937 if (vs->alias) {
938 bv[boolVarCount++] = bv[vs->i];
939 } else {
940 bv[boolVarCount++] = BoolVar(*this, vs2bsl(vs), vs2bsh(vs));
941 }
943 bv_introduced[2*(boolVarCount-1)+1] = vs->funcDep;
944 }
945
946#ifdef GECODE_HAS_SET_VARS
947 void
949 if (vs->alias) {
950 sv[setVarCount++] = sv[vs->i];
951 } else if (vs->assigned) {
952 assert(vs->upperBound());
953 AST::SetLit* vsv = vs->upperBound.some();
954 if (vsv->interval) {
955 IntSet d(vsv->min, vsv->max);
956 sv[setVarCount++] = SetVar(*this, d, d);
957 } else {
958 int* is = heap.alloc<int>(static_cast<unsigned long int>(vsv->s.size()));
959 for (int i=vsv->s.size(); i--; )
960 is[i] = vsv->s[i];
961 IntSet d(is, vsv->s.size());
962 heap.free(is,static_cast<unsigned long int>(vsv->s.size()));
963 sv[setVarCount++] = SetVar(*this, d, d);
964 }
965 } else if (vs->upperBound()) {
966 AST::SetLit* vsv = vs->upperBound.some();
967 if (vsv->interval) {
968 IntSet d(vsv->min, vsv->max);
969 sv[setVarCount++] = SetVar(*this, IntSet::empty, d);
970 } else {
971 int* is = heap.alloc<int>(static_cast<unsigned long int>(vsv->s.size()));
972 for (int i=vsv->s.size(); i--; )
973 is[i] = vsv->s[i];
974 IntSet d(is, vsv->s.size());
975 heap.free(is,static_cast<unsigned long int>(vsv->s.size()));
976 sv[setVarCount++] = SetVar(*this, IntSet::empty, d);
977 }
978 } else {
982 }
984 sv_introduced[2*(setVarCount-1)+1] = vs->funcDep;
985 }
986#else
987 void
989 throw FlatZinc::Error("Gecode", "set variables not supported");
990 }
991#endif
992
993#ifdef GECODE_HAS_FLOAT_VARS
994 void
996 if (vs->alias) {
997 fv[floatVarCount++] = fv[vs->i];
998 } else {
999 double dmin, dmax;
1000 if (vs->domain()) {
1001 dmin = vs->domain.some().first;
1002 dmax = vs->domain.some().second;
1003 if (dmin > dmax) {
1004 fail();
1005 return;
1006 }
1007 } else {
1008 dmin = Float::Limits::min;
1009 dmax = Float::Limits::max;
1010 }
1011 fv[floatVarCount++] = FloatVar(*this, dmin, dmax);
1012 }
1014 fv_introduced[2*(floatVarCount-1)+1] = vs->funcDep;
1015 }
1016#else
1017 void
1019 throw FlatZinc::Error("Gecode", "float variables not supported");
1020 }
1021#endif
1022
1023 namespace {
1024 struct ConExprOrder {
1025 bool operator() (ConExpr* ce0, ConExpr* ce1) {
1026 return ce0->args->a.size() < ce1->args->a.size();
1027 }
1028 };
1029 }
1030
1031 void
1032 FlatZincSpace::postConstraints(std::vector<ConExpr*>& ces) {
1033 ConExprOrder ceo;
1034 std::sort(ces.begin(), ces.end(), ceo);
1035
1036 for (unsigned int i=0; i<ces.size(); i++) {
1037 const ConExpr& ce = *ces[i];
1038 try {
1039 registry().post(*this, ce);
1040 } catch (Gecode::Exception& e) {
1041 throw FlatZinc::Error("Gecode", e.what(), ce.ann);
1042 } catch (AST::TypeError& e) {
1043 throw FlatZinc::Error("Type error", e.what(), ce.ann);
1044 }
1045 delete ces[i];
1046 ces[i] = nullptr;
1047 }
1048 }
1049
1050 void flattenAnnotations(AST::Array* ann, std::vector<AST::Node*>& out) {
1051 for (unsigned int i=0; i<ann->a.size(); i++) {
1052 if (ann->a[i]->isCall("seq_search")) {
1053 AST::Call* c = ann->a[i]->getCall();
1054 if (c->args->isArray())
1055 flattenAnnotations(c->args->getArray(), out);
1056 else
1057 out.push_back(c->args);
1058 } else {
1059 out.push_back(ann->a[i]);
1060 }
1061 }
1062 }
1063
1064 void
1066 bool ignoreUnknown,
1067 std::ostream& err) {
1068 int seed = opt.seed();
1069 double decay = opt.decay();
1070 Rnd rnd(static_cast<unsigned int>(seed));
1071 TieBreak<IntVarBranch> def_int_varsel = INT_VAR_AFC_SIZE_MAX(0.99);
1072 IntBoolVarBranch def_intbool_varsel = INTBOOL_VAR_AFC_SIZE_MAX(0.99);
1073 IntValBranch def_int_valsel = INT_VAL_MIN();
1074 std::string def_int_rel_left = "=";
1075 std::string def_int_rel_right = "!=";
1076 TieBreak<BoolVarBranch> def_bool_varsel = BOOL_VAR_AFC_MAX(0.99);
1077 BoolValBranch def_bool_valsel = BOOL_VAL_MIN();
1078 std::string def_bool_rel_left = "=";
1079 std::string def_bool_rel_right = "!=";
1080#ifdef GECODE_HAS_SET_VARS
1081 SetVarBranch def_set_varsel = SET_VAR_AFC_SIZE_MAX(0.99);
1082 SetValBranch def_set_valsel = SET_VAL_MIN_INC();
1083 std::string def_set_rel_left = "in";
1084 std::string def_set_rel_right = "not in";
1085#endif
1086#ifdef GECODE_HAS_FLOAT_VARS
1087 TieBreak<FloatVarBranch> def_float_varsel = FLOAT_VAR_SIZE_MIN();
1088 FloatValBranch def_float_valsel = FLOAT_VAL_SPLIT_MIN();
1089 std::string def_float_rel_left = "<=";
1090 std::string def_float_rel_right = ">";
1091#endif
1092
1093 std::vector<bool> iv_searched(iv.size());
1094 for (unsigned int i=iv.size(); i--;)
1095 iv_searched[i] = false;
1096 std::vector<bool> bv_searched(bv.size());
1097 for (unsigned int i=bv.size(); i--;)
1098 bv_searched[i] = false;
1099#ifdef GECODE_HAS_SET_VARS
1100 std::vector<bool> sv_searched(sv.size());
1101 for (unsigned int i=sv.size(); i--;)
1102 sv_searched[i] = false;
1103#endif
1104#ifdef GECODE_HAS_FLOAT_VARS
1105 std::vector<bool> fv_searched(fv.size());
1106 for (unsigned int i=fv.size(); i--;)
1107 fv_searched[i] = false;
1108#endif
1109
1110 _lns = 0;
1111 if (ann) {
1112 std::vector<AST::Node*> flatAnn;
1113 if (ann->isArray()) {
1114 flattenAnnotations(ann->getArray() , flatAnn);
1115 } else {
1116 flatAnn.push_back(ann);
1117 }
1118
1119 for (unsigned int i=0; i<flatAnn.size(); i++) {
1120 if (flatAnn[i]->isCall("restart_geometric")) {
1121 AST::Call* call = flatAnn[i]->getCall("restart_geometric");
1122 opt.restart(RM_GEOMETRIC);
1123 AST::Array* args = call->getArgs(2);
1124 opt.restart_base(args->a[0]->getFloat());
1125 opt.restart_scale(args->a[1]->getInt());
1126 } else if (flatAnn[i]->isCall("restart_luby")) {
1127 AST::Call* call = flatAnn[i]->getCall("restart_luby");
1128 opt.restart(RM_LUBY);
1129 opt.restart_scale(call->args->getInt());
1130 } else if (flatAnn[i]->isCall("restart_linear")) {
1131 AST::Call* call = flatAnn[i]->getCall("restart_linear");
1132 opt.restart(RM_LINEAR);
1133 opt.restart_scale(call->args->getInt());
1134 } else if (flatAnn[i]->isCall("restart_constant")) {
1135 AST::Call* call = flatAnn[i]->getCall("restart_constant");
1136 opt.restart(RM_CONSTANT);
1137 opt.restart_scale(call->args->getInt());
1138 } else if (flatAnn[i]->isCall("restart_none")) {
1139 opt.restart(RM_NONE);
1140 } else if (flatAnn[i]->isCall("relax_and_reconstruct")) {
1141 if (_lns != 0)
1142 throw FlatZinc::Error("FlatZinc",
1143 "Only one relax_and_reconstruct annotation allowed");
1144 AST::Call *call = flatAnn[i]->getCall("relax_and_reconstruct");
1145 AST::Array* args;
1146 if (call->args->getArray()->a.size()==2) {
1147 args = call->getArgs(2);
1148 } else {
1149 args = call->getArgs(3);
1150 }
1151 _lns = args->a[1]->getInt();
1152 AST::Array *vars = args->a[0]->getArray();
1153 int k=vars->a.size();
1154 for (int i=vars->a.size(); i--;)
1155 if (vars->a[i]->isInt())
1156 k--;
1157 iv_lns = IntVarArray(*this, k);
1158 k = 0;
1159 for (unsigned int i=0; i<vars->a.size(); i++) {
1160 if (vars->a[i]->isInt())
1161 continue;
1162 iv_lns[k++] = iv[vars->a[i]->getIntVar()];
1163 }
1164 if (args->a.size()==3) {
1165 AST::Array *initial = args->a[2]->getArray();
1166 _lnsInitialSolution = IntSharedArray(initial->a.size());
1167 for (unsigned int i=initial->a.size(); i--;)
1168 _lnsInitialSolution[i] = initial->a[i]->getInt();
1169 }
1170 } else if (flatAnn[i]->isCall("gecode_search")) {
1171 AST::Call* c = flatAnn[i]->getCall();
1172 branchWithPlugin(c->args);
1173 } else if (flatAnn[i]->isCall("int_search")) {
1174 AST::Call *call = flatAnn[i]->getCall("int_search");
1175 AST::Array *args = call->getArgs(4);
1176 AST::Array *vars = args->a[0]->getArray();
1177 int k=vars->a.size();
1178 for (int i=vars->a.size(); i--;)
1179 if (vars->a[i]->isInt())
1180 k--;
1181 IntVarArgs va(k);
1182 std::vector<std::string> names;
1183 k=0;
1184 for (unsigned int i=0; i<vars->a.size(); i++) {
1185 if (vars->a[i]->isInt())
1186 continue;
1187 va[k++] = iv[vars->a[i]->getIntVar()];
1188 iv_searched[vars->a[i]->getIntVar()] = true;
1189 names.push_back(vars->a[i]->getVarName());
1190 }
1191 std::string r0, r1;
1192 {
1193 BrancherGroup bg;
1194 branch(bg(*this), va,
1195 ann2ivarsel(args->a[1],rnd,decay),
1196 ann2ivalsel(args->a[2],r0,r1,rnd),
1197 nullptr,
1199 branchInfo.add(bg,r0,r1,names);
1200 }
1201 } else if (flatAnn[i]->isCall("int_assign")) {
1202 AST::Call *call = flatAnn[i]->getCall("int_assign");
1203 AST::Array *args = call->getArgs(2);
1204 AST::Array *vars = args->a[0]->getArray();
1205 int k=vars->a.size();
1206 for (int i=vars->a.size(); i--;)
1207 if (vars->a[i]->isInt())
1208 k--;
1209 IntVarArgs va(k);
1210 k=0;
1211 for (unsigned int i=0; i<vars->a.size(); i++) {
1212 if (vars->a[i]->isInt())
1213 continue;
1214 va[k++] = iv[vars->a[i]->getIntVar()];
1215 iv_searched[vars->a[i]->getIntVar()] = true;
1216 }
1217 assign(*this, va, ann2asnivalsel(args->a[1],rnd), nullptr,
1219 } else if (flatAnn[i]->isCall("bool_search")) {
1220 AST::Call *call = flatAnn[i]->getCall("bool_search");
1221 AST::Array *args = call->getArgs(4);
1222 AST::Array *vars = args->a[0]->getArray();
1223 int k=vars->a.size();
1224 for (int i=vars->a.size(); i--;)
1225 if (vars->a[i]->isBool())
1226 k--;
1227 BoolVarArgs va(k);
1228 k=0;
1229 std::vector<std::string> names;
1230 for (unsigned int i=0; i<vars->a.size(); i++) {
1231 if (vars->a[i]->isBool())
1232 continue;
1233 va[k++] = bv[vars->a[i]->getBoolVar()];
1234 bv_searched[vars->a[i]->getBoolVar()] = true;
1235 names.push_back(vars->a[i]->getVarName());
1236 }
1237
1238 std::string r0, r1;
1239 {
1240 BrancherGroup bg;
1241 branch(bg(*this), va,
1242 ann2bvarsel(args->a[1],rnd,decay),
1243 ann2bvalsel(args->a[2],r0,r1,rnd),
1244 nullptr,
1246 branchInfo.add(bg,r0,r1,names);
1247 }
1248 } else if (flatAnn[i]->isCall("int_default_search")) {
1249 AST::Call *call = flatAnn[i]->getCall("int_default_search");
1250 AST::Array *args = call->getArgs(2);
1251 def_int_varsel = ann2ivarsel(args->a[0],rnd,decay);
1252 def_int_valsel = ann2ivalsel(args->a[1],
1253 def_int_rel_left,def_int_rel_right,rnd);
1254 } else if (flatAnn[i]->isCall("bool_default_search")) {
1255 AST::Call *call = flatAnn[i]->getCall("bool_default_search");
1256 AST::Array *args = call->getArgs(2);
1257 def_bool_varsel = ann2bvarsel(args->a[0],rnd,decay);
1258 def_bool_valsel = ann2bvalsel(args->a[1],
1259 def_bool_rel_left,def_bool_rel_right,
1260 rnd);
1261 } else if (flatAnn[i]->isCall("set_search")) {
1262#ifdef GECODE_HAS_SET_VARS
1263 AST::Call *call = flatAnn[i]->getCall("set_search");
1264 AST::Array *args = call->getArgs(4);
1265 AST::Array *vars = args->a[0]->getArray();
1266 int k=vars->a.size();
1267 for (int i=vars->a.size(); i--;)
1268 if (vars->a[i]->isSet())
1269 k--;
1270 SetVarArgs va(k);
1271 k=0;
1272 std::vector<std::string> names;
1273 for (unsigned int i=0; i<vars->a.size(); i++) {
1274 if (vars->a[i]->isSet())
1275 continue;
1276 va[k++] = sv[vars->a[i]->getSetVar()];
1277 sv_searched[vars->a[i]->getSetVar()] = true;
1278 names.push_back(vars->a[i]->getVarName());
1279 }
1280 std::string r0, r1;
1281 {
1282 BrancherGroup bg;
1283 branch(bg(*this), va,
1284 ann2svarsel(args->a[1],rnd,decay),
1285 ann2svalsel(args->a[2],r0,r1,rnd),
1286 nullptr,
1288 branchInfo.add(bg,r0,r1,names);
1289 }
1290#else
1291 if (!ignoreUnknown) {
1292 err << "Warning, ignored search annotation: ";
1293 flatAnn[i]->print(err);
1294 err << std::endl;
1295 }
1296#endif
1297 } else if (flatAnn[i]->isCall("set_default_search")) {
1298#ifdef GECODE_HAS_SET_VARS
1299 AST::Call *call = flatAnn[i]->getCall("set_default_search");
1300 AST::Array *args = call->getArgs(2);
1301 def_set_varsel = ann2svarsel(args->a[0],rnd,decay);
1302 def_set_valsel = ann2svalsel(args->a[1],
1303 def_set_rel_left,def_set_rel_right,rnd);
1304#else
1305 if (!ignoreUnknown) {
1306 err << "Warning, ignored search annotation: ";
1307 flatAnn[i]->print(err);
1308 err << std::endl;
1309 }
1310#endif
1311 } else if (flatAnn[i]->isCall("float_default_search")) {
1312#ifdef GECODE_HAS_FLOAT_VARS
1313 AST::Call *call = flatAnn[i]->getCall("float_default_search");
1314 AST::Array *args = call->getArgs(2);
1315 def_float_varsel = ann2fvarsel(args->a[0],rnd,decay);
1316 def_float_valsel = ann2fvalsel(args->a[1],
1317 def_float_rel_left,def_float_rel_right);
1318#else
1319 if (!ignoreUnknown) {
1320 err << "Warning, ignored search annotation: ";
1321 flatAnn[i]->print(err);
1322 err << std::endl;
1323 }
1324#endif
1325 } else if (flatAnn[i]->isCall("float_search")) {
1326#ifdef GECODE_HAS_FLOAT_VARS
1327 AST::Call *call = flatAnn[i]->getCall("float_search");
1328 AST::Array *args = call->getArgs(5);
1329 AST::Array *vars = args->a[0]->getArray();
1330 int k=vars->a.size();
1331 for (int i=vars->a.size(); i--;)
1332 if (vars->a[i]->isFloat())
1333 k--;
1334 FloatVarArgs va(k);
1335 k=0;
1336 std::vector<std::string> names;
1337 for (unsigned int i=0; i<vars->a.size(); i++) {
1338 if (vars->a[i]->isFloat())
1339 continue;
1340 va[k++] = fv[vars->a[i]->getFloatVar()];
1341 fv_searched[vars->a[i]->getFloatVar()] = true;
1342 names.push_back(vars->a[i]->getVarName());
1343 }
1344 std::string r0, r1;
1345 {
1346 BrancherGroup bg;
1347 branch(bg(*this), va,
1348 ann2fvarsel(args->a[2],rnd,decay),
1349 ann2fvalsel(args->a[3],r0,r1),
1350 nullptr,
1351 &varValPrintF);
1352 branchInfo.add(bg,r0,r1,names);
1353 }
1354#else
1355 if (!ignoreUnknown) {
1356 err << "Warning, ignored search annotation: ";
1357 flatAnn[i]->print(err);
1358 err << std::endl;
1359 }
1360#endif
1361 } else {
1362 if (!ignoreUnknown) {
1363 err << "Warning, ignored search annotation: ";
1364 flatAnn[i]->print(err);
1365 err << std::endl;
1366 }
1367 }
1368 }
1369 }
1370 int introduced = 0;
1371 int funcdep = 0;
1372 int searched = 0;
1373 for (int i=iv.size(); i--;) {
1374 if (iv_searched[i] || (_method != SAT && _optVarIsInt && _optVar==i)) {
1375 searched++;
1376 } else if (iv_introduced[2*i]) {
1377 if (iv_introduced[2*i+1]) {
1378 funcdep++;
1379 } else {
1380 introduced++;
1381 }
1382 }
1383 }
1384 std::vector<std::string> iv_sol_names(iv.size()-(introduced+funcdep+searched));
1385 IntVarArgs iv_sol(iv.size()-(introduced+funcdep+searched));
1386 std::vector<std::string> iv_tmp_names(introduced);
1387 IntVarArgs iv_tmp(introduced);
1388 for (int i=iv.size(), j=0, k=0; i--;) {
1389 if (iv_searched[i] || (_method != SAT && _optVarIsInt && _optVar==i))
1390 continue;
1391 if (iv_introduced[2*i]) {
1392 if (!iv_introduced[2*i+1]) {
1393 iv_tmp_names[j] = p.intVarName(i);
1394 iv_tmp[j++] = iv[i];
1395 }
1396 } else {
1397 iv_sol_names[k] = p.intVarName(i);
1398 iv_sol[k++] = iv[i];
1399 }
1400 }
1401
1402 introduced = 0;
1403 funcdep = 0;
1404 searched = 0;
1405 for (int i=bv.size(); i--;) {
1406 if (bv_searched[i]) {
1407 searched++;
1408 } else if (bv_introduced[2*i]) {
1409 if (bv_introduced[2*i+1]) {
1410 funcdep++;
1411 } else {
1412 introduced++;
1413 }
1414 }
1415 }
1416 std::vector<std::string> bv_sol_names(bv.size()-(introduced+funcdep+searched));
1417 BoolVarArgs bv_sol(bv.size()-(introduced+funcdep+searched));
1418 BoolVarArgs bv_tmp(introduced);
1419 std::vector<std::string> bv_tmp_names(introduced);
1420 for (int i=bv.size(), j=0, k=0; i--;) {
1421 if (bv_searched[i])
1422 continue;
1423 if (bv_introduced[2*i]) {
1424 if (!bv_introduced[2*i+1]) {
1425 bv_tmp_names[j] = p.boolVarName(i);
1426 bv_tmp[j++] = bv[i];
1427 }
1428 } else {
1429 bv_sol_names[k] = p.boolVarName(i);
1430 bv_sol[k++] = bv[i];
1431 }
1432 }
1433
1434 if (iv_sol.size() > 0 && bv_sol.size() > 0) {
1435 branch(*this, iv_sol, bv_sol, def_intbool_varsel, def_int_valsel);
1436 } else if (iv_sol.size() > 0) {
1437 BrancherGroup bg;
1438 branch(bg(*this), iv_sol, def_int_varsel, def_int_valsel, nullptr,
1440 branchInfo.add(bg,def_int_rel_left,def_int_rel_right,iv_sol_names);
1441 } else if (bv_sol.size() > 0) {
1442 BrancherGroup bg;
1443 branch(bg(*this), bv_sol, def_bool_varsel, def_bool_valsel, nullptr,
1445 branchInfo.add(bg,def_bool_rel_left,def_bool_rel_right,bv_sol_names);
1446 }
1447#ifdef GECODE_HAS_FLOAT_VARS
1448 introduced = 0;
1449 funcdep = 0;
1450 searched = 0;
1451 for (int i=fv.size(); i--;) {
1452 if (fv_searched[i] || (_method != SAT && !_optVarIsInt && _optVar==i)) {
1453 searched++;
1454 } else if (fv_introduced[2*i]) {
1455 if (fv_introduced[2*i+1]) {
1456 funcdep++;
1457 } else {
1458 introduced++;
1459 }
1460 }
1461 }
1462 std::vector<std::string> fv_sol_names(fv.size()-(introduced+funcdep+searched));
1463 FloatVarArgs fv_sol(fv.size()-(introduced+funcdep+searched));
1464 FloatVarArgs fv_tmp(introduced);
1465 std::vector<std::string> fv_tmp_names(introduced);
1466 for (int i=fv.size(), j=0, k=0; i--;) {
1467 if (fv_searched[i] || (_method != SAT && !_optVarIsInt && _optVar==i))
1468 continue;
1469 if (fv_introduced[2*i]) {
1470 if (!fv_introduced[2*i+1]) {
1471 fv_tmp_names[j] = p.floatVarName(i);
1472 fv_tmp[j++] = fv[i];
1473 }
1474 } else {
1475 fv_sol_names[k] = p.floatVarName(i);
1476 fv_sol[k++] = fv[i];
1477 }
1478 }
1479
1480 if (fv_sol.size() > 0) {
1481 BrancherGroup bg;
1482 branch(bg(*this), fv_sol, def_float_varsel, def_float_valsel, nullptr,
1483 &varValPrintF);
1484 branchInfo.add(bg,def_float_rel_left,def_float_rel_right,fv_sol_names);
1485 }
1486#endif
1487#ifdef GECODE_HAS_SET_VARS
1488 introduced = 0;
1489 funcdep = 0;
1490 searched = 0;
1491 for (int i=sv.size(); i--;) {
1492 if (sv_searched[i]) {
1493 searched++;
1494 } else if (sv_introduced[2*i]) {
1495 if (sv_introduced[2*i+1]) {
1496 funcdep++;
1497 } else {
1498 introduced++;
1499 }
1500 }
1501 }
1502 std::vector<std::string> sv_sol_names(sv.size()-(introduced+funcdep+searched));
1503 SetVarArgs sv_sol(sv.size()-(introduced+funcdep+searched));
1504 SetVarArgs sv_tmp(introduced);
1505 std::vector<std::string> sv_tmp_names(introduced);
1506 for (int i=sv.size(), j=0, k=0; i--;) {
1507 if (sv_searched[i])
1508 continue;
1509 if (sv_introduced[2*i]) {
1510 if (!sv_introduced[2*i+1]) {
1511 sv_tmp_names[j] = p.setVarName(i);
1512 sv_tmp[j++] = sv[i];
1513 }
1514 } else {
1515 sv_sol_names[k] = p.setVarName(i);
1516 sv_sol[k++] = sv[i];
1517 }
1518 }
1519
1520 if (sv_sol.size() > 0) {
1521 BrancherGroup bg;
1522 branch(bg(*this), sv_sol, def_set_varsel, def_set_valsel, nullptr,
1524 branchInfo.add(bg,def_set_rel_left,def_set_rel_right,sv_sol_names);
1525
1526 }
1527#endif
1528 iv_aux = IntVarArray(*this, iv_tmp);
1529 bv_aux = BoolVarArray(*this, bv_tmp);
1530 int n_aux = iv_aux.size() + bv_aux.size();
1531#ifdef GECODE_HAS_SET_VARS
1532 sv_aux = SetVarArray(*this, sv_tmp);
1533 n_aux += sv_aux.size();
1534#endif
1535#ifdef GECODE_HAS_FLOAT_VARS
1536 fv_aux = FloatVarArray(*this, fv_tmp);
1537 n_aux += fv_aux.size();
1538#endif
1539
1540 if (n_aux > 0) {
1541 if (_method == SAT) {
1542 AuxVarBrancher::post(*this, def_int_varsel, def_int_valsel,
1543 def_bool_varsel, def_bool_valsel
1545 , def_set_varsel, def_set_valsel
1546#endif
1548 , def_float_varsel, def_float_valsel
1549#endif
1550 );
1551 } else {
1552 {
1553 BrancherGroup bg;
1554 branch(bg(*this),iv_aux,def_int_varsel,def_int_valsel, nullptr,
1556 branchInfo.add(bg,def_int_rel_left,def_int_rel_right,iv_tmp_names);
1557 }
1558 {
1559 BrancherGroup bg;
1560 branch(bg(*this),bv_aux,def_bool_varsel,def_bool_valsel, nullptr,
1562 branchInfo.add(bg,def_bool_rel_left,def_bool_rel_right,bv_tmp_names);
1563 }
1564 #ifdef GECODE_HAS_SET_VARS
1565 {
1566 BrancherGroup bg;
1567 branch(bg(*this),sv_aux,def_set_varsel,def_set_valsel, nullptr,
1569 branchInfo.add(bg,def_set_rel_left,def_set_rel_right,sv_tmp_names);
1570 }
1571 #endif
1572 #ifdef GECODE_HAS_FLOAT_VARS
1573 {
1574 BrancherGroup bg;
1575 branch(bg(*this),fv_aux,def_float_varsel,def_float_valsel, nullptr,
1576 &varValPrintF);
1577 branchInfo.add(bg,def_float_rel_left,def_float_rel_right,fv_tmp_names);
1578 }
1579 #endif
1580
1581 }
1582 }
1583
1584 if (_method == MIN) {
1585 if (_optVarIsInt) {
1586 std::vector<std::string> names(1);
1587 names[0] = p.intVarName(_optVar);
1588 BrancherGroup bg;
1589 branch(bg(*this), iv[_optVar], INT_VAL_MIN(),
1591 branchInfo.add(bg,"=","!=",names);
1592 } else {
1593#ifdef GECODE_HAS_FLOAT_VARS
1594 std::vector<std::string> names(1);
1595 names[0] = p.floatVarName(_optVar);
1596 BrancherGroup bg;
1597 branch(bg(*this), fv[_optVar], FLOAT_VAL_SPLIT_MIN(),
1598 &varValPrintF);
1599 branchInfo.add(bg,"<=",">",names);
1600#endif
1601 }
1602 } else if (_method == MAX) {
1603 if (_optVarIsInt) {
1604 std::vector<std::string> names(1);
1605 names[0] = p.intVarName(_optVar);
1606 BrancherGroup bg;
1607 branch(bg(*this), iv[_optVar], INT_VAL_MAX(),
1609 branchInfo.add(bg,"=","!=",names);
1610 } else {
1611#ifdef GECODE_HAS_FLOAT_VARS
1612 std::vector<std::string> names(1);
1613 names[0] = p.floatVarName(_optVar);
1614 BrancherGroup bg;
1615 branch(bg(*this), fv[_optVar], FLOAT_VAL_SPLIT_MAX(),
1616 &varValPrintF);
1617 branchInfo.add(bg,"<=",">",names);
1618#endif
1619 }
1620 }
1621
1622 }
1623
1624 AST::Array*
1626 return _solveAnnotations;
1627 }
1628
1629 void
1634
1635 void
1636 FlatZincSpace::minimize(int var, bool isInt, AST::Array* ann) {
1637 _method = MIN;
1638 _optVar = var;
1639 _optVarIsInt = isInt;
1640 _solveAnnotations = ann;
1641 }
1642
1643 void
1644 FlatZincSpace::maximize(int var, bool isInt, AST::Array* ann) {
1645 _method = MAX;
1646 _optVar = var;
1647 _optVarIsInt = isInt;
1648 _solveAnnotations = ann;
1649 }
1650
1652 delete _initData;
1653 delete _solveAnnotations;
1654 }
1655
1656#ifdef GECODE_HAS_GIST
1657
1661 template<class Engine>
1663 };
1664
1666 template<typename S>
1667 class GistEngine<DFS<S> > {
1668 public:
1669 static void explore(S* root, const FlatZincOptions& opt,
1672 o.c_d = opt.c_d(); o.a_d = opt.a_d();
1673 o.inspect.click(i);
1674 o.inspect.compare(c);
1675 (void) Gecode::Gist::dfs(root, o);
1676 }
1677 };
1678
1680 template<typename S>
1681 class GistEngine<BAB<S> > {
1682 public:
1683 static void explore(S* root, const FlatZincOptions& opt,
1686 o.c_d = opt.c_d(); o.a_d = opt.a_d();
1687 o.inspect.click(i);
1688 o.inspect.compare(c);
1689 (void) Gecode::Gist::bab(root, o);
1690 }
1691 };
1692
1694 template<class S>
1697 private:
1698 const Printer& p;
1699 public:
1701 FZPrintingInspector(const Printer& p0);
1703 virtual void inspect(const Space& node);
1705 virtual void finalize(void);
1706 };
1707
1708 template<class S>
1710 : TextOutput("Gecode/FlatZinc"), p(p0) {}
1711
1712 template<class S>
1713 void
1715 init();
1716 dynamic_cast<const S&>(node).print(getStream(), p);
1717 getStream() << std::endl;
1718 }
1719
1720 template<class S>
1721 void
1725
1726 template<class S>
1728 : public Gecode::Gist::VarComparator<S> {
1729 private:
1730 const Printer& p;
1731 public:
1733 FZPrintingComparator(const Printer& p0);
1734
1736 virtual void compare(const Space& s0, const Space& s1);
1737 };
1738
1739 template<class S>
1741 : Gecode::Gist::VarComparator<S>("Gecode/FlatZinc"), p(p0) {}
1742
1743 template<class S>
1744 void
1746 this->init();
1747 try {
1748 dynamic_cast<const S&>(s0).compare(dynamic_cast<const S&>(s1),
1749 this->getStream(), p);
1750 } catch (Exception& e) {
1751 this->getStream() << "Exception: " << e.what();
1752 }
1753 this->getStream() << std::endl;
1754 }
1755
1756#endif
1757
1759 protected:
1760 std::unique_ptr<Search::Stop> stop_object;
1762 public:
1764 const BlackBoxContextHandle& black_box_context0)
1765 : stop_object(stop_object0), black_box_context(black_box_context0) {}
1766 bool stop(const Search::Statistics& s, const Search::Options& o) override {
1767 return black_box_context.failed() ||
1768 ((stop_object.get() != nullptr) && stop_object->stop(s,o));
1769 }
1770 };
1771
1773 protected:
1775 public:
1776 explicit InterruptHandlerGuard(bool install) : installed(install) {
1777 if (installed)
1779 }
1784 };
1785
1786 template<template<class> class Engine>
1787 void
1788 FlatZincSpace::runEngine(std::ostream& out, const Printer& p,
1789 const FlatZincOptions& opt, Support::Timer& t_total) {
1790 if (opt.restart()==RM_NONE) {
1791 runMeta<Engine,Driver::EngineToMeta>(out,p,opt,t_total);
1792 } else {
1793 runMeta<Engine,RBS>(out,p,opt,t_total);
1794 }
1795 }
1796
1797#ifdef GECODE_HAS_CPPROFILER
1798
1800 public:
1801 const Printer& p;
1802 FlatZincGetInfo(const Printer& printer) : p(printer) {}
1803 virtual std::string
1804 getInfo(const Space& space) const {
1805 std::stringstream ss;
1806 if (const FlatZincSpace* fz_space = dynamic_cast<const FlatZincSpace*>(&space)) {
1807 ss << "{\n\t\"domains\": \"";
1808 ss << fz_space->getDomains(p);
1809 ss << "\"\n}";
1810 }
1811 return ss.str();
1812 }
1814 };
1815
1816 void printIntVar(std::ostream& os, const std::string name, const Int::IntView& x) {
1817 os << "var ";
1818 if (x.assigned()) {
1819 os << "int: " << name << " = " << x.val() << ";";
1820 } else if (x.range()) {
1821 os << x.min() << ".." << x.max() << ": " << name << ";";
1822 } else {
1823 os << "array_union([";
1825 while (true) {
1826 os << r.min() << ".." << r.max();
1827 ++r;
1828 if (!r()) break;
1829 os << ',';
1830 }
1831 os << "]): " << name << ";";
1832 }
1833 os << "\n";
1834 }
1835 void printBoolVar(std::ostream& os, const std::string name, const BoolVar& b) {
1836 os << "var bool: " << name;
1837 if(b.assigned())
1838 os << " = " << (b.val() ? "true" : "false");
1839 os << ";\n";
1840 }
1841#ifdef GECODE_HAS_FLOAT_VARS
1842 void printFloatVar(std::ostream& os, const std::string name, const Float::FloatView& f) {
1843 os << "var ";
1844 if(f.assigned())
1845 os << "float: " << name << " = " << f.med() << ";";
1846 else
1847 os << f.min() << ".." << f.max() << ": " << name << ";";
1848 os << "\n";
1849 }
1850#endif
1851 std::string FlatZincSpace::getDomains(const Printer& p) const {
1852 std::ostringstream oss;
1853
1854 for (int i = 0; i < iv.size(); i++)
1855 printIntVar(oss, p.intVarName(i), iv[i]);
1856
1857 for (int i = 0; i < bv.size(); i++)
1858 printBoolVar(oss, p.boolVarName(i), bv[i]);
1859
1860#ifdef GECODE_HAS_FLOAT_VARS
1861 for (int i = 0; i < fv.size(); i++)
1862 printFloatVar(oss, p.floatVarName(i), fv[i]);
1863#endif
1864#ifdef GECODE_HAS_SET_VARS
1865 for (int i = 0; i < sv.size(); i++)
1866 oss << "var " << sv[i] << ": " << p.setVarName(i) << ";" << std::endl;
1867#endif
1868
1869 return oss.str();
1870 }
1871
1872#endif
1873
1874 template<template<class> class Engine,
1875 template<class,template<class> class> class Meta>
1876 void
1877 FlatZincSpace::runMeta(std::ostream& out, const Printer& p,
1878 const FlatZincOptions& opt, Support::Timer& t_total) {
1879#ifdef GECODE_HAS_FLOAT_VARS
1880 step = opt.step();
1881#endif
1882#ifdef GECODE_HAS_GIST
1883 if (opt.mode() == SM_GIST) {
1884 BlackBoxContextHandle& black_box_context = BlackBoxAccess::context(*this);
1885 (void) status();
1886 black_box_context.rethrow();
1889 (void) GistEngine<Engine<FlatZincSpace> >::explore(this,opt,&pi,&pc);
1890 black_box_context.rethrow();
1891 return;
1892 }
1893#endif
1894 StatusStatistics sstat;
1895 unsigned int n_p = 0;
1896 Support::Timer t_solve;
1897 t_solve.start();
1898 if (status(sstat) != SS_FAILED) {
1899 n_p = PropagatorGroup::all.size(*this);
1900 }
1901 BlackBoxContextHandle& black_box_context = BlackBoxAccess::context(*this);
1902 black_box_context.rethrow();
1903 Search::Options o;
1904 std::unique_ptr<Search::Stop> stop(
1905 Driver::CombinedStop::create(opt.node(), opt.fail(), opt.time(),
1906 opt.restart_limit(), true));
1907 if (black_box_context) {
1908 stop.reset(new FlatZincStop(stop.release(), black_box_context));
1909 }
1910 o.stop = stop.get();
1911 std::unique_ptr<SearchTracer> tracer;
1912 o.c_d = opt.c_d();
1913 o.a_d = opt.a_d();
1914
1915#ifdef GECODE_HAS_CPPROFILER
1916 if (opt.profiler_port()) {
1917 FlatZincGetInfo* getInfo = nullptr;
1918 if (opt.profiler_info())
1919 getInfo = new FlatZincGetInfo(p);
1920 tracer.reset(new CPProfilerSearchTracer(opt.profiler_id(),
1921 opt.name(), opt.profiler_port(),
1922 getInfo));
1923 o.tracer = tracer.get();
1924 }
1925
1926#endif
1927
1928 o.threads = opt.threads();
1929 o.nogoods_limit = opt.nogoods() ? opt.nogoods_limit() : 0;
1930 if (opt.restart() != RM_NONE)
1931 o.cutoff = new Search::CutoffAppend(new Search::CutoffConstant(0), 1,
1932 Driver::createCutoff(opt));
1933 int noOfSolutions = opt.solutions();
1934 if (noOfSolutions == -1) {
1935 noOfSolutions = (_method == SAT) ? 1 : 0;
1936 }
1937 bool printAll = _method == SAT || opt.allSolutions() || noOfSolutions != 0;
1938 int findSol = noOfSolutions;
1939 bool solution_limit_reached = false;
1940 bool engine_stopped = false;
1941 Gecode::Search::Statistics stat;
1942 std::unique_ptr<FlatZincSpace> sol;
1943 {
1944 InterruptHandlerGuard interrupt_handler(opt.interrupt());
1945 Meta<FlatZincSpace,Engine> se(this,o);
1946 while (FlatZincSpace* next = se.next()) {
1947 std::unique_ptr<FlatZincSpace> next_sol(next);
1948 if (black_box_context.failed()) {
1949 break;
1950 }
1951 sol = std::move(next_sol);
1952 if (printAll) {
1953 sol->print(out, p);
1954 out << "----------" << std::endl;
1955 }
1956 if (--findSol == 0) {
1957 solution_limit_reached = true;
1958 break;
1959 }
1960 }
1961 engine_stopped = se.stopped();
1962 if (opt.mode() == SM_STAT) {
1963 stat = se.statistics();
1964 }
1965 }
1966 if (black_box_context.failed()) {
1967 sol.reset();
1968 black_box_context.rethrow();
1969 }
1970 if (sol && !printAll) {
1971 sol->print(out, p);
1972 out << "----------" << std::endl;
1973 }
1974 if (!solution_limit_reached) {
1975 if (!engine_stopped) {
1976 if (sol) {
1977 out << "==========" << std::endl;
1978 } else {
1979 out << "=====UNSATISFIABLE=====" << std::endl;
1980 }
1981 } else if (!sol) {
1982 out << "=====UNKNOWN=====" << std::endl;
1983 }
1984 }
1985 if (opt.mode() == SM_STAT) {
1986 double totalTime = (t_total.stop() / 1000.0);
1987 double solveTime = (t_solve.stop() / 1000.0);
1988 double initTime = totalTime - solveTime;
1989 out << std::endl
1990 << "%%%mzn-stat: initTime=" << initTime
1991 << std::endl;
1992 out << "%%%mzn-stat: solveTime=" << solveTime
1993 << std::endl;
1994 out << "%%%mzn-stat: solutions="
1995 << std::abs(noOfSolutions - findSol) << std::endl
1996 << "%%%mzn-stat: variables="
1997 << (intVarCount + boolVarCount + setVarCount) << std::endl
1998 << "%%%mzn-stat: propagators=" << n_p << std::endl
1999 << "%%%mzn-stat: propagations=" << sstat.propagate+stat.propagate << std::endl
2000 << "%%%mzn-stat: nodes=" << stat.node << std::endl
2001 << "%%%mzn-stat: failures=" << stat.fail << std::endl
2002 << "%%%mzn-stat: restarts=" << stat.restart << std::endl
2003 << "%%%mzn-stat: peakDepth=" << stat.depth << std::endl
2004 << "%%%mzn-stat-end" << std::endl
2005 << std::endl;
2006 }
2007 }
2008
2009#ifdef GECODE_HAS_QT
2010 void
2011 FlatZincSpace::branchWithPlugin(AST::Node* ann) {
2012 if (AST::Call* c = dynamic_cast<AST::Call*>(ann)) {
2013 QString pluginName(c->id.c_str());
2014 if (QLibrary::isLibrary(pluginName+".dll")) {
2015 pluginName += ".dll";
2016 } else if (QLibrary::isLibrary(pluginName+".dylib")) {
2017 pluginName = "lib" + pluginName + ".dylib";
2018 } else if (QLibrary::isLibrary(pluginName+".so")) {
2019 // Must check .so after .dylib so that Mac OS uses .dylib
2020 pluginName = "lib" + pluginName + ".so";
2021 }
2022 QPluginLoader pl(pluginName);
2023 QObject* plugin_o = pl.instance();
2024 if (!plugin_o) {
2025 throw FlatZinc::Error("FlatZinc",
2026 "Error loading plugin "+pluginName.toStdString()+
2027 ": "+pl.errorString().toStdString());
2028 }
2029 BranchPlugin* pb = qobject_cast<BranchPlugin*>(plugin_o);
2030 if (!pb) {
2031 throw FlatZinc::Error("FlatZinc",
2032 "Error loading plugin "+pluginName.toStdString()+
2033 ": does not contain valid PluginBrancher");
2034 }
2035 pb->branch(*this, c);
2036 }
2037 }
2038#else
2039 void
2040 FlatZincSpace::branchWithPlugin(AST::Node*) {
2041 throw FlatZinc::Error("FlatZinc",
2042 "Branching with plugins not supported (requires Qt support)");
2043 }
2044#endif
2045
2046 void
2047 FlatZincSpace::run(std::ostream& out, const Printer& p,
2048 const FlatZincOptions& opt, Support::Timer& t_total) {
2049#ifndef GECODE_HAS_GIST
2050 if (opt.mode() == SM_GIST)
2051 throw FlatZinc::Error("FlatZinc",
2052 "Gist mode is unavailable in this build");
2053#endif
2054 switch (_method) {
2055 case MIN:
2056 case MAX:
2057 runEngine<BAB>(out,p,opt,t_total);
2058 break;
2059 case SAT:
2060 runEngine<DFS>(out,p,opt,t_total);
2061 break;
2062 }
2063 }
2064
2065 void
2067 if (_optVarIsInt) {
2068 if (_method == MIN)
2069 rel(*this, iv[_optVar], IRT_LE,
2070 static_cast<const FlatZincSpace*>(&s)->iv[_optVar].val());
2071 else if (_method == MAX)
2072 rel(*this, iv[_optVar], IRT_GR,
2073 static_cast<const FlatZincSpace*>(&s)->iv[_optVar].val());
2074 } else {
2075#ifdef GECODE_HAS_FLOAT_VARS
2076 FloatVal best = static_cast<const FlatZincSpace*>(&s)->fv[_optVar].val();
2077 // When minimizing, an assigned objective is below best - step
2078 // exactly when its upper bound is below the lower bound of that
2079 // interval (symmetrically when maximizing). Posting this strict
2080 // bound prunes the incumbent value before the objective is
2081 // assigned, and also guarantees progress when it never is.
2082 if (_method == MIN) {
2083 FloatNum n = (best-step).min();
2084 if (n <= Float::Limits::min)
2085 fail();
2086 else
2087 rel(*this, fv[_optVar], FRT_LQ,
2088 std::nextafter(n, Float::Limits::min));
2089 } else if (_method == MAX) {
2090 FloatNum n = (best+step).max();
2091 if (n >= Float::Limits::max)
2092 fail();
2093 else
2094 rel(*this, fv[_optVar], FRT_GQ,
2095 std::nextafter(n, Float::Limits::max));
2096 }
2097#endif
2098 }
2099 }
2100
2101 bool
2103 if (mi.type() == MetaInfo::RESTART) {
2104 if (restart_data.initialized() && restart_data().mark_complete) {
2105 // Fail the space
2106 this->fail();
2107 // Return true to signal we are in the global search space
2108 return true;
2109 }
2110
2111 bool ret = false;
2112 if (on_restart_iv.size() > 0) {
2113 int base = 0;
2114
2115 // Assign the sol_int values (use lb if no solution is known)
2116 const FlatZincSpace* last = static_cast<const FlatZincSpace*>(mi.last());
2117 assert(last == nullptr || last->on_restart_iv.size() == restart_data().on_restart_iv_sol);
2118 for (int i = 0; i < restart_data().on_restart_iv_sol; ++i) {
2119 IntVar& outVar = on_restart_iv[base + restart_data().on_restart_iv_sol + i];
2120 int solVal = (last != nullptr) ? last->on_restart_iv[i].val() : on_restart_iv[base + i].min();
2121 rel(*this, outVar, IRT_EQ, solVal);
2122 }
2123 base += restart_data().on_restart_iv_sol * 2;
2124
2125 // Assign last_val_int values
2126 for (size_t i = 0; i < restart_data().last_val_int.size(); ++i) {
2127 rel(*this, on_restart_iv[base + i], IRT_EQ, restart_data().last_val_int[i]);
2128 }
2129 base += restart_data().last_val_int.size();
2130
2131 // Assign uniform_int random values
2132 for (size_t i = 0; i < restart_data().uniform_range_int.size(); ++i) {
2133 const auto& range = restart_data().uniform_range_int[i];
2134 const unsigned long long int width =
2135 static_cast<unsigned long long int>(
2136 static_cast<long long int>(range.second) -
2137 static_cast<long long int>(range.first)) + 1ULL;
2138 const int rndVal =
2139 static_cast<int>(static_cast<long long int>(range.first) +
2140 static_cast<long long int>(_random(width)));
2141 rel(*this, on_restart_iv[base + i], IRT_EQ, rndVal);
2142 }
2143 base += restart_data().uniform_range_int.size();
2144
2145 // Set the status value
2146 if (restart_data().on_restart_status) {
2147 assert(base == on_restart_iv.size() - 1);
2148 IntVar& restart_status = on_restart_iv[base];
2149 switch(mi.reason()) {
2150 case MetaInfo::RR_INIT:
2151 assert(!mi.last());
2152 rel(*this, restart_status, IRT_EQ, 1); // 1: START
2153 break;
2154 case MetaInfo::RR_SOL:
2155 assert(mi.solution() > 0);
2156 rel(*this, restart_status, IRT_EQ, 4); // 4: SAT
2157 break;
2158 case MetaInfo::RR_CMPL:
2159 rel(*this, restart_status, IRT_EQ, 3); // 3: UNSAT
2160 break;
2161 default:
2162 assert(mi.reason() == MetaInfo::RR_LIM);
2163 rel(*this, restart_status, IRT_EQ, 2); // 2: UNKNOWN
2164 break;
2165 }
2166 base += 1;
2167 }
2168 assert(base == on_restart_iv.size());
2169
2170 // Reduce on_restart_iv to only the variables required in a solution
2171 IntVarArray tmp(*this, restart_data().on_restart_iv_sol);
2172 for (int i = 0; i < restart_data().on_restart_iv_sol; ++i) {
2173 tmp[i] = on_restart_iv[i];
2174 }
2175 on_restart_iv = tmp;
2176
2177 ret = true;
2178 }
2179 if (on_restart_bv.size() > 0) {
2180 int base = 0;
2181
2182 // Assign the sol_bool values (use lb if no solution is known)
2183 const FlatZincSpace* last = static_cast<const FlatZincSpace*>(mi.last());
2184 assert(last == nullptr || last->on_restart_bv.size() == restart_data().on_restart_bv_sol);
2185 for (int i = 0; i < restart_data().on_restart_bv_sol; ++i) {
2186 BoolVar& outVar = on_restart_bv[base + restart_data().on_restart_bv_sol + i];
2187 int solVal = (last != nullptr) ? last->on_restart_bv[i].val() : on_restart_bv[base + i].min();
2188 rel(*this, outVar, IRT_EQ, solVal);
2189 }
2190 base += restart_data().on_restart_bv_sol * 2;
2191
2192 // Assign last_val_bool values
2193 for (size_t i = 0; i < restart_data().last_val_bool.size(); ++i) {
2194 rel(*this, on_restart_bv[base + i], IRT_EQ, restart_data().last_val_bool[i]);
2195 }
2196 base += restart_data().last_val_bool.size();
2197 assert(base == on_restart_bv.size());
2198
2199 // Reduce on_restart_bv to only the variables required in a solution
2200 BoolVarArray tmp(*this, restart_data().on_restart_bv_sol);
2201 for (int i = 0; i < restart_data().on_restart_bv_sol; ++i) {
2202 tmp[i] = on_restart_bv[i];
2203 }
2204 on_restart_bv = tmp;
2205
2206 ret = true;
2207 }
2208#ifdef GECODE_HAS_SET_VARS
2209 if (on_restart_sv.size() > 0) {
2210 int base = 0;
2211
2212 // Assign the sol_set values (use lb if no solution is known)
2213 const FlatZincSpace* last = static_cast<const FlatZincSpace*>(mi.last());
2214 assert(last == nullptr || last->on_restart_sv.size() == restart_data().on_restart_sv_sol);
2215 for (int i = 0; i < restart_data().on_restart_sv_sol; ++i) {
2216 SetVar& outVar = on_restart_sv[base + restart_data().on_restart_sv_sol + i];
2217 Set::GlbRanges<Set::SetView> lb(last != nullptr ? last->on_restart_sv[i] : on_restart_sv[base + i]);
2218 IntSet val(lb);
2219 dom(*this, outVar, SRT_EQ, val);
2220 }
2221 base += restart_data().on_restart_sv_sol * 2;
2222
2223 // Assign last_val_set values
2224 for (size_t i = 0; i < restart_data().last_val_set.size(); ++i) {
2225 dom(*this, on_restart_sv[base + i], SRT_EQ, restart_data().last_val_set[i]);
2226 }
2227 base += restart_data().last_val_set.size();
2228 assert(base == on_restart_sv.size());
2229
2230 // Reduce on_restart_sv to only the variables required in a solution
2231 SetVarArray tmp(*this, restart_data().on_restart_sv_sol);
2232 for (int i = 0; i < restart_data().on_restart_sv_sol; ++i) {
2233 tmp[i] = on_restart_sv[i];
2234 }
2235 on_restart_sv = tmp;
2236
2237 ret = true;
2238 }
2239#endif
2240#ifdef GECODE_HAS_FLOAT_VARS
2241 if (on_restart_fv.size() > 0) {
2242 int base = 0;
2243
2244 // Assign the sol_float values (use lb if no solution is known)
2245 const FlatZincSpace* last = static_cast<const FlatZincSpace*>(mi.last());
2246 assert(last == nullptr || last->on_restart_fv.size() == restart_data().on_restart_fv_sol);
2247 for (int i = 0; i < restart_data().on_restart_fv_sol; ++i) {
2248 FloatVar& outVar = on_restart_fv[base + restart_data().on_restart_fv_sol + i];
2249 FloatVal solVal = (last != nullptr) ? last->on_restart_fv[i].val() : on_restart_fv[base + i].min();
2250 rel(*this, outVar, FRT_EQ, solVal);
2251 }
2252 base += restart_data().on_restart_fv_sol * 2;
2253
2254 // Assign last_val_float values
2255 for (size_t i = 0; i < restart_data().last_val_float.size(); ++i) {
2256 rel(*this, on_restart_fv[base + i], FRT_EQ, restart_data().last_val_float[i]);
2257 }
2258 base += restart_data().last_val_float.size();
2259
2260 // Assign uniform_float random values
2261 for (size_t i = 0; i < restart_data().uniform_range_float.size(); ++i) {
2262 const auto& range = restart_data().uniform_range_float[i];
2263 /* rndVal will be an element of [range.first, range.second] */
2264 const FloatVal rndVal =
2265 (static_cast<FloatVal>(_random(INT_MAX)) /
2266 static_cast<FloatVal>(INT_MAX - 1)) *
2267 (range.second - range.first) + range.first;
2268 rel(*this, on_restart_fv[base + i], FRT_EQ, rndVal);
2269 }
2270 base += restart_data().uniform_range_float.size();
2271 assert(base == on_restart_fv.size());
2272
2273 // Reduce on_restart_fv to only the variables required in a solution
2274 FloatVarArray tmp(*this, restart_data().on_restart_fv_sol);
2275 for (int i = 0; i < restart_data().on_restart_fv_sol; ++i) {
2276 tmp[i] = on_restart_fv[i];
2277 }
2278 on_restart_fv = tmp;
2279
2280 ret = true;
2281 }
2282#endif
2283 if (ret) {
2284 return false;
2285 }
2286 }
2287
2288 if ((mi.type() == MetaInfo::RESTART) && (mi.restart() != 0) &&
2289 (_lns > 0) && (mi.last()==nullptr) && (_lnsInitialSolution.size()>0)) {
2290 for (unsigned int i=iv_lns.size(); i--;) {
2291 if (_random(99U) <= _lns) {
2292 rel(*this, iv_lns[i], IRT_EQ, _lnsInitialSolution[i]);
2293 }
2294 }
2295 return false;
2296 } else if ((mi.type() == MetaInfo::RESTART) && (mi.restart() != 0) &&
2297 (_lns > 0) && mi.last()) {
2298 const FlatZincSpace& last =
2299 static_cast<const FlatZincSpace&>(*mi.last());
2300 for (unsigned int i=iv_lns.size(); i--;) {
2301 if (_random(99U) <= _lns) {
2302 rel(*this, iv_lns[i], IRT_EQ, last.iv_lns[i]);
2303 }
2304 }
2305 return false;
2306 }
2307 return true;
2308 }
2309
2310 Space*
2312 return new FlatZincSpace(*this);
2313 }
2314
2317 return _method;
2318 }
2319
2320 int
2322 return _optVar;
2323 }
2324
2325 bool
2327 return _optVarIsInt;
2328 }
2329
2330 void
2331 FlatZincSpace::print(std::ostream& out, const Printer& p) const {
2332 p.print(out, iv, bv
2334 , sv
2335#endif
2337 , fv
2338#endif
2339 );
2340 }
2341
2342 void
2343 FlatZincSpace::compare(const Space& s, std::ostream& out) const {
2344 (void) s; (void) out;
2345#ifdef GECODE_HAS_GIST
2346 const FlatZincSpace& fs = dynamic_cast<const FlatZincSpace&>(s);
2347 for (int i = 0; i < iv.size(); ++i) {
2348 std::stringstream ss;
2349 ss << "iv[" << i << "]";
2350 std::string result(Gecode::Gist::Comparator::compare(ss.str(), iv[i],
2351 fs.iv[i]));
2352 if (result.length() > 0) out << result << std::endl;
2353 }
2354 for (int i = 0; i < bv.size(); ++i) {
2355 std::stringstream ss;
2356 ss << "bv[" << i << "]";
2357 std::string result(Gecode::Gist::Comparator::compare(ss.str(), bv[i],
2358 fs.bv[i]));
2359 if (result.length() > 0) out << result << std::endl;
2360 }
2361#ifdef GECODE_HAS_SET_VARS
2362 for (int i = 0; i < sv.size(); ++i) {
2363 std::stringstream ss;
2364 ss << "sv[" << i << "]";
2365 std::string result(Gecode::Gist::Comparator::compare(ss.str(), sv[i],
2366 fs.sv[i]));
2367 if (result.length() > 0) out << result << std::endl;
2368 }
2369#endif
2370#ifdef GECODE_HAS_FLOAT_VARS
2371 for (int i = 0; i < fv.size(); ++i) {
2372 std::stringstream ss;
2373 ss << "fv[" << i << "]";
2374 std::string result(Gecode::Gist::Comparator::compare(ss.str(), fv[i],
2375 fs.fv[i]));
2376 if (result.length() > 0) out << result << std::endl;
2377 }
2378#endif
2379#endif
2380 }
2381
2382 void
2383 FlatZincSpace::compare(const FlatZincSpace& s, std::ostream& out,
2384 const Printer& p) const {
2385 p.printDiff(out, iv, s.iv, bv, s.bv
2387 , sv, s.sv
2388#endif
2390 , fv, s.fv
2391#endif
2392 );
2393 }
2394
2395 void
2397 p.shrinkArrays(*this, _optVar, _optVarIsInt, iv, bv
2399 , sv
2400#endif
2402 , fv
2403#endif
2404 );
2405 }
2406
2407 IntArgs
2409 AST::Array* a = arg->getArray();
2410 IntArgs ia(a->a.size()+offset);
2411 for (int i=offset; i--;)
2412 ia[i] = 0;
2413 for (int i=a->a.size(); i--;)
2414 ia[i+offset] = a->a[i]->getInt();
2415 return ia;
2416 }
2417 TupleSet
2418 FlatZincSpace::arg2tupleset(const IntArgs& a, int noOfVars) {
2419 int noOfTuples = a.size() == 0 ? 0 : (a.size()/noOfVars);
2420
2421 // Build TupleSet
2422 TupleSet ts(noOfVars);
2423 for (int i=0; i<noOfTuples; i++) {
2424 IntArgs t(noOfVars);
2425 for (int j=0; j<noOfVars; j++) {
2426 t[j] = a[i*noOfVars+j];
2427 }
2428 ts.add(t);
2429 }
2430 ts.finalize(EPK_AUTO);
2431
2432 if (_initData) {
2433 FlatZincSpaceInitData::TupleSetSet::iterator it = _initData->tupleSetSet.find(ts);
2434 if (it != _initData->tupleSetSet.end()) {
2435 return *it;
2436 }
2437 _initData->tupleSetSet.insert(ts);
2438 }
2439
2440
2441 return ts;
2442 }
2445 IntArgs ia(arg2intargs(arg,offset));
2446 SharedArray<int> sia(ia);
2447 if (_initData) {
2448 FlatZincSpaceInitData::IntSharedArraySet::iterator it = _initData->intSharedArraySet.find(sia);
2449 if (it != _initData->intSharedArraySet.end()) {
2450 return *it;
2451 }
2452 _initData->intSharedArraySet.insert(sia);
2453 }
2454
2455 return sia;
2456 }
2457 IntArgs
2459 AST::Array* a = arg->getArray();
2460 IntArgs ia(a->a.size()+offset);
2461 for (int i=offset; i--;)
2462 ia[i] = 0;
2463 for (int i=a->a.size(); i--;)
2464 ia[i+offset] = a->a[i]->getBool();
2465 return ia;
2466 }
2469 IntArgs ia(arg2boolargs(arg,offset));
2470 SharedArray<int> sia(ia);
2471 if (_initData) {
2472 FlatZincSpaceInitData::IntSharedArraySet::iterator it = _initData->intSharedArraySet.find(sia);
2473 if (it != _initData->intSharedArraySet.end()) {
2474 return *it;
2475 }
2476 _initData->intSharedArraySet.insert(sia);
2477 }
2478
2479 return sia;
2480 }
2481 IntSet
2483 AST::SetLit* sl = n->getSet();
2484 IntSet d;
2485 if (sl->interval) {
2486 d = IntSet(sl->min, sl->max);
2487 } else {
2488 Region re;
2489 int* is = re.alloc<int>(static_cast<unsigned long int>(sl->s.size()));
2490 for (int i=sl->s.size(); i--; )
2491 is[i] = sl->s[i];
2492 d = IntSet(is, sl->s.size());
2493 }
2494 return d;
2495 }
2498 AST::Array* a = arg->getArray();
2499 if (a->a.size() == 0) {
2500 IntSetArgs emptyIa(0);
2501 return emptyIa;
2502 }
2503 IntSetArgs ia(a->a.size()+offset);
2504 for (int i=offset; i--;)
2505 ia[i] = IntSet::empty;
2506 for (int i=a->a.size(); i--;) {
2507 ia[i+offset] = arg2intset(a->a[i]);
2508 }
2509 return ia;
2510 }
2513 AST::Array* a = arg->getArray();
2514 if (a->a.size() == 0) {
2515 IntVarArgs emptyIa(0);
2516 return emptyIa;
2517 }
2518 IntVarArgs ia(a->a.size()+offset);
2519 for (int i=offset; i--;)
2520 ia[i] = IntVar(*this, 0, 0);
2521 for (int i=a->a.size(); i--;) {
2522 if (a->a[i]->isIntVar()) {
2523 ia[i+offset] = iv[a->a[i]->getIntVar()];
2524 } else {
2525 int value = a->a[i]->getInt();
2526 IntVar iv(*this, value, value);
2527 ia[i+offset] = iv;
2528 }
2529 }
2530 return ia;
2531 }
2533 FlatZincSpace::arg2boolvarargs(AST::Node* arg, int offset, int siv) {
2534 AST::Array* a = arg->getArray();
2535 if (a->a.size() == 0) {
2536 BoolVarArgs emptyIa(0);
2537 return emptyIa;
2538 }
2539 BoolVarArgs ia(a->a.size()+offset-(siv==-1?0:1));
2540 for (int i=offset; i--;)
2541 ia[i] = BoolVar(*this, 0, 0);
2542 for (int i=0; i<static_cast<int>(a->a.size()); i++) {
2543 if (i==siv)
2544 continue;
2545 if (a->a[i]->isBool()) {
2546 bool value = a->a[i]->getBool();
2547 BoolVar iv(*this, value, value);
2548 ia[offset++] = iv;
2549 } else if (a->a[i]->isIntVar() &&
2550 aliasBool2Int(a->a[i]->getIntVar()) != -1) {
2551 ia[offset++] = bv[aliasBool2Int(a->a[i]->getIntVar())];
2552 } else {
2553 ia[offset++] = bv[a->a[i]->getBoolVar()];
2554 }
2555 }
2556 return ia;
2557 }
2558 BoolVar
2560 BoolVar x0;
2561 if (n->isBool()) {
2562 x0 = BoolVar(*this, n->getBool(), n->getBool());
2563 }
2564 else {
2565 x0 = bv[n->getBoolVar()];
2566 }
2567 return x0;
2568 }
2569 IntVar
2571 IntVar x0;
2572 if (n->isIntVar()) {
2573 x0 = iv[n->getIntVar()];
2574 } else {
2575 x0 = IntVar(*this, n->getInt(), n->getInt());
2576 }
2577 return x0;
2578 }
2579 bool
2581 AST::Array* a = b->getArray();
2582 singleInt = -1;
2583 if (a->a.size() == 0)
2584 return true;
2585 for (int i=a->a.size(); i--;) {
2586 if (a->a[i]->isBoolVar() || a->a[i]->isBool()) {
2587 } else if (a->a[i]->isIntVar()) {
2588 if (aliasBool2Int(a->a[i]->getIntVar()) == -1) {
2589 if (singleInt != -1) {
2590 return false;
2591 }
2592 singleInt = i;
2593 }
2594 } else {
2595 return false;
2596 }
2597 }
2598 return singleInt==-1 || a->a.size() > 1;
2599 }
2600#ifdef GECODE_HAS_SET_VARS
2601 SetVar
2603 SetVar x0;
2604 if (!n->isSetVar()) {
2605 IntSet d = arg2intset(n);
2606 x0 = SetVar(*this, d, d);
2607 } else {
2608 x0 = sv[n->getSetVar()];
2609 }
2610 return x0;
2611 }
2613 FlatZincSpace::arg2setvarargs(AST::Node* arg, int offset, int doffset,
2614 const IntSet& od) {
2615 AST::Array* a = arg->getArray();
2616 SetVarArgs ia(a->a.size()+offset);
2617 for (int i=offset; i--;) {
2618 IntSet d = i<doffset ? od : IntSet::empty;
2619 ia[i] = SetVar(*this, d, d);
2620 }
2621 for (int i=a->a.size(); i--;) {
2622 ia[i+offset] = arg2SetVar(a->a[i]);
2623 }
2624 return ia;
2625 }
2626#endif
2627#ifdef GECODE_HAS_FLOAT_VARS
2630 AST::Array* a = arg->getArray();
2631 FloatValArgs fa(a->a.size()+offset);
2632 for (int i=offset; i--;)
2633 fa[i] = 0.0;
2634 for (int i=a->a.size(); i--;)
2635 fa[i+offset] = a->a[i]->getFloat();
2636 return fa;
2637 }
2640 AST::Array* a = arg->getArray();
2641 if (a->a.size() == 0) {
2642 FloatVarArgs emptyFa(0);
2643 return emptyFa;
2644 }
2645 FloatVarArgs fa(a->a.size()+offset);
2646 for (int i=offset; i--;)
2647 fa[i] = FloatVar(*this, 0.0, 0.0);
2648 for (int i=a->a.size(); i--;) {
2649 if (a->a[i]->isFloatVar()) {
2650 fa[i+offset] = fv[a->a[i]->getFloatVar()];
2651 } else {
2652 double value = a->a[i]->getFloat();
2653 FloatVar fv(*this, value, value);
2654 fa[i+offset] = fv;
2655 }
2656 }
2657 return fa;
2658 }
2659 FloatVar
2661 FloatVar x0;
2662 if (n->isFloatVar()) {
2663 x0 = fv[n->getFloatVar()];
2664 } else {
2665 x0 = FloatVar(*this, n->getFloat(), n->getFloat());
2666 }
2667 return x0;
2668 }
2669#endif
2672 int ipl = IPL_DEF;
2673 if (ann) {
2674 if (ann->hasAtom("val") || ann->hasAtom("value_propagation"))
2675 ipl = IPL_VAL;
2676 else if (ann->hasAtom("domain") || ann->hasAtom("domain_propagation"))
2677 ipl = IPL_DOM;
2678 else if (ann->hasAtom("bounds") ||
2679 ann->hasAtom("bounds_propagation") ||
2680 ann->hasAtom("boundsR") ||
2681 ann->hasAtom("boundsD") ||
2682 ann->hasAtom("boundsZ"))
2683 ipl = IPL_BND;
2684 if (ann->hasAtom("gecode_full_propagation"))
2685 ipl |= IPL_FULL;
2686 else {
2687 if (ann->hasAtom("gecode_basic_propagation"))
2688 ipl |= IPL_BASIC;
2689 if (ann->hasAtom("gecode_advanced_propagation"))
2690 ipl |= IPL_ADVANCED;
2691 }
2692 }
2693 return static_cast<IntPropLevel>(ipl);
2694 }
2695
2696 DFA
2698 if (_initData) {
2699 FlatZincSpaceInitData::DFASet::iterator it = _initData->dfaSet.find(a);
2700 if (it != _initData->dfaSet.end()) {
2701 return *it;
2702 }
2703 _initData->dfaSet.insert(a);
2704 }
2705 return a;
2706 }
2707
2708 void
2710 _output = output;
2711 }
2712
2713 void
2714 Printer::printElem(std::ostream& out,
2715 AST::Node* ai,
2716 const Gecode::IntVarArray& iv,
2717 const Gecode::BoolVarArray& bv
2719 , const Gecode::SetVarArray& sv
2720#endif
2722 ,
2723 const Gecode::FloatVarArray& fv
2724#endif
2725 ) const {
2726 int k;
2727 if (ai->isInt(k)) {
2728 out << k;
2729 } else if (ai->isIntVar()) {
2730 out << iv[ai->getIntVar()];
2731 } else if (ai->isBoolVar()) {
2732 if (bv[ai->getBoolVar()].min() == 1) {
2733 out << "true";
2734 } else if (bv[ai->getBoolVar()].max() == 0) {
2735 out << "false";
2736 } else {
2737 out << "false..true";
2738 }
2739#ifdef GECODE_HAS_SET_VARS
2740 } else if (ai->isSetVar()) {
2741 if (!sv[ai->getSetVar()].assigned()) {
2742 out << sv[ai->getSetVar()];
2743 return;
2744 }
2745 SetVarGlbRanges svr(sv[ai->getSetVar()]);
2746 if (!svr()) {
2747 out << "{}";
2748 return;
2749 }
2750 int min = svr.min();
2751 int max = svr.max();
2752 ++svr;
2753 if (svr()) {
2754 SetVarGlbValues svv(sv[ai->getSetVar()]);
2755 int i = svv.val();
2756 out << "{" << i;
2757 ++svv;
2758 for (; svv(); ++svv)
2759 out << ", " << svv.val();
2760 out << "}";
2761 } else {
2762 out << min << ".." << max;
2763 }
2764#endif
2765#ifdef GECODE_HAS_FLOAT_VARS
2766 } else if (ai->isFloatVar()) {
2767 if (fv[ai->getFloatVar()].assigned()) {
2768 FloatVal vv = fv[ai->getFloatVar()].val();
2769 FloatNum v;
2770 if (vv.singleton())
2771 v = vv.min();
2772 else if (vv < 0.0)
2773 v = vv.max();
2774 else
2775 v = vv.min();
2776 std::ostringstream oss;
2777 // oss << std::scientific;
2778 oss << std::setprecision(std::numeric_limits<double>::digits10);
2779 oss << v;
2780 if (oss.str().find(".") == std::string::npos)
2781 oss << ".0";
2782 out << oss.str();
2783 } else {
2784 out << fv[ai->getFloatVar()];
2785 }
2786#endif
2787 } else if (ai->isBool()) {
2788 out << (ai->getBool() ? "true" : "false");
2789 } else if (ai->isSet()) {
2790 AST::SetLit* s = ai->getSet();
2791 if (s->interval) {
2792 out << s->min << ".." << s->max;
2793 } else {
2794 out << "{";
2795 for (unsigned int i=0; i<s->s.size(); i++) {
2796 out << s->s[i] << (i < s->s.size()-1 ? ", " : "}");
2797 }
2798 }
2799 } else if (ai->isString()) {
2800 std::string s = ai->getString();
2801 for (unsigned int i=0; i<s.size(); i++) {
2802 if (s[i] == '\\' && i<s.size()-1) {
2803 switch (s[i+1]) {
2804 case 'n': out << "\n"; break;
2805 case '\\': out << "\\"; break;
2806 case 't': out << "\t"; break;
2807 default: out << "\\" << s[i+1];
2808 }
2809 i++;
2810 } else {
2811 out << s[i];
2812 }
2813 }
2814 }
2815 }
2816
2817 void
2818 Printer::printElemDiff(std::ostream& out,
2819 AST::Node* ai,
2820 const Gecode::IntVarArray& iv1,
2821 const Gecode::IntVarArray& iv2,
2822 const Gecode::BoolVarArray& bv1,
2823 const Gecode::BoolVarArray& bv2
2825 , const Gecode::SetVarArray& sv1,
2826 const Gecode::SetVarArray& sv2
2827#endif
2829 , const Gecode::FloatVarArray& fv1,
2830 const Gecode::FloatVarArray& fv2
2831#endif
2832 ) const {
2833#ifdef GECODE_HAS_GIST
2834 using namespace Gecode::Gist;
2835 int k;
2836 if (ai->isInt(k)) {
2837 out << k;
2838 } else if (ai->isIntVar()) {
2839 std::string res(Comparator::compare("",iv1[ai->getIntVar()],
2840 iv2[ai->getIntVar()]));
2841 if (res.length() > 0) {
2842 res.erase(0, 1); // Remove '='
2843 out << res;
2844 } else {
2845 out << iv1[ai->getIntVar()];
2846 }
2847 } else if (ai->isBoolVar()) {
2848 std::string res(Comparator::compare("",bv1[ai->getBoolVar()],
2849 bv2[ai->getBoolVar()]));
2850 if (res.length() > 0) {
2851 res.erase(0, 1); // Remove '='
2852 out << res;
2853 } else {
2854 out << bv1[ai->getBoolVar()];
2855 }
2856#ifdef GECODE_HAS_SET_VARS
2857 } else if (ai->isSetVar()) {
2858 std::string res(Comparator::compare("",sv1[ai->getSetVar()],
2859 sv2[ai->getSetVar()]));
2860 if (res.length() > 0) {
2861 res.erase(0, 1); // Remove '='
2862 out << res;
2863 } else {
2864 out << sv1[ai->getSetVar()];
2865 }
2866#endif
2867#ifdef GECODE_HAS_FLOAT_VARS
2868 } else if (ai->isFloatVar()) {
2869 std::string res(Comparator::compare("",fv1[ai->getFloatVar()],
2870 fv2[ai->getFloatVar()]));
2871 if (res.length() > 0) {
2872 res.erase(0, 1); // Remove '='
2873 out << res;
2874 } else {
2875 out << fv1[ai->getFloatVar()];
2876 }
2877#endif
2878 } else if (ai->isBool()) {
2879 out << (ai->getBool() ? "true" : "false");
2880 } else if (ai->isSet()) {
2881 AST::SetLit* s = ai->getSet();
2882 if (s->interval) {
2883 out << s->min << ".." << s->max;
2884 } else {
2885 out << "{";
2886 for (unsigned int i=0; i<s->s.size(); i++) {
2887 out << s->s[i] << (i < s->s.size()-1 ? ", " : "}");
2888 }
2889 }
2890 } else if (ai->isString()) {
2891 std::string s = ai->getString();
2892 for (unsigned int i=0; i<s.size(); i++) {
2893 if (s[i] == '\\' && i<s.size()-1) {
2894 switch (s[i+1]) {
2895 case 'n': out << "\n"; break;
2896 case '\\': out << "\\"; break;
2897 case 't': out << "\t"; break;
2898 default: out << "\\" << s[i+1];
2899 }
2900 i++;
2901 } else {
2902 out << s[i];
2903 }
2904 }
2905 }
2906#else
2907 (void) out;
2908 (void) ai;
2909 (void) iv1;
2910 (void) iv2;
2911 (void) bv1;
2912 (void) bv2;
2913#ifdef GECODE_HAS_SET_VARS
2914 (void) sv1;
2915 (void) sv2;
2916#endif
2917#ifdef GECODE_HAS_FLOAT_VARS
2918 (void) fv1;
2919 (void) fv2;
2920#endif
2921
2922#endif
2923 }
2924
2925 void
2926 Printer::print(std::ostream& out,
2927 const Gecode::IntVarArray& iv,
2928 const Gecode::BoolVarArray& bv
2930 ,
2931 const Gecode::SetVarArray& sv
2932#endif
2934 ,
2935 const Gecode::FloatVarArray& fv
2936#endif
2937 ) const {
2938 if (_output == nullptr)
2939 return;
2940 for (unsigned int i=0; i< _output->a.size(); i++) {
2941 AST::Node* ai = _output->a[i];
2942 if (ai->isArray()) {
2943 AST::Array* aia = ai->getArray();
2944 int size = aia->a.size();
2945 out << "[";
2946 for (int j=0; j<size; j++) {
2947 printElem(out,aia->a[j],iv,bv
2949 ,sv
2950#endif
2952 ,fv
2953#endif
2954 );
2955 if (j<size-1)
2956 out << ", ";
2957 }
2958 out << "]";
2959 } else {
2960 printElem(out,ai,iv,bv
2962 ,sv
2963#endif
2965 ,fv
2966#endif
2967 );
2968 }
2969 }
2970 }
2971
2972 void
2973 Printer::printDiff(std::ostream& out,
2974 const Gecode::IntVarArray& iv1,
2975 const Gecode::IntVarArray& iv2,
2976 const Gecode::BoolVarArray& bv1,
2977 const Gecode::BoolVarArray& bv2
2979 ,
2980 const Gecode::SetVarArray& sv1,
2981 const Gecode::SetVarArray& sv2
2982#endif
2984 ,
2985 const Gecode::FloatVarArray& fv1,
2986 const Gecode::FloatVarArray& fv2
2987#endif
2988 ) const {
2989 if (_output == nullptr)
2990 return;
2991 for (unsigned int i=0; i< _output->a.size(); i++) {
2992 AST::Node* ai = _output->a[i];
2993 if (ai->isArray()) {
2994 AST::Array* aia = ai->getArray();
2995 int size = aia->a.size();
2996 out << "[";
2997 for (int j=0; j<size; j++) {
2998 printElemDiff(out,aia->a[j],iv1,iv2,bv1,bv2
3000 ,sv1,sv2
3001#endif
3003 ,fv1,fv2
3004#endif
3005 );
3006 if (j<size-1)
3007 out << ", ";
3008 }
3009 out << "]";
3010 } else {
3011 printElemDiff(out,ai,iv1,iv2,bv1,bv2
3013 ,sv1,sv2
3014#endif
3016 ,fv1,fv2
3017#endif
3018 );
3019 }
3020 }
3021 }
3022
3023 void
3024 Printer::addIntVarName(const std::string& n) {
3025 iv_names.push_back(n);
3026 }
3027 void
3028 Printer::addBoolVarName(const std::string& n) {
3029 bv_names.push_back(n);
3030 }
3031#ifdef GECODE_HAS_FLOAT_VARS
3032 void
3033 Printer::addFloatVarName(const std::string& n) {
3034 fv_names.push_back(n);
3035 }
3036#endif
3037#ifdef GECODE_HAS_SET_VARS
3038 void
3039 Printer::addSetVarName(const std::string& n) {
3040 sv_names.push_back(n);
3041 }
3042#endif
3043
3044 void
3046 std::map<int,int>& iv, std::map<int,int>& bv,
3047 std::map<int,int>& sv, std::map<int,int>& fv) {
3048 if (node->isIntVar()) {
3049 AST::IntVar* x = static_cast<AST::IntVar*>(node);
3050 if (iv.find(x->i) == iv.end()) {
3051 int newi = iv.size();
3052 iv[x->i] = newi;
3053 }
3054 x->i = iv[x->i];
3055 } else if (node->isBoolVar()) {
3056 AST::BoolVar* x = static_cast<AST::BoolVar*>(node);
3057 if (bv.find(x->i) == bv.end()) {
3058 int newi = bv.size();
3059 bv[x->i] = newi;
3060 }
3061 x->i = bv[x->i];
3062 } else if (node->isSetVar()) {
3063 AST::SetVar* x = static_cast<AST::SetVar*>(node);
3064 if (sv.find(x->i) == sv.end()) {
3065 int newi = sv.size();
3066 sv[x->i] = newi;
3067 }
3068 x->i = sv[x->i];
3069 } else if (node->isFloatVar()) {
3070 AST::FloatVar* x = static_cast<AST::FloatVar*>(node);
3071 if (fv.find(x->i) == fv.end()) {
3072 int newi = fv.size();
3073 fv[x->i] = newi;
3074 }
3075 x->i = fv[x->i];
3076 }
3077 }
3078
3079 void
3081 int& optVar, bool optVarIsInt,
3085 ,
3087#endif
3089 ,
3091#endif
3092 ) {
3093 if (_output == nullptr) {
3094 if (optVarIsInt && optVar != -1) {
3095 IntVar ov = iv[optVar];
3096 iv = IntVarArray(home, 1);
3097 iv[0] = ov;
3098 optVar = 0;
3099 } else {
3100 iv = IntVarArray(home, 0);
3101 }
3102 bv = BoolVarArray(home, 0);
3103#ifdef GECODE_HAS_SET_VARS
3104 sv = SetVarArray(home, 0);
3105#endif
3106#ifdef GECODE_HAS_FLOAT_VARS
3107 if (!optVarIsInt && optVar != -1) {
3108 FloatVar ov = fv[optVar];
3109 fv = FloatVarArray(home, 1);
3110 fv[0] = ov;
3111 optVar = 0;
3112 } else {
3113 fv = FloatVarArray(home,0);
3114 }
3115#endif
3116 return;
3117 }
3118 std::map<int,int> iv_new;
3119 std::map<int,int> bv_new;
3120 std::map<int,int> sv_new;
3121 std::map<int,int> fv_new;
3122
3123 if (optVar != -1) {
3124 if (optVarIsInt)
3125 iv_new[optVar] = 0;
3126 else
3127 fv_new[optVar] = 0;
3128 optVar = 0;
3129 }
3130
3131 for (unsigned int i=0; i< _output->a.size(); i++) {
3132 AST::Node* ai = _output->a[i];
3133 if (ai->isArray()) {
3134 AST::Array* aia = ai->getArray();
3135 for (unsigned int j=0; j<aia->a.size(); j++) {
3136 shrinkElement(aia->a[j],iv_new,bv_new,sv_new,fv_new);
3137 }
3138 } else {
3139 shrinkElement(ai,iv_new,bv_new,sv_new,fv_new);
3140 }
3141 }
3142
3143 IntVarArgs iva(iv_new.size());
3144 std::vector<std::string> iv_names_new(iv_new.size());
3145 for (std::map<int,int>::iterator i=iv_new.begin(); i != iv_new.end(); ++i) {
3146 iva[(*i).second] = iv[(*i).first];
3147 iv_names_new[(*i).second] = iv_names[(*i).first];
3148 }
3149 iv = IntVarArray(home, iva);
3150 iv_names = iv_names_new;
3151
3152 BoolVarArgs bva(bv_new.size());
3153 std::vector<std::string> bv_names_new(bv_new.size());
3154 for (std::map<int,int>::iterator i=bv_new.begin(); i != bv_new.end(); ++i) {
3155 bva[(*i).second] = bv[(*i).first];
3156 bv_names_new[(*i).second] = bv_names[(*i).first];
3157 }
3158 bv = BoolVarArray(home, bva);
3159 bv_names = bv_names_new;
3160
3161#ifdef GECODE_HAS_SET_VARS
3162 SetVarArgs sva(sv_new.size());
3163 std::vector<std::string> sv_names_new(sv_new.size());
3164 for (std::map<int,int>::iterator i=sv_new.begin(); i != sv_new.end(); ++i) {
3165 sva[(*i).second] = sv[(*i).first];
3166 sv_names_new[(*i).second] = sv_names[(*i).first];
3167 }
3168 sv = SetVarArray(home, sva);
3169 sv_names = sv_names_new;
3170#endif
3171
3172#ifdef GECODE_HAS_FLOAT_VARS
3173 FloatVarArgs fva(fv_new.size());
3174 std::vector<std::string> fv_names_new(fv_new.size());
3175 for (std::map<int,int>::iterator i=fv_new.begin(); i != fv_new.end(); ++i) {
3176 fva[(*i).second] = fv[(*i).first];
3177 fv_names_new[(*i).second] = fv_names[(*i).first];
3178 }
3179 fv = FloatVarArray(home, fva);
3180 fv_names = fv_names_new;
3181#endif
3182 }
3183
3185 delete _output;
3186 }
3187
3188}}
3189
3190// STATISTICS: flatzinc-any
Archive representation
Definition archive.hpp:42
void put(unsigned int i)
Add i to the contents.
Definition archive.hpp:174
T * a
Element array.
Definition array.hpp:548
int size(void) const
Return size of array (number of elements).
Definition array.hpp:1606
Depth-first branch-and-bound search engine.
Definition search.hh:1373
Which values to select for assignment.
Definition int.hh:6115
Which values to select for branching first.
Definition int.hh:6004
Passing Boolean variables.
Definition int.hh:739
Boolean variable array.
Definition int.hh:840
Boolean integer variables.
Definition int.hh:534
Group of branchers.
Definition core.hpp:806
Base-class for branchers.
Definition core.hpp:1460
friend class Space
Definition core.hpp:1462
Brancher(Home home)
Constructor for creation.
Definition core.hpp:3822
friend class Choice
Definition core.hpp:1463
Class to send solution information to CPProfiler.
Definition search.hh:431
Choice for performing commit
Definition core.hpp:1430
virtual void archive(Archive &e) const
Archive into e.
Definition core.cpp:958
Finite automaton with deterministic construction by default.
Definition int.hh:2620
Depth-first search engine.
Definition search.hh:1211
static void installCtrlHandler(bool install, bool force=false)
Install handler for catching Ctrl-C.
Definition script.hpp:127
Exception: Base-class for exceptions
Definition exception.hpp:42
virtual const char * what(void) const noexcept
Return information.
Definition exception.cpp:55
std::vector< Node * > a
Definition ast.hh:233
Node representing an atom
Definition ast.hh:290
Boolean variable node.
Definition ast.hh:197
Node representing a function call
Definition ast.hh:255
Array * getArgs(unsigned int n)
Definition ast.hh:265
Float variable node.
Definition ast.hh:214
Integer variable node.
Definition ast.hh:206
A node in a FlatZinc abstract syntax tree.
Definition ast.hh:67
bool isSetVar(void)
Test if node is a set variable node.
Definition ast.hh:478
Array * getArray(void)
Cast this node to an array node.
Definition ast.hh:396
bool isBool(void)
Test if node is a Boolean node.
Definition ast.hh:490
bool isFloatVar(void)
Test if node is a float variable node.
Definition ast.hh:482
bool isSet(void)
Test if node is a set literal node.
Definition ast.hh:498
double getFloat(void)
Cast this node to a Float node.
Definition ast.hh:452
int getFloatVar(void)
Cast this node to a Float variable node.
Definition ast.hh:428
bool isArray(void)
Test if node is an array node.
Definition ast.hh:506
SetLit * getSet(void)
Cast this node to a set literal node.
Definition ast.hh:458
bool isString(void)
Test if node is a string node.
Definition ast.hh:502
bool hasAtom(const std::string &id)
Test if node has atom with id.
Definition ast.hh:321
bool isInt(int &i)
Test if node is int, if yes set i to the value.
Definition ast.hh:364
int getInt(void)
Cast this node to an integer node.
Definition ast.hh:440
bool isIntVar(void)
Test if node is an integer variable node.
Definition ast.hh:470
int getIntVar(void)
Cast this node to an integer variable node.
Definition ast.hh:416
bool isBoolVar(void)
Test if node is a Boolean variable node.
Definition ast.hh:474
Call * getCall(void)
Return function call.
Definition ast.hh:343
int getBoolVar(void)
Cast this node to a Boolean variable node.
Definition ast.hh:422
virtual void print(std::ostream &)=0
Output string representation.
int getSetVar(void)
Cast this node to a set variable node.
Definition ast.hh:434
bool getBool(void)
Cast this node to a Boolean node.
Definition ast.hh:446
std::string getString(void)
Cast this node to a string node.
Definition ast.hh:464
Set literal node
Definition ast.hh:171
std::vector< int > s
Definition ast.hh:175
Set variable node
Definition ast.hh:222
Exception signaling type error
Definition ast.hh:55
Choice that only signals failure or success
Definition flatzinc.cpp:142
bool fail
Whether brancher should fail.
Definition flatzinc.cpp:145
virtual size_t size(void) const
Report size occupied.
Definition flatzinc.cpp:150
Choice(const Brancher &b, bool fail0)
Initialize choice for brancher b.
Definition flatzinc.cpp:147
virtual void archive(Archive &e) const
Archive into e.
Definition flatzinc.cpp:154
virtual Choice * choice(const Space &, Archive &e)
Return choice.
Definition flatzinc.cpp:216
TieBreak< BoolVarBranch > bool_varsel
Definition flatzinc.cpp:162
virtual void print(const Space &, const Gecode::Choice &c, unsigned int, std::ostream &o) const
Print explanation.
Definition flatzinc.cpp:225
TieBreak< IntVarBranch > int_varsel
Definition flatzinc.cpp:160
virtual bool status(const Space &_home) const
Check status of brancher, return true if alternatives left.
Definition flatzinc.cpp:175
bool done
Flag whether brancher is done.
Definition flatzinc.cpp:110
virtual Actor * copy(Space &home)
Copy brancher.
Definition flatzinc.cpp:233
static void post(Home home, TieBreak< IntVarBranch > int_varsel, IntValBranch int_valsel, TieBreak< BoolVarBranch > bool_varsel, BoolValBranch bool_valsel, SetVarBranch set_varsel, SetValBranch set_valsel, TieBreak< FloatVarBranch > float_varsel, FloatValBranch float_valsel)
Post brancher.
Definition flatzinc.cpp:237
TieBreak< FloatVarBranch > float_varsel
Definition flatzinc.cpp:169
virtual Choice * choice(Space &home)
Return choice.
Definition flatzinc.cpp:194
virtual ExecStatus commit(Space &, const Gecode::Choice &c, unsigned int)
Perform commit for choice c.
Definition flatzinc.cpp:221
virtual size_t dispose(Space &)
Delete brancher and return its size.
Definition flatzinc.cpp:264
AuxVarBrancher(Home home, TieBreak< IntVarBranch > int_varsel0, IntValBranch int_valsel0, TieBreak< BoolVarBranch > bool_varsel0, BoolValBranch bool_valsel0, SetVarBranch set_varsel0, SetValBranch set_valsel0, TieBreak< FloatVarBranch > float_varsel0, FloatValBranch float_valsel0)
Construct brancher.
Definition flatzinc.cpp:112
AuxVarBrancher(Space &home, AuxVarBrancher &b)
Copy constructor.
Definition flatzinc.cpp:138
static BlackBoxContextHandle & context(FlatZincSpace &s)
Definition flatzinc.cpp:878
Model-local context shared by blackbox propagators and search support.
Definition blackbox.hh:56
void rethrow(void) const
Rethrow the first recorded propagation exception.
Specification for Boolean variables.
Definition varspec.hh:97
Option< AST::SetLit * > domain
Definition varspec.hh:99
void print(const Brancher &b, unsigned int a, int i, int n, std::ostream &o) const
Output branch information.
Definition flatzinc.cpp:297
void add(BrancherGroup bg, const std::string &rel0, const std::string &rel1, const std::vector< std::string > &n)
Add new brancher information.
Definition flatzinc.cpp:289
void print(const Brancher &b, unsigned int a, int i, const FloatNumBranch &nl, std::ostream &o) const
Definition flatzinc.cpp:303
virtual SharedHandle::Object * copy(void) const
Definition flatzinc.cpp:285
void init(void)
Initialise for use.
Definition flatzinc.cpp:320
void print(const Brancher &b, unsigned int a, int i, int n, std::ostream &o) const
Output branch information.
Definition flatzinc.cpp:333
void add(BrancherGroup bg, const std::string &rel0, const std::string &rel1, const std::vector< std::string > &n)
Add new brancher information.
Definition flatzinc.cpp:326
Abstract representation of a constraint.
Definition conexpr.hh:43
AST::Array * ann
Constraint annotations.
Definition conexpr.hh:50
Exception class for FlatZinc errors
Definition flatzinc.hh:727
virtual void compare(const Space &s0, const Space &s1)
Use the compare method of the template class S to compare two spaces.
FZPrintingComparator(const Printer &p0)
Constructor.
An inspector for printing simple text output.
virtual void finalize(void)
Finalize when Gist exits.
FZPrintingInspector(const Printer &p0)
Constructor.
virtual void inspect(const Space &node)
Use the print method of the template class S to print a space.
FlatZincGetInfo(const Printer &printer)
virtual std::string getInfo(const Space &space) const
Return info for a space.
Options for running FlatZinc models
Definition flatzinc.hh:226
std::unordered_set< TupleSet > TupleSetSet
Hash table of tuple sets.
Definition flatzinc.cpp:761
BlackBoxContextHandle blackBoxContext
Opaque state shared by blackbox propagators in this model.
Definition flatzinc.cpp:776
DFASet dfaSet
Hash table of DFAs.
Definition flatzinc.cpp:773
std::unordered_set< DFA > DFASet
Hash table of DFAs.
Definition flatzinc.cpp:771
IntSharedArraySet intSharedArraySet
Hash table of shared integer arrays.
Definition flatzinc.cpp:768
TupleSetSet tupleSetSet
Hash table of tuple sets.
Definition flatzinc.cpp:763
std::unordered_set< SharedArray< int > > IntSharedArraySet
Hash table of shared integer arrays.
Definition flatzinc.cpp:766
A space that can be initialized with a FlatZinc model.
Definition flatzinc.hh:424
void createBranchers(Printer &p, AST::Node *ann, FlatZincOptions &opt, bool ignoreUnknown, std::ostream &err=std::cerr)
Create branchers corresponding to the solve item annotations.
Gecode::IntVarArray iv_lns
The integer variables used in LNS.
Definition flatzinc.hh:487
void shrinkArrays(Printer &p)
Remove all variables not needed for output.
unsigned int _lns
Percentage of variables to keep in LNS (or 0 for no LNS).
Definition flatzinc.hh:452
void maximize(int var, bool isInt, AST::Array *annotation)
Post that integer variable var should be maximized.
IntVarArgs arg2intvarargs(AST::Node *arg, int offset=0)
Convert arg to IntVarArgs.
Gecode::FloatVarArray fv
The float variables.
Definition flatzinc.hh:574
Rnd _random
Random number generator.
Definition flatzinc.hh:458
Gecode::FloatVarArray on_restart_fv
On Restart Tracked Floating Point Variables.
Definition flatzinc.hh:550
void newBoolVar(BoolVarSpec *vs)
Create new Boolean variable from specification.
Definition flatzinc.cpp:936
FloatVar arg2FloatVar(AST::Node *n)
Convert n to FloatVar.
void print(std::ostream &out, const Printer &p) const
Produce output on out using p.
std::vector< bool > fv_introduced
Indicates whether a float variable is introduced by mzn2fzn.
Definition flatzinc.hh:578
AST::Array * _solveAnnotations
Annotations on the solve item.
Definition flatzinc.hh:461
int _optVar
Index of the variable to optimize.
Definition flatzinc.hh:444
BranchInformation branchInfo
Information for printing branches.
Definition flatzinc.hh:669
void run(std::ostream &out, const Printer &p, const FlatZincOptions &opt, Gecode::Support::Timer &t_total)
Run the search.
DFA getSharedDFA(DFA &a)
Share DFA a if possible.
void newFloatVar(FloatVarSpec *vs)
Create new float variable from specification.
Definition flatzinc.cpp:995
SetVar arg2SetVar(AST::Node *n)
Convert n to SetVar.
int * iv_boolalias
Indicates whether an integer variable aliases a Boolean variable.
Definition flatzinc.hh:557
virtual bool slave(const MetaInfo &mi)
Slave function for restarts.
void postConstraints(std::vector< ConExpr * > &ces)
Post a constraint specified by ce.
SetVarArgs arg2setvarargs(AST::Node *arg, int offset=0, int doffset=0, const IntSet &od=IntSet::empty)
Convert n to SetVarArgs.
bool _optVarIsInt
Whether variable to optimize is integer (or float).
Definition flatzinc.hh:446
FlatZincSpace(FlatZincSpace &)
Copy constructor.
Definition flatzinc.cpp:782
Gecode::BoolVarArray bv
The Boolean variables.
Definition flatzinc.hh:559
void newSetVar(SetVarSpec *vs)
Create new set variable from specification.
Definition flatzinc.cpp:948
bool optVarIsInt(void) const
Return whether variable used for optimization is integer (or float).
Gecode::SetVarArray on_restart_sv
On Restart Tracked Set Variables.
Definition flatzinc.hh:546
std::vector< bool > iv_introduced
Indicates whether an integer variable is introduced by mzn2fzn.
Definition flatzinc.hh:555
IntVar arg2IntVar(AST::Node *n)
Convert n to IntVar.
std::string getDomains(const Printer &p) const
Get string representing the domains of variables (for cpprofiler).
FlatZincSpaceInitData * _initData
Initialisation data (only used for posting constraints).
Definition flatzinc.hh:433
Meth method(void) const
Return whether to solve a satisfaction or optimization problem.
std::vector< bool > sv_introduced
Indicates whether a set variable is introduced by mzn2fzn.
Definition flatzinc.hh:570
IntSet arg2intset(AST::Node *n)
Convert n to IntSet.
std::vector< bool > bv_introduced
Indicates whether a Boolean variable is introduced by mzn2fzn.
Definition flatzinc.hh:563
Gecode::FloatVarArray fv_aux
The introduced float variables.
Definition flatzinc.hh:576
void minimize(int var, bool isInt, AST::Array *annotation)
Post that integer variable var should be minimized.
virtual void constrain(const Space &s)
Implement optimization.
IntArgs arg2boolargs(AST::Node *arg, int offset=0)
Convert arg (array of Booleans) to IntArgs.
Gecode::SetVarArray sv_aux
The introduced set variables.
Definition flatzinc.hh:568
int floatVarCount
Number of float variables.
Definition flatzinc.hh:439
int boolVarCount
Number of Boolean variables.
Definition flatzinc.hh:437
Gecode::SetVarArray sv
The set variables.
Definition flatzinc.hh:566
int setVarCount
Number of set variables.
Definition flatzinc.hh:441
Gecode::IntVarArray on_restart_iv
On Restart Tracked Integer Variables.
Definition flatzinc.hh:541
int optVar(void) const
Return index of variable used for optimization.
FloatVarArgs arg2floatvarargs(AST::Node *arg, int offset=0)
Convert n to FloatVarArgs.
IntSharedArray arg2boolsharedarray(AST::Node *arg, int offset=0)
Convert arg (array of integers) to IntSharedArray.
void solve(AST::Array *annotation)
Post the solve item.
Gecode::FloatNum step
Step by which a next solution has to have lower cost.
Definition flatzinc.hh:580
IntSharedArray _lnsInitialSolution
Initial solution to start the LNS (or nullptr for no LNS).
Definition flatzinc.hh:455
Gecode::BoolVarArray bv_aux
The introduced Boolean variables.
Definition flatzinc.hh:561
IntSharedArray arg2intsharedarray(AST::Node *arg, int offset=0)
Convert arg (array of integers) to IntSharedArray.
BoolVarArgs arg2boolvarargs(AST::Node *arg, int offset=0, int siv=-1)
Convert arg to BoolVarArgs.
void aliasBool2Int(int iv, int bv)
Link integer variable iv to Boolean variable bv.
Definition flatzinc.cpp:927
AST::Array * solveAnnotations(void) const
Return the solve item annotations.
Gecode::IntVarArray iv_aux
The introduced integer variables.
Definition flatzinc.hh:484
Gecode::IntVarArray iv
The integer variables.
Definition flatzinc.hh:482
virtual Gecode::Space * copy(void)
Copy function.
void init(int intVars, int boolVars, int setVars, int floatVars)
Initialize space with given number of variables.
Definition flatzinc.cpp:884
Gecode::BoolVarArray on_restart_bv
On Restart Tracked Boolean Variables.
Definition flatzinc.hh:543
bool isBoolArray(AST::Node *b, int &singleInt)
Check if b is array of Booleans (or has a single integer).
IntPropLevel ann2ipl(AST::Node *ann)
Convert ann to integer propagation level.
void newIntVar(IntVarSpec *vs)
Create new integer variable from specification.
Definition flatzinc.cpp:909
Meth _method
Whether to solve as satisfaction or optimization problem.
Definition flatzinc.hh:449
void compare(const Space &s, std::ostream &out) const
Compare this space with space s and print the differences on out.
int intVarCount
Number of integer variables.
Definition flatzinc.hh:435
BoolVar arg2BoolVar(AST::Node *n)
Convert n to BoolVar.
TupleSet arg2tupleset(const IntArgs &a, int noOfVars)
Convert a to TupleSet.
IntSetArgs arg2intsetargs(AST::Node *arg, int offset=0)
Convert arg to IntSetArgs.
FloatValArgs arg2floatargs(AST::Node *arg, int offset=0)
Convert n to FloatValArgs.
bool needAuxVars
Whether the introduced variables still need to be copied.
Definition flatzinc.hh:583
IntArgs arg2intargs(AST::Node *arg, int offset=0)
Convert arg (array of integers) to IntArgs.
std::unique_ptr< Search::Stop > stop_object
FlatZincStop(Search::Stop *stop_object0, const BlackBoxContextHandle &black_box_context0)
BlackBoxContextHandle black_box_context
bool stop(const Search::Statistics &s, const Search::Options &o) override
Stop search, if returns true.
Specification for floating point variables.
Definition varspec.hh:119
Option< std::pair< double, double > > domain
Definition varspec.hh:121
static void explore(S *root, const FlatZincOptions &opt, Gist::Inspector *i, Gist::Comparator *c)
static void explore(S *root, const FlatZincOptions &opt, Gist::Inspector *i, Gist::Comparator *c)
Traits class for search engines.
Which integer or Boolean variable to select for branching.
Definition branch.hh:44
Specification for integer variables.
Definition varspec.hh:72
Option< AST::SetLit * > domain
Definition varspec.hh:74
Output support class for FlatZinc interpreter.
Definition flatzinc.hh:107
void addFloatVarName(const std::string &n)
void printDiff(std::ostream &out, const Gecode::IntVarArray &iv1, const Gecode::IntVarArray &iv2, const Gecode::BoolVarArray &bv1, const Gecode::BoolVarArray &bv2, const Gecode::SetVarArray &sv1, const Gecode::SetVarArray &sv2, const Gecode::FloatVarArray &fv1, const Gecode::FloatVarArray &fv2) const
void addSetVarName(const std::string &n)
void init(AST::Array *output)
void print(std::ostream &out, const Gecode::IntVarArray &iv, const Gecode::BoolVarArray &bv, const Gecode::SetVarArray &sv, const Gecode::FloatVarArray &fv) const
void shrinkArrays(Space &home, int &optVar, bool optVarIsInt, Gecode::IntVarArray &iv, Gecode::BoolVarArray &bv, Gecode::SetVarArray &sv, Gecode::FloatVarArray &fv)
void addIntVarName(const std::string &n)
void addBoolVarName(const std::string &n)
void shrinkElement(AST::Node *node, std::map< int, int > &iv, std::map< int, int > &bv, std::map< int, int > &sv, std::map< int, int > &fv)
void post(FlatZincSpace &s, const ConExpr &ce)
Post constraint specified by ce.
Definition registry.cpp:57
Specification for set variables.
Definition varspec.hh:139
Option< AST::SetLit * > upperBound
Definition varspec.hh:141
int i
Variable index.
Definition varspec.hh:57
bool introduced
Whether the variable was introduced in the mzn2fzn translation.
Definition varspec.hh:63
bool assigned
Whether the variable is assigned.
Definition varspec.hh:61
bool alias
Whether the variable aliases another variable.
Definition varspec.hh:59
bool funcDep
Whether the variable functionally depends on another variable.
Definition varspec.hh:65
Value description class for branching.
Definition float.hh:1464
bool l
Whether to try the lower or upper half first.
Definition float.hh:1469
FloatNum n
The middle value for branching.
Definition float.hh:1467
Passing float arguments.
Definition float.hh:948
Which values to select for branching first.
Definition float.hh:1828
Float value type.
Definition float.hh:329
FloatNum size(void) const
Return size of float value (distance between maximum and minimum).
Definition val.hpp:78
Passing float variables.
Definition float.hh:977
Float variable array.
Definition float.hh:1030
Float variables.
Definition float.hh:865
Float view for float variables.
Definition view.hpp:52
Abstract base class for comparators.
Definition gist.hh:119
virtual void compare(const Space &s0, const Space &s1)=0
Call-back function.
Abstract base class for inspectors.
Definition gist.hh:99
void compare(Comparator *c)
Add comparator.
Definition gist.hpp:182
void click(Inspector *i)
Add inspector that reacts on node double clicks.
Definition gist.hpp:170
Options for Gist
Definition gist.hh:234
class Gecode::Gist::Options::I_ inspect
An window for simple text output.
Definition gist.hh:160
void finalize(void)
Clean up when Gist exits.
Definition gist.cpp:64
TextOutput(const std::string &name)
Constructor.
Definition gist.cpp:60
std::ostream & getStream(void)
Get the stream that is used to output text.
Definition gist.cpp:85
void init(void)
Initialize the implementation object.
Definition gist.cpp:77
A simple comparator.
Definition gist.hh:211
VarComparator(std::string name)
Constructor.
Definition gist.hpp:37
unsigned int id(void) const
Return a unique id for the group.
Definition core.hpp:5258
Home class for posting propagators
Definition core.hpp:863
Passing integer arguments.
Definition int.hh:653
Which values to select for assignment.
Definition int.hh:6086
Integer sets.
Definition int.hh:179
static const IntSet empty
Empty set.
Definition int.hh:302
Which values to select for branching first.
Definition int.hh:5969
Passing integer variables.
Definition int.hh:681
Integer variable array.
Definition int.hh:792
Integer variables.
Definition int.hh:390
Integer view for integer variables.
Definition view.hpp:129
int min(void) const
Return minimum of domain.
Definition int.hpp:58
bool range(void) const
Test whether domain is a range.
Definition int.hpp:103
int val(void) const
Return assigned value (only if assigned).
Definition int.hpp:70
int max(void) const
Return maximum of domain.
Definition int.hpp:62
Range iterator for integer views.
Definition view.hpp:54
Information passed by meta search engines.
Definition core.hpp:1635
@ RESTART
Information is provided by a restart-based engine.
Definition core.hpp:1640
unsigned long long int solution(void) const
Return number of solutions since last restart.
Definition core.hpp:3245
unsigned long int restart(void) const
Return number of restarts.
Definition core.hpp:3236
const Space * last(void) const
Return last solution found (possibly nullptr).
Definition core.hpp:3255
RestartReason reason(void) const
Return reason for restarting.
Definition core.hpp:3241
@ RR_INIT
Restarting after initialisation.
Definition core.hpp:1649
@ RR_SOL
Restarting after a solution is found.
Definition core.hpp:1651
@ RR_CMPL
Restarting after exhausting search space.
Definition core.hpp:1653
@ RR_LIM
Restarting after reaching restart limit.
Definition core.hpp:1655
Type type(void) const
Return type of information.
Definition core.hpp:3232
static PropagatorGroup all
Group of all propagators.
Definition core.hpp:796
T * alloc(long unsigned int n)
Allocate block of n objects of type T from region.
Definition region.hpp:386
Random number generator.
Definition rnd.hpp:42
Search engine options
Definition search.hh:848
unsigned int c_d
Create a clone after every c_d commits (commit distance).
Definition search.hh:863
unsigned int a_d
Create a clone during recomputation if distance is greater than a_d (adaptive distance).
Definition search.hh:865
Search engine statistics
Definition search.hh:155
unsigned long int restart
Number of restarts.
Definition search.hh:164
unsigned long int depth
Maximum depth of search stack.
Definition search.hh:162
unsigned long long int fail
Number of failed nodes in search tree.
Definition search.hh:158
unsigned long long int node
Number of nodes expanded.
Definition search.hh:160
Base-class for Stop-object.
Definition search.hh:919
Which values to select for branching first.
Definition set.hh:1460
Passing set variables.
Definition set.hh:491
Set variable array
Definition set.hh:575
Which variable to select for branching.
Definition set.hh:1309
Set variables
Definition set.hh:127
Range iterator for the greatest lower bound.
Definition var-imp.hpp:359
Shared array with arbitrary number of elements.
int size(void) const
Return number of elements.
SharedHandle(void)
Create shared handle with no object pointing to.
SharedHandle::Object * object(void) const
Access to the shared object.
Computation spaces.
Definition core.hpp:1787
struct Gecode::Space::@055132133326276162005044145100211202071356247106::@275070317317120154232063063134255170030071110047 p
Data only available during propagation or branching.
struct Gecode::Space::@055132133326276162005044145100211202071356247106::@155123175027073262103111264343315000271204104107 c
Data available only during copying.
friend class Region
Definition core.hpp:1800
T * alloc(long unsigned int n)
Allocate block of n objects of type T from space heap.
Definition core.hpp:2973
friend class BrancherGroup
Definition core.hpp:1793
Statistics for execution of status
Definition core.hpp:1736
unsigned long long int propagate
Number of propagator executions.
Definition core.hpp:1739
double stop(void)
Get time since start of timer.
Definition timer.hpp:63
void start(void)
Start timer.
Definition timer.hpp:58
Combine variable selection criteria for tie-breaking.
Definition tiebreak.hpp:38
Class representing a set of tuples.
Definition int.hh:2821
TupleSet & add(const IntArgs &t)
Add tuple t to tuple set.
std::size_t hash(void) const
Return hash key.
void finalize(void)
Finalize tuple set with dense support data.
bool assigned(void) const
Test if all variables are assigned.
Definition array.hpp:1045
int size(void) const
Return size of array (number of elements).
Definition array.hpp:945
bool assigned(void) const
Test whether view is assigned.
Definition view.hpp:516
Base class for variables.
Definition var.hpp:40
unsigned int seed
The random seed to be used.
Definition test.hh:138
unsigned int threads
Number of threads to use.
Definition test.hh:136
const int * pi[]
Definition photo.cpp:14262
Heap heap
The single global heap.
Definition heap.cpp:44
void fail(void)
Fail space.
Definition core.hpp:4275
@ SM_GIST
Run script in Gist.
Definition driver.hh:101
@ RM_CONSTANT
Restart with constant sequence.
Definition driver.hh:110
@ RM_LINEAR
Restart with linear sequence.
Definition driver.hh:111
@ RM_LUBY
Restart with Luby sequence.
Definition driver.hh:112
@ RM_NONE
No restarts.
Definition driver.hh:109
@ RM_GEOMETRIC
Restart with geometric sequence.
Definition driver.hh:113
int bab(Space *root, const Gist::Options &opt=Gist::Options::def)
Create a new stand-alone Gist for branch-and-bound search of root.
Definition gist.hpp:208
int dfs(Space *root, const Gist::Options &opt=Gist::Options::def)
Create a new stand-alone Gist for root.
Definition gist.hpp:203
void assign(Home home, const FloatVarArgs &x, FloatVarBranch vars, FloatAssign vals, FloatBranchFilter bf=nullptr, FloatVarValPrint vvp=nullptr)
Assign all x with variable selection vars and value selection vals.
Definition branch.cpp:111
void rel(Home home, FloatVar x0, FloatRelType frt, FloatVar x1)
Post propagator for .
Definition rel.cpp:68
double FloatNum
Floating point number base type.
Definition float.hh:106
@ FRT_EQ
Equality ( ).
Definition float.hh:1071
@ FRT_LQ
Less or equal ( ).
Definition float.hh:1073
@ FRT_GQ
Greater or equal ( ).
Definition float.hh:1075
IntPropLevel
Propagation levels for integer propagators.
Definition int.hh:1274
@ IRT_EQ
Equality ( ).
Definition int.hh:1226
@ IRT_LE
Less ( ).
Definition int.hh:1229
@ IRT_GR
Greater ( ).
Definition int.hh:1231
@ IPL_BASIC
Use basic propagation algorithm.
Definition int.hh:1281
@ IPL_DOM
Domain propagation Options: basic versus advanced propagation.
Definition int.hh:1279
@ IPL_FULL
Use full propagation.
Definition int.hh:1284
@ IPL_VAL
Value propagation.
Definition int.hh:1277
@ IPL_ADVANCED
Use advanced propagation algorithm.
Definition int.hh:1282
@ IPL_DEF
Simple propagation levels.
Definition int.hh:1276
@ IPL_BND
Bounds propagation.
Definition int.hh:1278
Space(void)
Default constructor.
Definition core.cpp:121
@ SRT_EQ
Equality ( ).
Definition set.hh:651
Space * clone(void) const
Clone space.
Definition core.hpp:3384
@ SS_FAILED
Space is failed
Definition core.hpp:1727
void stop(Support::Timer &timer, std::ostream &os)
Get time since start of timer and print user friendly time information.
Definition script.cpp:42
Interpreter for the FlatZinc language.
void printIntVar(std::ostream &os, const std::string name, const Int::IntView &x)
Registry & registry(void)
Return global registry object.
Definition registry.cpp:51
void varValPrintF(const Space &home, const Brancher &b, unsigned int a, FloatVar, int i, const FloatNumBranch &nl, std::ostream &o)
Definition flatzinc.cpp:353
TieBreak< IntVarBranch > ann2ivarsel(AST::Node *ann, Rnd rnd, double decay)
Definition flatzinc.cpp:405
void varValPrint(const Space &home, const Brancher &b, unsigned int a, Var, int i, const int &n, std::ostream &o)
Definition flatzinc.cpp:345
BoolAssign ann2asnbvalsel(AST::Node *ann, Rnd rnd)
Definition flatzinc.cpp:608
TieBreak< BoolVarBranch > ann2bvarsel(AST::Node *ann, Rnd rnd, double decay)
Definition flatzinc.cpp:523
void printFloatVar(std::ostream &os, const std::string name, const Float::FloatView &f)
void printBoolVar(std::ostream &os, const std::string name, const BoolVar &b)
TieBreak< FloatVarBranch > ann2fvarsel(AST::Node *ann, Rnd rnd, double decay)
Definition flatzinc.cpp:694
BoolValBranch ann2bvalsel(AST::Node *ann, std::string &r0, std::string &r1, Rnd rnd)
Definition flatzinc.cpp:557
IntSet vs2is(IntVarSpec *vs)
Definition flatzinc.cpp:361
FloatValBranch ann2fvalsel(AST::Node *ann, std::string r0, std::string r1)
Definition flatzinc.cpp:738
int vs2bsl(BoolVarSpec *bs)
Definition flatzinc.cpp:381
IntValBranch ann2ivalsel(AST::Node *ann, std::string &r0, std::string &r1, Rnd rnd)
Definition flatzinc.cpp:454
IntBoolVarBranch INTBOOL_VAR_AFC_SIZE_MAX(double d=1.0)
Select variable with largest accumulated failure count divided by domain size.
Definition branch.hpp:138
GECODE_FLATZINC_EXPORT Rnd defrnd
Uninitialized default random number generator.
void branch(Home home, const IntVarArgs &x, const BoolVarArgs &y, IntBoolVarBranch vars, IntValBranch vals)
Branch function for integer and Boolean variables.
Definition branch.cpp:120
SetVarBranch ann2svarsel(AST::Node *ann, Rnd rnd, double decay)
Definition flatzinc.cpp:626
SetValBranch ann2svalsel(AST::Node *ann, std::string r0, std::string r1, Rnd rnd)
Definition flatzinc.cpp:664
int vs2bsh(BoolVarSpec *bs)
Definition flatzinc.cpp:393
IntAssign ann2asnivalsel(AST::Node *ann, Rnd rnd)
Definition flatzinc.cpp:505
void flattenAnnotations(AST::Array *ann, std::vector< AST::Node * > &out)
const FloatNum max
Largest allowed float value.
Definition float.hh:839
const FloatNum min
Smallest allowed float value.
Definition float.hh:841
The Gecode Interactive Search Tool.
const int min
Smallest allowed integer value.
Definition int.hh:123
const int max
Largest allowed integer value.
Definition int.hh:121
const int min
Smallest allowed integer in integer set.
Definition set.hh:99
const int max
Largest allowed integer in integer set.
Definition set.hh:97
void print(std::basic_ostream< Char, Traits > &s, bool assigned, IL &lb, IU &ub, unsigned int cardMin, unsigned int cardMax)
Print set view.
Definition print.hpp:63
Gecode toplevel namespace
FloatVarBranch FLOAT_VAR_RND(Rnd r)
Select random variable (uniform distribution, for tie breaking).
Definition var.hpp:112
FloatValBranch FLOAT_VAL_SPLIT_MAX(void)
Select values greater than mean of smallest and largest value.
Definition val.hpp:60
ArgArray< IntSet > IntSetArgs
Passing set arguments.
Definition int.hh:644
SetVarBranch SET_VAR_ACTION_SIZE_MIN(double d=1.0, BranchTbl tbl=nullptr)
Select variable with smallest action divided by domain size with decay factor d.
Definition var.hpp:246
IntAssign INT_ASSIGN_RND(Rnd r)
Select random value.
Definition assign.hpp:70
SetVarBranch SET_VAR_ACTION_SIZE_MAX(double d=1.0, BranchTbl tbl=nullptr)
Select variable with largest action divided by domain size with decay factor d.
Definition var.hpp:256
IntValBranch INT_VAL_SPLIT_MIN(void)
Select values not greater than mean of smallest and largest value.
Definition val.hpp:75
FloatVarBranch FLOAT_VAR_AFC_MIN(double d=1.0, BranchTbl tbl=nullptr)
Select variable with smallest accumulated failure count with decay factor d.
Definition var.hpp:127
BoolAssign BOOL_ASSIGN_MAX(void)
Select largest value.
Definition assign.hpp:105
FloatVarBranch FLOAT_VAR_SIZE_MAX(BranchTbl tbl=nullptr)
Select variable with largest domain size.
Definition var.hpp:212
IntVarBranch INT_VAR_AFC_SIZE_MAX(double d=1.0, BranchTbl tbl=nullptr)
Select variable with largest accumulated failure count divided by domain size with decay factor d.
Definition var.hpp:236
FloatVarBranch FLOAT_VAR_MAX_MAX(BranchTbl tbl=nullptr)
Select variable with largest max.
Definition var.hpp:202
SetVarBranch SET_VAR_NONE(void)
Select first unassigned variable.
Definition var.hpp:96
IntVarBranch INT_VAR_DEGREE_MAX(BranchTbl tbl=nullptr)
Select variable with largest degree.
Definition var.hpp:121
IntVarBranch INT_VAR_ACTION_MAX(double d=1.0, BranchTbl tbl=nullptr)
Select variable with highest action with decay factor d.
Definition var.hpp:156
FloatVarBranch FLOAT_VAR_AFC_SIZE_MIN(double d=1.0, BranchTbl tbl=nullptr)
Select variable with smalllest accumulated failure count divided by domain size with decay factor d.
Definition var.hpp:227
SharedArray< int > IntSharedArray
Arrays of integers that can be shared among several element constraints.
Definition int.hh:1813
IntValBranch INT_VAL_MED(void)
Select greatest value not greater than the median.
Definition val.hpp:60
IntVarBranch INT_VAR_REGRET_MIN_MAX(BranchTbl tbl=nullptr)
Select variable with largest min-regret.
Definition var.hpp:291
IntVarBranch INT_VAR_ACTION_SIZE_MAX(double d=1.0, BranchTbl tbl=nullptr)
Select variable with largest action divided by domain size with decay factor d.
Definition var.hpp:256
void min(Home home, FloatVar x0, FloatVar x1, FloatVar x2)
Post propagator for .
BoolValBranch BOOL_VAL_MIN(void)
Select smallest value.
Definition val.hpp:130
IntVarBranch INT_VAR_NONE(void)
Select first unassigned variable.
Definition var.hpp:96
void dom(Home home, FloatVar x, FloatVal n)
Propagates .
Definition dom.cpp:40
BoolVarBranch BOOL_VAR_NONE(void)
Select first unassigned variable.
Definition var.hpp:364
IntVarBranch INT_VAR_AFC_MAX(double d=1.0, BranchTbl tbl=nullptr)
Select variable with largest accumulated failure count with decay factor d.
Definition var.hpp:136
IntVarBranch INT_VAR_AFC_MIN(double d=1.0, BranchTbl tbl=nullptr)
Select variable with smallest accumulated failure count with decay factor d.
Definition var.hpp:126
IntValBranch INT_VALUES_MIN(void)
Try all values starting from smallest.
Definition val.hpp:100
SetVarBranch SET_VAR_SIZE_MIN(BranchTbl tbl=nullptr)
Select variable with smallest unknown set.
Definition var.hpp:206
SetVarBranch SET_VAR_RND(Rnd r)
Select random variable (uniform distribution, for tie breaking).
Definition var.hpp:101
void range(Home home, const IntVarArgs &x, SetVar y, SetVar z)
Post constraint .
Definition aliases.hpp:158
void cmb_hash(std::size_t &seed, const T h)
Combine hash value h into seed.
Definition hash.hpp:44
SetVarBranch SET_VAR_MAX_MAX(BranchTbl tbl=nullptr)
Select variable with largest maximum unknown element.
Definition var.hpp:201
IntValBranch INT_VAL_MAX(void)
Select largest value.
Definition val.hpp:65
FloatVarBranch FLOAT_VAR_ACTION_MAX(double d=1.0, BranchTbl tbl=nullptr)
Select variable with highest action with decay factor d.
Definition var.hpp:157
BoolValBranch BOOL_VAL_MAX(void)
Select largest value.
Definition val.hpp:135
BoolVarBranch BOOL_VAR_RND(Rnd r)
Select random variable (uniform distribution, for tie breaking).
Definition var.hpp:369
BoolVarBranch BOOL_VAR_ACTION_MIN(double d=1.0, BranchTbl tbl=nullptr)
Select variable with lowest action with decay factor d.
Definition var.hpp:414
SetVarBranch SET_VAR_AFC_MAX(double d=1.0, BranchTbl tbl=nullptr)
Select variable with largest accumulated failure count with decay factor d.
Definition var.hpp:136
FloatVarBranch FLOAT_VAR_MIN_MIN(BranchTbl tbl=nullptr)
Select variable with smallest min.
Definition var.hpp:187
SetVarBranch SET_VAR_MIN_MIN(BranchTbl tbl=nullptr)
Select variable with smallest minimum unknown element.
Definition var.hpp:186
FloatVarBranch FLOAT_VAR_ACTION_MIN(double d=1.0, BranchTbl tbl=nullptr)
Select variable with lowest action with decay factor d.
Definition var.hpp:147
SetValBranch SET_VAL_MAX_INC(void)
Include largest element.
Definition val.hpp:75
BoolAssign BOOL_ASSIGN_RND(Rnd r)
Select random value.
Definition assign.hpp:110
IntValBranch INT_VAL_SPLIT_MAX(void)
Select values greater than mean of smallest and largest value.
Definition val.hpp:80
IntValBranch INT_VAL_MIN(void)
Select smallest value.
Definition val.hpp:55
IntAssign INT_ASSIGN_MED(void)
Select greatest value not greater than the median.
Definition assign.hpp:60
SetVarBranch SET_VAR_AFC_MIN(double d=1.0, BranchTbl tbl=nullptr)
Select variable with smallest accumulated failure count with decay factor d.
Definition var.hpp:126
BoolVarBranch BOOL_VAR_AFC_MIN(double d=1.0, BranchTbl tbl=nullptr)
Select variable with smallest accumulated failure count with decay factor d.
Definition var.hpp:394
T * dfs(T *s, const Search::Options &o=Search::Options::def)
Invoke depth-first search engine for subclass T of space s with options o.
Definition dfs.hpp:73
BoolVarBranch BOOL_VAR_AFC_MAX(double d=1.0, BranchTbl tbl=nullptr)
Select variable with largest accumulated failure count with decay factor d.
Definition var.hpp:404
FloatVarBranch FLOAT_VAR_NONE(void)
Select first unassigned variable.
Definition var.hpp:97
IntVarBranch INT_VAR_MAX_MAX(BranchTbl tbl=nullptr)
Select variable with largest max.
Definition var.hpp:201
IntAssign INT_ASSIGN_MIN(void)
Select smallest value.
Definition assign.hpp:55
IntVarBranch INT_VAR_ACTION_MIN(double d=1.0, BranchTbl tbl=nullptr)
Select variable with lowest action with decay factor d.
Definition var.hpp:146
IntVarBranch INT_VAR_RND(Rnd r)
Select random variable (uniform distribution, for tie breaking).
Definition var.hpp:101
IntVarBranch INT_VAR_AFC_SIZE_MIN(double d=1.0, BranchTbl tbl=nullptr)
Select variable with smallest accumulated failure count divided by domain size with decay factor d.
Definition var.hpp:226
SetValBranch SET_VAL_MIN_INC(void)
Include smallest element.
Definition val.hpp:55
ExecStatus
Definition core.hpp:479
@ ES_OK
Execution is okay.
Definition core.hpp:483
@ ES_FAILED
Execution has resulted in failure.
Definition core.hpp:481
void max(Home home, FloatVar x0, FloatVar x1, FloatVar x2)
Post propagator for .
FloatVarBranch FLOAT_VAR_DEGREE_MAX(BranchTbl tbl=nullptr)
Select variable with largest degree.
Definition var.hpp:122
SetVarBranch SET_VAR_AFC_SIZE_MIN(double d=1.0, BranchTbl tbl=nullptr)
Select variable with smallest accumulated failure count divided by domain size with decay factor d.
Definition var.hpp:226
SetValBranch SET_VAL_MAX_EXC(void)
Exclude largest element.
Definition val.hpp:80
FloatVarBranch FLOAT_VAR_ACTION_SIZE_MAX(double d=1.0, BranchTbl tbl=nullptr)
Select variable with largest action divided by domain size with decay factor d.
Definition var.hpp:257
BoolValBranch BOOL_VAL_RND(Rnd r)
Select random value.
Definition val.hpp:140
SetVarBranch SET_VAR_AFC_SIZE_MAX(double d=1.0, BranchTbl tbl=nullptr)
Select variable with largest accumulated failure count divided by domain size with decay factor d.
Definition var.hpp:236
SetVarBranch SET_VAR_ACTION_MIN(double d=1.0, BranchTbl tbl=nullptr)
Select variable with lowest action with decay factor d.
Definition var.hpp:146
IntVarBranch INT_VAR_SIZE_MIN(BranchTbl tbl=nullptr)
Select variable with smallest domain size.
Definition var.hpp:206
BoolVarBranch BOOL_VAR_DEGREE_MAX(BranchTbl tbl=nullptr)
Select variable with largest degree.
Definition var.hpp:389
FloatVarBranch FLOAT_VAR_AFC_SIZE_MAX(double d=1.0, BranchTbl tbl=nullptr)
Select variable with largest accumulated failure count divided by domain size with decay factor d.
Definition var.hpp:237
IntVarBranch INT_VAR_ACTION_SIZE_MIN(double d=1.0, BranchTbl tbl=nullptr)
Select variable with smallest action divided by domain size with decay factor d.
Definition var.hpp:246
BoolVarBranch BOOL_VAR_ACTION_MAX(double d=1.0, BranchTbl tbl=nullptr)
Select variable with highest action with decay factor d.
Definition var.hpp:424
BoolAssign BOOL_ASSIGN_MIN(void)
Select smallest value.
Definition assign.hpp:100
FloatValBranch FLOAT_VAL_SPLIT_MIN(void)
Select values not greater than mean of smallest and largest value.
Definition val.hpp:55
IntAssign INT_ASSIGN_MAX(void)
Select largest value.
Definition assign.hpp:65
FloatVarBranch FLOAT_VAR_SIZE_MIN(BranchTbl tbl=nullptr)
Select variable with smallest domain size.
Definition var.hpp:207
IntVarBranch INT_VAR_MIN_MIN(BranchTbl tbl=nullptr)
Select variable with smallest min.
Definition var.hpp:186
FloatVarBranch FLOAT_VAR_AFC_MAX(double d=1.0, BranchTbl tbl=nullptr)
Select variable with largest accumulated failure count with decay factor d.
Definition var.hpp:137
SetValBranch SET_VAL_MIN_EXC(void)
Exclude smallest element.
Definition val.hpp:60
IntVarBranch INT_VAR_SIZE_MAX(BranchTbl tbl=nullptr)
Select variable with largest domain size.
Definition var.hpp:211
SetVarBranch SET_VAR_SIZE_MAX(BranchTbl tbl=nullptr)
Select variable with largest unknown set.
Definition var.hpp:211
IntValBranch INT_VAL_RND(Rnd r)
Select random value.
Definition val.hpp:70
SetVarBranch SET_VAR_ACTION_MAX(double d=1.0, BranchTbl tbl=nullptr)
Select variable with highest action with decay factor d.
Definition var.hpp:156
FloatVarBranch FLOAT_VAR_ACTION_SIZE_MIN(double d=1.0, BranchTbl tbl=nullptr)
Select variable with smallest action divided by domain size with decay factor d.
Definition var.hpp:247
Gecode::IntArgs i({1, 2, 3, 4})
Options opt
The options.
Definition test.cpp:163
const Val & some(void) const
Definition option.hh:47
size_t operator()(const Gecode::DFA &d) const
Return hash key for d.
Definition flatzinc.cpp:83
size_t operator()(const Gecode::SharedArray< int > &x) const
Return hash key for x.
Definition flatzinc.cpp:72
size_t operator()(const Gecode::TupleSet &x) const
Return hash key for x.
Definition flatzinc.cpp:63
#define GECODE_HAS_FLOAT_VARS
Definition config.hpp:75
#define GECODE_HAS_SET_VARS
Definition config.hpp:105
#define forceinline
Definition config.hpp:144