54 namespace Gecode {
namespace FlatZinc {
89 int_varsel(int_varsel0), int_valsel(int_valsel0),
90 bool_varsel(bool_varsel0), bool_valsel(bool_valsel0)
91 #ifdef GECODE_HAS_SET_VARS
92 , set_varsel(set_varsel0), set_valsel(set_valsel0)
94 #ifdef GECODE_HAS_FLOAT_VARS
95 , float_varsel(float_varsel0), float_valsel(float_valsel0)
100 :
Brancher(home, share, b), done(b.done) {}
111 virtual size_t size(
void)
const {
125 #ifdef GECODE_HAS_SET_VARS 129 #ifdef GECODE_HAS_FLOAT_VARS 137 if (done)
return false;
143 #ifdef GECODE_HAS_SET_VARS 147 #ifdef GECODE_HAS_FLOAT_VARS 161 #ifdef GECODE_HAS_SET_VARS 164 #ifdef GECODE_HAS_FLOAT_VARS 171 return new Choice(*
this,
false);
173 return new Choice(*
this,
true);
178 bool fail; e >> fail;
179 return new Choice(*
this, fail);
188 std::ostream& o)
const {
190 << (
static_cast<const Choice&
>(
c).fail ?
"fail" :
"ok")
215 bool_varsel, bool_valsel
216 #ifdef GECODE_HAS_SET_VARS
217 , set_varsel, set_valsel
219 #ifdef GECODE_HAS_FLOAT_VARS
220 , float_varsel, float_valsel
226 return sizeof(*this);
236 BI(
void) : r0(
""), r1(
""),
n(0) {}
237 BI(
const string& r00,
const string& r10,
const vector<string>& n0)
238 : r0(r00), r1(r10),
n(n0) {}
252 const vector<string>&
n) {
253 v.resize(
std::max(static_cast<unsigned int>(v.size()),bg.
id()+1));
254 v[bg.
id()] = BI(rel0,rel1,n);
258 unsigned int a,
int i,
int n, ostream& o)
const {
260 o << bi.n[
i] <<
" " << (a==0 ? bi.r0 : bi.r1) <<
" " << n;
262 #ifdef GECODE_HAS_FLOAT_VARS 268 << (((a == 0) == nl.
l) ?
"<=" :
">=") << nl.
n;
273 BranchInformation::BranchInformation(
void)
281 assert(
object() == NULL);
287 const std::string& rel0,
288 const std::string& rel1,
289 const std::vector<std::string>&
n) {
294 int n, std::ostream& o)
const {
297 #ifdef GECODE_HAS_FLOAT_VARS 307 Var,
int i,
const int&
n,
312 #ifdef GECODE_HAS_FLOAT_VARS 338 int* newdom =
heap.
alloc<
int>(
static_cast<unsigned long int>(sl->
s.size()));
339 for (
int i=sl->
s.size();
i--;)
340 newdom[
i] = sl->
s[
i];
341 IntSet ret(newdom, sl->
s.size());
342 heap.
free(newdom, static_cast<unsigned long int>(sl->
s.size()));
374 if (
AST::Atom* s = dynamic_cast<AST::Atom*>(ann)) {
375 if (s->id ==
"input_order")
377 if (s->id ==
"first_fail")
379 if (s->id ==
"anti_first_fail")
381 if (s->id ==
"smallest")
383 if (s->id ==
"largest")
385 if (s->id ==
"occurrence")
387 if (s->id ==
"max_regret")
389 if (s->id ==
"most_constrained")
392 if (s->id ==
"random") {
395 if (s->id ==
"dom_w_deg") {
398 if (s->id ==
"afc_min")
400 if (s->id ==
"afc_max")
402 if (s->id ==
"afc_size_min")
404 if (s->id ==
"afc_size_max") {
407 if (s->id ==
"action_min")
409 if (s->id ==
"action_max")
411 if (s->id ==
"action_size_min")
413 if (s->id ==
"action_size_max")
416 std::cerr <<
"Warning, ignored search annotation: ";
417 ann->
print(std::cerr);
418 std::cerr << std::endl;
424 if (
AST::Atom* s = dynamic_cast<AST::Atom*>(ann)) {
425 if (s->id ==
"indomain_min") {
429 if (s->id ==
"indomain_max") {
433 if (s->id ==
"indomain_median") {
437 if (s->id ==
"indomain_split") {
441 if (s->id ==
"indomain_reverse_split") {
445 if (s->id ==
"indomain_random") {
449 if (s->id ==
"indomain") {
453 if (s->id ==
"indomain_middle") {
454 std::cerr <<
"Warning, replacing unsupported annotation " 455 <<
"indomain_middle with indomain_median" << std::endl;
459 if (s->id ==
"indomain_interval") {
460 std::cerr <<
"Warning, replacing unsupported annotation " 461 <<
"indomain_interval with indomain_split" << std::endl;
466 std::cerr <<
"Warning, ignored search annotation: ";
467 ann->
print(std::cerr);
468 std::cerr << std::endl;
474 if (
AST::Atom* s = dynamic_cast<AST::Atom*>(ann)) {
475 if (s->id ==
"indomain_min")
477 if (s->id ==
"indomain_max")
479 if (s->id ==
"indomain_median")
481 if (s->id ==
"indomain_random") {
485 std::cerr <<
"Warning, ignored search annotation: ";
486 ann->
print(std::cerr);
487 std::cerr << std::endl;
492 if (
AST::Atom* s = dynamic_cast<AST::Atom*>(ann)) {
493 if ((s->id ==
"input_order") ||
494 (s->id ==
"first_fail") ||
495 (s->id ==
"anti_first_fail") ||
496 (s->id ==
"smallest") ||
497 (s->id ==
"largest") ||
498 (s->id ==
"max_regret"))
500 if ((s->id ==
"occurrence") ||
501 (s->id ==
"most_constrained"))
503 if (s->id ==
"random")
505 if ((s->id ==
"afc_min") ||
506 (s->id ==
"afc_size_min"))
508 if ((s->id ==
"afc_max") ||
509 (s->id ==
"afc_size_max") ||
510 (s->id ==
"dom_w_deg"))
512 if ((s->id ==
"action_min") &&
513 (s->id ==
"action_size_min"))
515 if ((s->id ==
"action_max") ||
516 (s->id ==
"action_size_max"))
519 std::cerr <<
"Warning, ignored search annotation: ";
520 ann->
print(std::cerr);
521 std::cerr << std::endl;
527 if (
AST::Atom* s = dynamic_cast<AST::Atom*>(ann)) {
528 if (s->id ==
"indomain_min") {
532 if (s->id ==
"indomain_max") {
536 if (s->id ==
"indomain_median") {
540 if (s->id ==
"indomain_split") {
544 if (s->id ==
"indomain_reverse_split") {
548 if (s->id ==
"indomain_random") {
552 if (s->id ==
"indomain") {
556 if (s->id ==
"indomain_middle") {
557 std::cerr <<
"Warning, replacing unsupported annotation " 558 <<
"indomain_middle with indomain_median" << std::endl;
562 if (s->id ==
"indomain_interval") {
563 std::cerr <<
"Warning, replacing unsupported annotation " 564 <<
"indomain_interval with indomain_split" << std::endl;
569 std::cerr <<
"Warning, ignored search annotation: ";
570 ann->
print(std::cerr);
571 std::cerr << std::endl;
577 if (
AST::Atom* s = dynamic_cast<AST::Atom*>(ann)) {
578 if ((s->id ==
"indomain_min") ||
579 (s->id ==
"indomain_median"))
581 if (s->id ==
"indomain_max")
583 if (s->id ==
"indomain_random") {
587 std::cerr <<
"Warning, ignored search annotation: ";
588 ann->
print(std::cerr);
589 std::cerr << std::endl;
593 #ifdef GECODE_HAS_SET_VARS 595 if (
AST::Atom* s = dynamic_cast<AST::Atom*>(ann)) {
596 if (s->id ==
"input_order")
598 if (s->id ==
"first_fail")
600 if (s->id ==
"anti_first_fail")
602 if (s->id ==
"smallest")
604 if (s->id ==
"largest")
606 if (s->id ==
"afc_min")
608 if (s->id ==
"afc_max")
610 if (s->id ==
"afc_size_min")
612 if (s->id ==
"afc_size_max")
614 if (s->id ==
"action_min")
616 if (s->id ==
"action_max")
618 if (s->id ==
"action_size_min")
620 if (s->id ==
"action_size_max")
622 if (s->id ==
"random") {
626 std::cerr <<
"Warning, ignored search annotation: ";
627 ann->
print(std::cerr);
628 std::cerr << std::endl;
635 if (
AST::Atom* s = dynamic_cast<AST::Atom*>(ann)) {
636 if (s->id ==
"indomain_min") {
637 r0 =
"in"; r1 =
"not in";
640 if (s->id ==
"indomain_max") {
641 r0 =
"in"; r1 =
"not in";
644 if (s->id ==
"outdomain_min") {
645 r1 =
"in"; r0 =
"not in";
648 if (s->id ==
"outdomain_max") {
649 r1 =
"in"; r0 =
"not in";
653 std::cerr <<
"Warning, ignored search annotation: ";
654 ann->
print(std::cerr);
655 std::cerr << std::endl;
656 r0 =
"in"; r1 =
"not in";
661 #ifdef GECODE_HAS_FLOAT_VARS 664 if (
AST::Atom* s = dynamic_cast<AST::Atom*>(ann)) {
665 if (s->id ==
"input_order")
667 if (s->id ==
"first_fail")
669 if (s->id ==
"anti_first_fail")
671 if (s->id ==
"smallest")
673 if (s->id ==
"largest")
675 if (s->id ==
"occurrence")
677 if (s->id ==
"most_constrained")
680 if (s->id ==
"random") {
683 if (s->id ==
"afc_min")
685 if (s->id ==
"afc_max")
687 if (s->id ==
"afc_size_min")
689 if (s->id ==
"afc_size_max")
691 if (s->id ==
"action_min")
693 if (s->id ==
"action_max")
695 if (s->id ==
"action_size_min")
697 if (s->id ==
"action_size_max")
700 std::cerr <<
"Warning, ignored search annotation: ";
701 ann->
print(std::cerr);
702 std::cerr << std::endl;
707 if (
AST::Atom* s = dynamic_cast<AST::Atom*>(ann)) {
708 if (s->id ==
"indomain_split") {
712 if (s->id ==
"indomain_reverse_split") {
717 std::cerr <<
"Warning, ignored search annotation: ";
718 ann->
print(std::cerr);
719 std::cerr << std::endl;
727 :
Space(share, f), _random(f._random),
728 _solveAnnotations(NULL), iv_boolalias(NULL),
732 needAuxVars(f.needAuxVars) {
748 iva[iva.
size()-1].update(*
this, share, f.
iv_aux[
i]);
761 bva[bva.
size()-1].update(*
this, share, f.
bv_aux[
i]);
767 #ifdef GECODE_HAS_SET_VARS 775 sva[sva.
size()-1].update(*
this, share, f.
sv_aux[
i]);
781 #ifdef GECODE_HAS_FLOAT_VARS 789 fva[fva.
size()-1].update(*
this, share, f.
fv_aux[
i]);
807 int setVars,
int floatVars) {
818 #ifdef GECODE_HAS_SET_VARS 823 #ifdef GECODE_HAS_FLOAT_VARS 868 #ifdef GECODE_HAS_SET_VARS 880 int* is =
heap.
alloc<
int>(
static_cast<unsigned long int>(vsv->s.size()));
881 for (
int i=vsv->s.
size();
i--; )
884 heap.
free(is,static_cast<unsigned long int>(vsv->s.size()));
893 int* is =
heap.
alloc<
int>(
static_cast<unsigned long int>(vsv->
s.size()));
894 for (
int i=vsv->
s.size();
i--; )
897 heap.
free(is,static_cast<unsigned long int>(vsv->
s.size()));
915 #ifdef GECODE_HAS_FLOAT_VARS 946 struct ConExprOrder {
948 return ce0->
args->
a.size() < ce1->
args->
a.size();
958 for (
unsigned int i=0;
i<ces.
size();
i++) {
973 for (
unsigned int i=0;
i<ann->
a.size();
i++) {
974 if (ann->
a[
i]->isCall(
"seq_search")) {
979 out.push_back(c->
args);
981 out.push_back(ann->
a[
i]);
991 Rnd rnd(static_cast<unsigned int>(seed));
994 std::string def_int_rel_left =
"=";
995 std::string def_int_rel_right =
"!=";
998 std::string def_bool_rel_left =
"=";
999 std::string def_bool_rel_right =
"!=";
1000 #ifdef GECODE_HAS_SET_VARS 1003 std::string def_set_rel_left =
"in";
1004 std::string def_set_rel_right =
"not in";
1006 #ifdef GECODE_HAS_FLOAT_VARS 1009 std::string def_float_rel_left =
"<=";
1010 std::string def_float_rel_right =
">";
1013 std::vector<bool> iv_searched(
iv.
size());
1014 for (
unsigned int i=
iv.
size();
i--;)
1015 iv_searched[
i] =
false;
1016 std::vector<bool> bv_searched(
bv.
size());
1017 for (
unsigned int i=
bv.
size();
i--;)
1018 bv_searched[
i] =
false;
1019 #ifdef GECODE_HAS_SET_VARS 1020 std::vector<bool> sv_searched(
sv.
size());
1021 for (
unsigned int i=
sv.
size();
i--;)
1022 sv_searched[
i] =
false;
1024 #ifdef GECODE_HAS_FLOAT_VARS 1025 std::vector<bool> fv_searched(
fv.
size());
1026 for (
unsigned int i=
fv.
size();
i--;)
1027 fv_searched[
i] =
false;
1032 std::vector<AST::Node*> flatAnn;
1036 flatAnn.push_back(ann);
1039 for (
unsigned int i=0;
i<flatAnn.
size();
i++) {
1040 if (flatAnn[
i]->isCall(
"relax_and_reconstruct")) {
1043 "Only one relax_and_reconstruct annotation allowed");
1051 _lns = args->
a[1]->getInt();
1053 int k=vars->
a.size();
1054 for (
int i=vars->
a.size();
i--;)
1055 if (vars->
a[
i]->isInt())
1059 for (
unsigned int i=0;
i<vars->
a.size();
i++) {
1060 if (vars->
a[
i]->isInt())
1064 if (args->
a.size()==3) {
1067 for (
unsigned int i=initial->
a.size();
i--;)
1070 }
else if (flatAnn[
i]->isCall(
"gecode_search")) {
1072 branchWithPlugin(c->
args);
1073 }
else if (flatAnn[
i]->isCall(
"int_search")) {
1077 int k=vars->
a.size();
1078 for (
int i=vars->
a.size();
i--;)
1079 if (vars->
a[
i]->isInt())
1082 vector<string> names;
1084 for (
unsigned int i=0;
i<vars->
a.size();
i++) {
1085 if (vars->
a[
i]->isInt())
1087 va[k++] =
iv[vars->
a[
i]->getIntVar()];
1088 iv_searched[vars->
a[
i]->getIntVar()] =
true;
1089 names.push_back(vars->
a[
i]->getVarName());
1098 &varValPrint<IntVar>);
1101 }
else if (flatAnn[
i]->isCall(
"int_assign")) {
1105 int k=vars->
a.size();
1106 for (
int i=vars->
a.size();
i--;)
1107 if (vars->
a[
i]->isInt())
1111 for (
unsigned int i=0;
i<vars->
a.size();
i++) {
1112 if (vars->
a[
i]->isInt())
1114 va[k++] =
iv[vars->
a[
i]->getIntVar()];
1115 iv_searched[vars->
a[
i]->getIntVar()] =
true;
1118 &varValPrint<IntVar>);
1119 }
else if (flatAnn[
i]->isCall(
"bool_search")) {
1123 int k=vars->
a.size();
1124 for (
int i=vars->
a.size();
i--;)
1125 if (vars->
a[
i]->isBool())
1129 vector<string> names;
1130 for (
unsigned int i=0;
i<vars->
a.size();
i++) {
1131 if (vars->
a[
i]->isBool())
1133 va[k++] =
bv[vars->
a[
i]->getBoolVar()];
1134 bv_searched[vars->
a[
i]->getBoolVar()] =
true;
1135 names.push_back(vars->
a[
i]->getVarName());
1145 &varValPrint<BoolVar>);
1148 }
else if (flatAnn[
i]->isCall(
"int_default_search")) {
1153 def_int_rel_left,def_int_rel_right,rnd);
1154 }
else if (flatAnn[
i]->isCall(
"bool_default_search")) {
1159 def_bool_rel_left,def_bool_rel_right,
1161 }
else if (flatAnn[
i]->isCall(
"set_search")) {
1162 #ifdef GECODE_HAS_SET_VARS 1166 int k=vars->
a.size();
1167 for (
int i=vars->
a.size();
i--;)
1168 if (vars->
a[
i]->isSet())
1172 vector<string> names;
1173 for (
unsigned int i=0;
i<vars->
a.size();
i++) {
1174 if (vars->
a[
i]->isSet())
1176 va[k++] =
sv[vars->
a[
i]->getSetVar()];
1177 sv_searched[vars->
a[
i]->getSetVar()] =
true;
1178 names.push_back(vars->
a[
i]->getVarName());
1187 &varValPrint<SetVar>);
1191 if (!ignoreUnknown) {
1192 err <<
"Warning, ignored search annotation: ";
1193 flatAnn[
i]->print(err);
1197 }
else if (flatAnn[
i]->isCall(
"set_default_search")) {
1198 #ifdef GECODE_HAS_SET_VARS 1203 def_set_rel_left,def_set_rel_right,rnd);
1205 if (!ignoreUnknown) {
1206 err <<
"Warning, ignored search annotation: ";
1207 flatAnn[
i]->print(err);
1211 }
else if (flatAnn[
i]->isCall(
"float_default_search")) {
1212 #ifdef GECODE_HAS_FLOAT_VARS 1217 def_float_rel_left,def_float_rel_right);
1219 if (!ignoreUnknown) {
1220 err <<
"Warning, ignored search annotation: ";
1221 flatAnn[
i]->print(err);
1225 }
else if (flatAnn[
i]->isCall(
"float_search")) {
1226 #ifdef GECODE_HAS_FLOAT_VARS 1230 int k=vars->
a.size();
1231 for (
int i=vars->
a.size();
i--;)
1232 if (vars->
a[
i]->isFloat())
1236 vector<string> names;
1237 for (
unsigned int i=0;
i<vars->
a.size();
i++) {
1238 if (vars->
a[
i]->isFloat())
1240 va[k++] =
fv[vars->
a[
i]->getFloatVar()];
1241 fv_searched[vars->
a[
i]->getFloatVar()] =
true;
1242 names.push_back(vars->
a[
i]->getVarName());
1255 if (!ignoreUnknown) {
1256 err <<
"Warning, ignored search annotation: ";
1257 flatAnn[
i]->print(err);
1262 if (!ignoreUnknown) {
1263 err <<
"Warning, ignored search annotation: ";
1264 flatAnn[
i]->print(err);
1284 std::vector<std::string> iv_sol_names(
iv.
size()-(introduced+funcdep+searched));
1286 std::vector<std::string> iv_tmp_names(introduced);
1288 for (
int i=
iv.
size(), j=0, k=0;
i--;) {
1294 iv_tmp[j++] =
iv[
i];
1298 iv_sol[k++] =
iv[
i];
1306 if (bv_searched[
i]) {
1316 std::vector<std::string> bv_sol_names(
bv.
size()-(introduced+funcdep+searched));
1319 std::vector<std::string> bv_tmp_names(introduced);
1320 for (
int i=
bv.
size(), j=0, k=0;
i--;) {
1326 bv_tmp[j++] =
bv[
i];
1330 bv_sol[k++] =
bv[
i];
1334 if (iv_sol.
size() > 0) {
1336 branch(bg(*
this), iv_sol, def_int_varsel, def_int_valsel,
nullptr,
1337 &varValPrint<IntVar>);
1338 branchInfo.
add(bg,def_int_rel_left,def_int_rel_right,iv_sol_names);
1340 if (bv_sol.
size() > 0) {
1342 branch(bg(*
this), bv_sol, def_bool_varsel, def_bool_valsel,
nullptr,
1343 &varValPrint<BoolVar>);
1344 branchInfo.
add(bg,def_bool_rel_left,def_bool_rel_right,bv_sol_names);
1346 #ifdef GECODE_HAS_FLOAT_VARS 1361 std::vector<std::string> fv_sol_names(
fv.
size()-(introduced+funcdep+searched));
1364 std::vector<std::string> fv_tmp_names(introduced);
1365 for (
int i=
fv.
size(), j=0, k=0;
i--;) {
1371 fv_tmp[j++] =
fv[
i];
1375 fv_sol[k++] =
fv[
i];
1379 if (fv_sol.
size() > 0) {
1381 branch(bg(*
this), fv_sol, def_float_varsel, def_float_valsel,
nullptr,
1383 branchInfo.
add(bg,def_float_rel_left,def_float_rel_right,fv_sol_names);
1386 #ifdef GECODE_HAS_SET_VARS 1391 if (sv_searched[
i]) {
1401 std::vector<std::string> sv_sol_names(
sv.
size()-(introduced+funcdep+searched));
1404 std::vector<std::string> sv_tmp_names(introduced);
1405 for (
int i=
sv.
size(), j=0, k=0;
i--;) {
1411 sv_tmp[j++] =
sv[
i];
1415 sv_sol[k++] =
sv[
i];
1419 if (sv_sol.
size() > 0) {
1421 branch(bg(*
this), sv_sol, def_set_varsel, def_set_valsel,
nullptr,
1422 &varValPrint<SetVar>);
1423 branchInfo.
add(bg,def_set_rel_left,def_set_rel_right,sv_sol_names);
1430 #ifdef GECODE_HAS_SET_VARS 1434 #ifdef GECODE_HAS_FLOAT_VARS 1441 std::vector<std::string> names(1);
1445 &varValPrint<IntVar>);
1448 #ifdef GECODE_HAS_FLOAT_VARS 1449 std::vector<std::string> names(1);
1459 std::vector<std::string> names(1);
1463 &varValPrint<IntVar>);
1466 #ifdef GECODE_HAS_FLOAT_VARS 1467 std::vector<std::string> names(1);
1480 def_bool_varsel, def_bool_valsel
1482 , def_set_varsel, def_set_valsel
1485 , def_float_varsel, def_float_valsel
1491 branch(bg(*
this),
iv_aux,def_int_varsel,def_int_valsel,
nullptr,
1492 &varValPrint<IntVar>);
1493 branchInfo.
add(bg,def_int_rel_left,def_int_rel_right,iv_tmp_names);
1497 branch(bg(*
this),
bv_aux,def_bool_varsel,def_bool_valsel,
nullptr,
1498 &varValPrint<BoolVar>);
1499 branchInfo.
add(bg,def_bool_rel_left,def_bool_rel_right,bv_tmp_names);
1501 #ifdef GECODE_HAS_SET_VARS 1504 branch(bg(*
this),
sv_aux,def_set_varsel,def_set_valsel,
nullptr,
1505 &varValPrint<SetVar>);
1506 branchInfo.
add(bg,def_set_rel_left,def_set_rel_right,sv_tmp_names);
1509 #ifdef GECODE_HAS_FLOAT_VARS 1512 branch(bg(*
this),
fv_aux,def_float_varsel,def_float_valsel,
nullptr,
1514 branchInfo.
add(bg,def_float_rel_left,def_float_rel_right,fv_tmp_names);
1553 #ifdef GECODE_HAS_GIST 1558 template<
class Engine>
1563 template<
typename S>
1577 template<
typename S>
1600 virtual void inspect(
const Space& node);
1602 virtual void finalize(
void);
1607 : TextOutput(
"Gecode/FlatZinc"),
p(p0) {}
1638 :
Gecode::Gist::VarComparator<S>(
"Gecode/FlatZinc"),
p(p0) {}
1645 dynamic_cast<const S&
>(s0).
compare(dynamic_cast<const S&>(s1),
1656 template<
template<
class>
class Engine>
1658 FlatZincSpace::runEngine(std::ostream& out,
const Printer& p,
1661 runMeta<Engine,Driver::EngineToMeta>(out,p,
opt,t_total);
1663 runMeta<Engine,RBS>(out,p,
opt,t_total);
1667 template<
template<
class>
class Engine,
1668 template<
class,
template<
class>
class>
class Meta>
1670 FlatZincSpace::runMeta(std::ostream& out, const Printer& p,
1671 const FlatZincOptions& opt, Support::Timer& t_total) {
1672 #ifdef GECODE_HAS_GIST 1681 unsigned int n_p = 0;
1692 #ifdef GECODE_HAS_FLOAT_VARS 1700 Meta<FlatZincSpace,Engine> se(
this,o);
1702 if (noOfSolutions == -1) {
1703 noOfSolutions = (_method == SAT) ? 1 : 0;
1705 bool printAll = _method == SAT || opt.
allSolutions() || noOfSolutions != 0;
1706 int findSol = noOfSolutions;
1707 FlatZincSpace* sol = NULL;
1708 while (FlatZincSpace* next_sol = se.next()) {
1713 out <<
"----------" << std::endl;
1718 if (sol && !printAll) {
1720 out <<
"----------" << std::endl;
1722 if (!se.stopped()) {
1724 out <<
"==========" << endl;
1726 out <<
"=====UNSATISFIABLE=====" << endl;
1729 out <<
"=====UNKNOWN=====" << endl;
1741 <<
"%% solvetime: ";
1745 <<
std::abs(noOfSolutions - findSol) << endl
1747 << (intVarCount + boolVarCount + setVarCount) << endl
1748 <<
"%% propagators: " << n_p << endl
1750 <<
"%% nodes: " << stat.
node << endl
1751 <<
"%% failures: " << stat.
fail << endl
1752 <<
"%% restarts: " << stat.
restart << endl
1753 <<
"%% peak depth: " << stat.
depth << endl
1759 #ifdef GECODE_HAS_QT 1761 FlatZincSpace::branchWithPlugin(
AST::Node* ann) {
1762 if (
AST::Call*
c = dynamic_cast<AST::Call*>(ann)) {
1763 QString pluginName(
c->id.c_str());
1764 if (QLibrary::isLibrary(pluginName+
".dll")) {
1765 pluginName +=
".dll";
1766 }
else if (QLibrary::isLibrary(pluginName+
".dylib")) {
1767 pluginName =
"lib" + pluginName +
".dylib";
1768 }
else if (QLibrary::isLibrary(pluginName+
".so")) {
1770 pluginName =
"lib" + pluginName +
".so";
1772 QPluginLoader pl(pluginName);
1773 QObject* plugin_o = pl.instance();
1776 "Error loading plugin "+pluginName.toStdString()+
1777 ": "+pl.errorString().toStdString());
1779 BranchPlugin* pb = qobject_cast<BranchPlugin*>(plugin_o);
1782 "Error loading plugin "+pluginName.toStdString()+
1783 ": does not contain valid PluginBrancher");
1785 pb->branch(*
this,
c);
1790 FlatZincSpace::branchWithPlugin(
AST::Node*) {
1792 "Branching with plugins not supported (requires Qt support)");
1802 runEngine<BAB>(out,p,
opt,t_total);
1805 runEngine<DFS>(out,p,
opt,t_total);
1815 static_cast<const FlatZincSpace*>(&s)->iv[_optVar].val());
1816 else if (_method == MAX)
1818 static_cast<const FlatZincSpace*>(&s)->iv[_optVar].val());
1820 #ifdef GECODE_HAS_FLOAT_VARS 1823 static_cast<const FlatZincSpace*>(&s)->fv[_optVar].val()-
step);
1824 else if (_method == MAX)
1826 static_cast<const FlatZincSpace*>(&s)->fv[_optVar].val()+
step);
1834 (_lns > 0) && (mi.
last()==NULL) && (_lnsInitialSolution.size()>0)) {
1835 for (
unsigned int i=iv_lns.
size();
i--;) {
1836 if ((*_random)(99) <= _lns) {
1837 rel(*
this, iv_lns[
i],
IRT_EQ, _lnsInitialSolution[i]);
1842 (_lns > 0) && mi.
last()) {
1843 const FlatZincSpace& last =
1844 static_cast<const FlatZincSpace&
>(*mi.
last());
1845 for (
unsigned int i=iv_lns.
size();
i--;) {
1846 if ((*_random)(99) <= _lns) {
1857 return new FlatZincSpace(share, *
this);
1872 return _optVarIsInt;
1889 (void) s; (void) out;
1890 #ifdef GECODE_HAS_GIST 1891 const FlatZincSpace& fs =
dynamic_cast<const FlatZincSpace&
>(s);
1892 for (
int i = 0;
i < iv.
size(); ++
i) {
1893 std::stringstream ss;
1894 ss <<
"iv[" <<
i <<
"]";
1897 if (result.length() > 0) out << result << std::endl;
1899 for (
int i = 0;
i < bv.
size(); ++
i) {
1900 std::stringstream ss;
1901 ss <<
"bv[" <<
i <<
"]";
1904 if (result.length() > 0) out << result << std::endl;
1906 #ifdef GECODE_HAS_SET_VARS 1907 for (
int i = 0;
i < sv.
size(); ++
i) {
1908 std::stringstream ss;
1909 ss <<
"sv[" <<
i <<
"]";
1912 if (result.length() > 0) out << result << std::endl;
1915 #ifdef GECODE_HAS_FLOAT_VARS 1916 for (
int i = 0;
i < fv.
size(); ++
i) {
1917 std::stringstream ss;
1918 ss <<
"fv[" <<
i <<
"]";
1921 if (result.length() > 0) out << result << std::endl;
1956 for (
int i=offset;
i--;)
1958 for (
int i=a->
a.size();
i--;)
1959 ia[
i+offset] = a->
a[
i]->getInt();
1966 for (
int i=offset;
i--;)
1968 for (
int i=a->
a.size();
i--;)
1969 ia[
i+offset] = a->
a[
i]->getBool();
1980 int* is = re.
alloc<
int>(
static_cast<unsigned long int>(sl->
s.size()));
1981 for (
int i=sl->
s.size();
i--; )
1990 if (a->
a.size() == 0) {
1995 for (
int i=offset;
i--;)
1997 for (
int i=a->
a.size();
i--;) {
1998 ia[
i+offset] = arg2intset(a->
a[
i]);
2005 if (a->
a.size() == 0) {
2010 for (
int i=offset;
i--;)
2012 for (
int i=a->
a.size();
i--;) {
2013 if (a->
a[
i]->isIntVar()) {
2014 ia[
i+offset] = iv[a->
a[
i]->getIntVar()];
2016 int value = a->
a[
i]->getInt();
2017 IntVar iv(*
this, value, value);
2026 if (a->
a.size() == 0) {
2031 for (
int i=offset;
i--;)
2033 for (
int i=0; i<static_cast<int>(a->
a.size());
i++) {
2036 if (a->
a[
i]->isBool()) {
2037 bool value = a->
a[
i]->getBool();
2038 BoolVar iv(*
this, value, value);
2040 }
else if (a->
a[
i]->isIntVar() &&
2041 aliasBool2Int(a->
a[
i]->getIntVar()) != -1) {
2042 ia[offset++] = bv[aliasBool2Int(a->
a[
i]->getIntVar())];
2044 ia[offset++] = bv[a->
a[
i]->getBoolVar()];
2074 if (a->
a.size() == 0)
2076 for (
int i=a->
a.size();
i--;) {
2077 if (a->
a[
i]->isBoolVar() || a->
a[
i]->isBool()) {
2078 }
else if (a->
a[
i]->isIntVar()) {
2079 if (aliasBool2Int(a->
a[
i]->getIntVar()) == -1) {
2080 if (singleInt != -1) {
2089 return singleInt==-1 || a->
a.size() > 1;
2091 #ifdef GECODE_HAS_SET_VARS 2097 x0 =
SetVar(*
this, d, d);
2108 for (
int i=offset;
i--;) {
2112 for (
int i=a->
a.size();
i--;) {
2113 ia[
i+offset] = arg2SetVar(a->
a[
i]);
2118 #ifdef GECODE_HAS_FLOAT_VARS 2123 for (
int i=offset;
i--;)
2125 for (
int i=a->
a.size();
i--;)
2126 fa[
i+offset] = a->
a[
i]->getFloat();
2132 if (a->
a.size() == 0) {
2137 for (
int i=offset;
i--;)
2139 for (
int i=a->
a.size();
i--;) {
2140 if (a->
a[
i]->isFloatVar()) {
2141 fa[
i+offset] = fv[a->
a[
i]->getFloatVar()];
2143 double value = a->
a[
i]->getFloat();
2184 Printer::printElem(std::ostream& out,
2204 }
else if (bv[ai->
getBoolVar()].max() == 0) {
2207 out <<
"false..true";
2209 #ifdef GECODE_HAS_SET_VARS 2220 int min = svr.min();
2221 int max = svr.max();
2228 for (; svv(); ++svv)
2229 out <<
", " << svv.val();
2232 out << min <<
".." <<
max;
2235 #ifdef GECODE_HAS_FLOAT_VARS 2246 std::ostringstream oss;
2248 oss << std::setprecision(std::numeric_limits<double>::digits10);
2250 if (oss.str().find(
".") == std::string::npos)
2257 }
else if (ai->
isBool()) {
2258 out << (ai->
getBool() ?
"true" :
"false");
2259 }
else if (ai->
isSet()) {
2262 out << s->
min <<
".." << s->
max;
2265 for (
unsigned int i=0;
i<s->
s.size();
i++) {
2266 out << s->
s[
i] << (
i < s->
s.size()-1 ?
", " :
"}");
2271 for (
unsigned int i=0;
i<s.
size();
i++) {
2272 if (s[
i] ==
'\\' &&
i<s.
size()-1) {
2274 case 'n': out <<
"\n";
break;
2275 case '\\': out <<
"\\";
break;
2276 case 't': out <<
"\t";
break;
2277 default: out <<
"\\" << s[
i+1];
2288 Printer::printElemDiff(std::ostream& out,
2294 #ifdef GECODE_HAS_SET_VARS
2298 #ifdef GECODE_HAS_FLOAT_VARS
2303 #ifdef GECODE_HAS_GIST 2311 if (res.length() > 0) {
2320 if (res.length() > 0) {
2326 #ifdef GECODE_HAS_SET_VARS 2330 if (res.length() > 0) {
2337 #ifdef GECODE_HAS_FLOAT_VARS 2341 if (res.length() > 0) {
2348 }
else if (ai->
isBool()) {
2349 out << (ai->
getBool() ?
"true" :
"false");
2350 }
else if (ai->
isSet()) {
2353 out << s->
min <<
".." << s->
max;
2356 for (
unsigned int i=0;
i<s->
s.size();
i++) {
2357 out << s->
s[
i] << (
i < s->
s.size()-1 ?
", " :
"}");
2362 for (
unsigned int i=0;
i<s.
size();
i++) {
2363 if (s[
i] ==
'\\' &&
i<s.
size()-1) {
2365 case 'n': out <<
"\n";
break;
2366 case '\\': out <<
"\\";
break;
2367 case 't': out <<
"\t";
break;
2368 default: out <<
"\\" << s[
i+1];
2383 #ifdef GECODE_HAS_SET_VARS 2387 #ifdef GECODE_HAS_FLOAT_VARS 2399 #ifdef GECODE_HAS_SET_VARS
2403 #ifdef GECODE_HAS_FLOAT_VARS
2408 if (_output == NULL)
2410 for (
unsigned int i=0;
i< _output->
a.size();
i++) {
2414 int size = aia->
a.size();
2416 for (
int j=0; j<
size; j++) {
2417 printElem(out,aia->
a[j],iv,bv
2418 #ifdef GECODE_HAS_SET_VARS
2421 #ifdef GECODE_HAS_FLOAT_VARS
2430 printElem(out,ai,iv,bv
2431 #ifdef GECODE_HAS_SET_VARS
2434 #ifdef GECODE_HAS_FLOAT_VARS
2448 #ifdef GECODE_HAS_SET_VARS
2453 #ifdef GECODE_HAS_FLOAT_VARS
2459 if (_output == NULL)
2461 for (
unsigned int i=0;
i< _output->
a.size();
i++) {
2465 int size = aia->
a.size();
2467 for (
int j=0; j<
size; j++) {
2468 printElemDiff(out,aia->
a[j],iv1,iv2,bv1,bv2
2469 #ifdef GECODE_HAS_SET_VARS
2472 #ifdef GECODE_HAS_FLOAT_VARS
2481 printElemDiff(out,ai,iv1,iv2,bv1,bv2
2482 #ifdef GECODE_HAS_SET_VARS
2485 #ifdef GECODE_HAS_FLOAT_VARS
2495 iv_names.push_back(n);
2499 bv_names.push_back(n);
2501 #ifdef GECODE_HAS_FLOAT_VARS 2504 fv_names.push_back(n);
2507 #ifdef GECODE_HAS_SET_VARS 2510 sv_names.push_back(n);
2516 std::map<int,int>& iv, std::map<int,int>& bv,
2517 std::map<int,int>& sv, std::map<int,int>& fv) {
2520 if (iv.find(x->
i) == iv.end()) {
2521 int newi = iv.size();
2527 if (bv.find(x->
i) == bv.end()) {
2528 int newi = bv.size();
2534 if (sv.find(x->
i) == sv.end()) {
2535 int newi = sv.size();
2541 if (fv.find(x->
i) == fv.end()) {
2542 int newi = fv.size();
2551 int& optVar,
bool optVarIsInt,
2554 #ifdef GECODE_HAS_SET_VARS
2558 #ifdef GECODE_HAS_FLOAT_VARS
2563 if (_output == NULL) {
2564 if (optVarIsInt && optVar != -1) {
2573 #ifdef GECODE_HAS_SET_VARS 2576 #ifdef GECODE_HAS_FLOAT_VARS 2577 if (!optVarIsInt && optVar != -1) {
2588 std::map<int,int> iv_new;
2589 std::map<int,int> bv_new;
2590 std::map<int,int> sv_new;
2591 std::map<int,int> fv_new;
2601 for (
unsigned int i=0;
i< _output->
a.size();
i++) {
2605 for (
unsigned int j=0; j<aia->
a.size(); j++) {
2606 shrinkElement(aia->
a[j],iv_new,bv_new,sv_new,fv_new);
2609 shrinkElement(ai,iv_new,bv_new,sv_new,fv_new);
2614 for (map<int,int>::iterator
i=iv_new.
begin();
i != iv_new.
end(); ++
i) {
2615 iva[(*i).second] = iv[(*i).first];
2620 for (map<int,int>::iterator
i=bv_new.
begin();
i != bv_new.
end(); ++
i) {
2621 bva[(*i).second] = bv[(*i).first];
2625 #ifdef GECODE_HAS_SET_VARS 2627 for (map<int,int>::iterator
i=sv_new.
begin();
i != sv_new.
end(); ++
i) {
2628 sva[(*i).second] = sv[(*i).first];
2633 #ifdef GECODE_HAS_FLOAT_VARS 2635 for (map<int,int>::iterator
i=fv_new.
begin();
i != fv_new.
end(); ++
i) {
2636 fva[(*i).second] = fv[(*i).first];
void click(Inspector *i)
Add inspector that reacts on node double clicks.
void shrinkArrays(Printer &p)
Remove all variables not needed for output.
unsigned int a_d
Create a clone during recomputation if distance is greater than a_d (adaptive distance) ...
BoolValBranch BOOL_VAL_RND(Rnd r)
Select random value.
int solutions(void) const
Which values to select for branching first.
Gecode::SetVarArray sv_aux
The introduced set variables.
int floatVarCount
Number of float variables.
const Gecode::FloatNum step
Option< AST::SetLit *> domain
Options for running FlatZinc models
SetVarBranch SET_VAR_SIZE_MIN(BranchTbl tbl)
unsigned int nogoods_limit
Depth limit for extraction of no-goods.
virtual Choice * choice(Space &home)
Return choice.
IntVarBranch INT_VAR_NONE(void)
Select first unassigned variable.
RestartMode restart(void) const
Combine variable selection criteria for tie-breaking.
IntSet vs2is(IntVarSpec *vs)
virtual void print(const Space &, const Gecode::Choice &c, unsigned int, std::ostream &o) const
Print explanation.
Gecode::Support::RandomGenerator random
The actual random number generator.
Which values to select for branching first.
std::ostream & getStream(void)
Get the stream that is used to output text.
BoolVarBranch BOOL_VAR_NONE(void)
Select first unassigned variable.
IntArgs arg2intargs(AST::Node *arg, int offset=0)
Convert arg (array of integers) to IntArgs.
void post(FlatZincSpace &s, const ConExpr &ce)
Post constraint specified by ce.
FloatValBranch FLOAT_VAL_SPLIT_MAX(void)
Select values greater than mean of smallest and largest value.
BoolVarBranch BOOL_VAR_AFC_MIN(double d, BranchTbl tbl)
Select variable with smallest accumulated failure count with decay factor d.
int size(void) const
Return size of array (number of elements)
Traits class for search engines.
const int min
Smallest allowed integer in integer set.
FloatVarArgs arg2floatvarargs(AST::Node *arg, int offset=0)
Convert n to FloatVarArgs.
bool isBool(void)
Test if node is a Boolean node.
BoolAssign BOOL_ASSIGN_MIN(void)
Select smallest value.
virtual Gecode::Space * copy(bool share)
Copy function.
std::vector< bool > sv_introduced
Indicates whether a set variable is introduced by mzn2fzn.
void branch(Home home, const FloatVarArgs &x, FloatVarBranch vars, FloatValBranch vals, FloatBranchFilter bf, FloatVarValPrint vvp)
Branch over x with variable selection vars and value selection vals.
Which values to select for branching first.
bool getBool(void)
Cast this node to a Boolean node.
int size(void) const
Return size of array (number of elements)
const FloatNum max
Largest allowed float value.
#define GECODE_HAS_SET_VARS
Gecode::BoolVarArray bv
The Boolean variables.
void put(unsigned int i)
Add i to the contents.
Meth _method
Whether to solve as satisfaction or optimization problem.
unsigned int c_d
Create a clone after every c_d commits (commit distance)
FloatVarBranch FLOAT_VAR_DEGREE_MAX(BranchTbl tbl)
Select variable with largest degree.
Cutoff generator appending two cutoff generators.
T * alloc(long unsigned int n)
Allocate block of n objects of type T from region.
SetValBranch ann2svalsel(AST::Node *ann, std::string r0, std::string r1, Rnd rnd)
Which values to select for branching first.
SetLit * getSet(void)
Cast this node to a set literal node.
void newIntVar(IntVarSpec *vs)
Create new integer variable from specification.
IntVarBranch INT_VAR_SIZE_MAX(BranchTbl tbl)
Select variable with largest domain size.
Abstract base class for comparators.
Call * getCall(void)
Return function call.
void max(Home home, FloatVar x0, FloatVar x1, FloatVar x2)
Post propagator for .
int getFloatVar(void)
Cast this node to a Float variable node.
Gecode::ScriptMode mode(void) const
Gecode::IntVarArray iv
The integer variables.
void abs(Home home, FloatVar x0, FloatVar x1)
Post propagator for .
static PropagatorGroup all
Group of all propagators.
void stop(Support::Timer &timer, std::ostream &os)
Get time since start of timer and print user friendly time information.
IntAssign INT_ASSIGN_MED(void)
Select greatest value not greater than the median.
Specification for set variables.
FloatVarBranch FLOAT_VAR_AFC_SIZE_MIN(double d, BranchTbl tbl)
Select variable with smalllest accumulated failure count divided by domain size with decay factor d...
virtual void compare(const Space &s0, const Space &s1)
Use the compare method of the template class S to compare two spaces.
BranchInformation branchInfo
Information for printing branches.
void compare(const Space &s, std::ostream &out) const
Compare this space with space s and print the differences on out.
int boolVarCount
Number of Boolean variables.
IntVarBranch INT_VAR_DEGREE_MAX(BranchTbl tbl)
Select variable with largest degree.
BoolVarBranch BOOL_VAR_ACTION_MIN(double d, BranchTbl tbl)
Select variable with lowest action with decay factor d.
bool assigned(void) const
Test if all variables are assigned.
IntVarBranch INT_VAR_AFC_MIN(double d, BranchTbl tbl)
Select variable with smallest accumulated failure count with decay factor d.
bool singleton(void) const
Test whether float is a singleton.
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.
void dom(Home home, FloatVar x, FloatVal n)
Propagates .
bool optVarIsInt(void) const
Return whether variable used for optimization is integer (or float)
Which values to select for assignment.
void minimize(int var, bool isInt, AST::Array *annotation)
Post that integer variable var should be minimized.
unsigned long int fail
Number of failed nodes in search tree.
bool isSetVar(void)
Test if node is a set variable node.
bool isBoolVar(void)
Test if node is a Boolean variable node.
unsigned long int depth
Maximum depth of search stack.
TieBreak< IntVarBranch > ann2ivarsel(AST::Node *ann, Rnd rnd, double decay)
FloatValBranch ann2fvalsel(AST::Node *ann, std::string r0, std::string r1)
bool allSolutions(void) const
BoolAssign ann2asnbvalsel(AST::Node *ann, Rnd rnd)
BoolAssign BOOL_ASSIGN_MAX(void)
Select largest value.
int vs2bsh(BoolVarSpec *bs)
IntVarBranch INT_VAR_REGRET_MIN_MAX(BranchTbl tbl)
Select variable with largest min-regret.
SetVarBranch SET_VAR_MAX_MAX(BranchTbl tbl)
Space * clone(bool share_data=true, bool share_info=true, CloneStatistics &stat=unused_clone) const
Clone space.
void init(int intVars, int boolVars, int setVars, int floatVars)
Initialize space with given number of variables.
static void explore(S *root, const FlatZincOptions &opt, Gist::Inspector *i, Gist::Comparator *c)
BoolValBranch ann2bvalsel(AST::Node *ann, std::string &r0, std::string &r1, Rnd rnd)
void varValPrint(const Space &home, const Brancher &b, unsigned int a, Var, int i, const int &n, std::ostream &o)
AuxVarBrancher(Space &home, bool share, AuxVarBrancher &b)
Copy constructor.
Meth method(void) const
Return whether to solve a satisfaction or optimization problem.
unsigned long int propagate
Number of propagator executions.
Search::Cutoff * createCutoff(const Options &o)
Create cutoff object from options.
const int max
Largest allowed integer in integer set.
SetVarBranch SET_VAR_NONE(void)
Array * getArray(void)
Cast this node to an array node.
unsigned int id(void) const
Return a unique id for the group.
A thread-safe random number generator.
struct Gecode::Space::@56::@57 p
Data only available during propagation or branching.
const int max
Largest allowed integer value.
FloatVarBranch FLOAT_VAR_ACTION_SIZE_MIN(double d, BranchTbl tbl)
Select variable with smallest action divided by domain size with decay factor d.
int vs2bsl(BoolVarSpec *bs)
An inspector for printing simple text output.
Abstract base class for inspectors.
FloatVarBranch FLOAT_VAR_NONE(void)
Select first unassigned variable.
unsigned int size(Space &home) const
Return number of propagators in a group.
const int min
Smallest allowed integer value.
Base-class for both propagators and branchers.
virtual size_t size(void) const
Report size occupied.
Statistics for execution of status
void newSetVar(SetVarSpec *vs)
Create new set variable from specification.
IntAssign INT_ASSIGN_MIN(void)
Select smallest value.
IntValBranch INT_VAL_RND(Rnd r)
Select random value.
virtual Choice * choice(const Space &, Archive &e)
Return choice.
std::vector< bool > iv_introduced
Indicates whether an integer variable is introduced by mzn2fzn.
IntVarBranch INT_VAR_MAX_MAX(BranchTbl tbl)
Select variable with largest max.
void newBoolVar(BoolVarSpec *vs)
Create new Boolean variable from specification.
Gecode::Support::Mutex mutex
A mutex for the random number generator.
void update(Space &, bool share, VarArray< Var > &a)
Update array to be a clone of array a.
bool alias
Whether the variable aliases another variable.
SetVarBranch ann2svarsel(AST::Node *ann, Rnd rnd, double decay)
void start(void)
Start timer.
SetVar arg2SetVar(AST::Node *n)
Convert n to SetVar.
unsigned int nogoods_limit(void) const
int getSetVar(void)
Cast this node to a set variable node.
double getFloat(void)
Cast this node to a Float node.
struct Gecode::@579::NNF::@61::@63 a
For atomic nodes.
Gecode::FloatVal c(-8, 8)
FloatVarBranch FLOAT_VAR_SIZE_MAX(BranchTbl tbl)
Select variable with largest domain size.
Cutoff * cutoff
Cutoff for restart-based search.
int optVar(void) const
Return index of variable used for optimization.
double threads
Number of threads to use.
void sort(TaskViewArray< TaskView > &t)
Sort task view array t according to sto and inc (increasing or decreasing)
SetVarBranch SET_VAR_AFC_MAX(double d, BranchTbl tbl)
int p
Number of positive literals for node type.
IntVarBranch INT_VAR_ACTION_MAX(double d, BranchTbl tbl)
Select variable with highest action with decay factor d.
T * alloc(long unsigned int n)
Allocate block of n objects of type T from heap.
Gecode::FloatVarArray fv
The float variables.
const FloatNum min
Smallest allowed float value.
BoolValBranch BOOL_VAL_MIN(void)
Select smallest value.
IntVarBranch INT_VAR_AFC_SIZE_MAX(double d, BranchTbl tbl)
Select variable with largest accumulated failure count divided by domain size with decay factor d...
Gecode::IntArgs i(4, 1, 2, 3, 4)
IntAssign ann2asnivalsel(AST::Node *ann, Rnd rnd)
Base-class for branchers.
FloatNum n
The middle value for branching.
virtual bool status(const Space &_home) const
Check status of brancher, return true if alternatives left.
BoolValBranch BOOL_VAL_MAX(void)
Select largest value.
int n
Number of negative literals for node type.
BrancherGroup group(void) const
Return group brancher belongs to.
std::vector< bool > fv_introduced
Indicates whether a float variable is introduced by mzn2fzn.
IntPropLevel ann2ipl(AST::Node *ann)
Convert ann to integer propagation level.
Option< std::pair< double, double > > domain
int dfs(Space *root, const Gist::Options &opt)
Create a new stand-alone Gist for root.
IntAssign INT_ASSIGN_RND(Rnd r)
Select random value.
Depth-first branch-and-bound search engine.
void createBranchers(Printer &p, AST::Node *ann, int seed, double decay, bool ignoreUnknown, std::ostream &err=std::cerr)
Create branchers corresponding to the solve item annotations.
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.
Execution has resulted in failure.
Specification for Boolean variables.
Value description class for branching.
double threads(void) const
Node representing an atom
A lock as a scoped frontend for a mutex.
SharedHandle::Object * object(void) const
Access to the shared object.
int _optVar
Index of the variable to optimize.
int getIntVar(void)
Cast this node to an integer variable node.
void finalize(void)
Clean up when Gist exits.
Output support class for FlatZinc interpreter.
IntVarBranch INT_VAR_MIN_MIN(BranchTbl tbl)
Select variable with smallest min.
IntVar arg2IntVar(AST::Node *n)
Convert n to IntVar.
Choice(const Brancher &b, bool fail0)
Initialize choice for brancher b.
FZPrintingInspector(const Printer &p0)
Constructor.
static void installCtrlHandler(bool install, bool force=false)
Install handler for catching Ctrl-C.
static Search::Stop * create(unsigned int node, unsigned int fail, unsigned int time, bool intr)
Create appropriate stop-object.
IntAssign INT_ASSIGN_MAX(void)
Select largest value.
unsigned int operator()(unsigned int n)
Returns a random integer from the interval [0..n)
Simple propagation levels.
int getBoolVar(void)
Cast this node to a Boolean variable node.
The Gecode Interactive Search Tool.
virtual const char * what(void) const
Return information.
virtual void archive(Archive &e) const
Archive into e.
bool isSet(void)
Test if node is a set literal node.
void fail(void)
Fail space.
FznRnd * _random
Random number generator.
unsigned int size(void) const
Return size (cardinality) of set.
BoolVarArgs arg2boolvarargs(AST::Node *arg, int offset=0, int siv=-1)
Convert arg to BoolVarArgs.
IntValBranch INT_VAL_MIN(void)
Select smallest value.
const std::string & floatVarName(int i) const
std::string what(void) const
unsigned int size(I &i)
Size of all ranges of range iterator i.
void newFloatVar(FloatVarSpec *vs)
Create new float variable from specification.
static void explore(S *root, const FlatZincOptions &opt, Gist::Inspector *i, Gist::Comparator *c)
struct Gecode::@579::NNF::@61::@62 b
For binary nodes (and, or, eqv)
virtual ExecStatus commit(Space &, const Gecode::Choice &c, unsigned int)
Perform commit for choice c.
IntValBranch INT_VAL_SPLIT_MAX(void)
Select values greater than mean of smallest and largest value.
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)
bool l
Whether to try the lower or upper half first.
IntVarBranch INT_VAR_RND(Rnd r)
Select random variable (uniform distribution, for tie breaking)
iterator begin(void)
Return an iterator at the beginning of the array.
Iterator for the greatest lower bound ranges of a set variable.
Gecode::BoolVarArray bv_aux
The introduced Boolean variables.
bool clone
Whether engines create a clone when being initialized.
void print(std::ostream &out, const Gecode::IntVarArray &iv, const Gecode::BoolVarArray &bv, const Gecode::SetVarArray &sv, const Gecode::FloatVarArray &fv) const
FznRnd(unsigned int s=1)
Constructor.
Array * getArgs(unsigned int n)
BoolAssign BOOL_ASSIGN_RND(Rnd r)
Select random value.
FloatValBranch FLOAT_VAL_SPLIT_MIN(void)
Select values not greater than mean of smallest and largest value.
void addSetVarName(const std::string &n)
bool funcDep
Whether the variable functionally depends on another variable.
SetVarBranch SET_VAR_AFC_MIN(double d, BranchTbl tbl)
IntVarBranch INT_VAR_AFC_MAX(double d, BranchTbl tbl)
Select variable with largest accumulated failure count with decay factor d.
FloatVarBranch FLOAT_VAR_AFC_MIN(double d, BranchTbl tbl)
Select variable with smallest accumulated failure count with decay factor d.
virtual void compare(const Space &s0, const Space &s1)=0
Call-back function.
Choice that only signals failure or success
SetVarBranch SET_VAR_RND(Rnd r)
unsigned int node(void) const
Option< AST::SetLit *> domain
FlatZincSpace(bool share, FlatZincSpace &)
Copy constructor.
TieBreak< BoolVarBranch > ann2bvarsel(AST::Node *ann, Rnd rnd, double decay)
IntVarArgs arg2intvarargs(AST::Node *arg, int offset=0)
Convert arg to IntVarArgs.
virtual void constrain(const Space &s)
Implement optimization.
bool isIntVar(void)
Test if node is an integer variable node.
const std::string & intVarName(int i) const
FloatVarBranch FLOAT_VAR_RND(Rnd r)
Select random variable (uniform distribution, for tie breaking)
Passing integer variables.
bool isBoolArray(AST::Node *b, int &singleInt)
Check if b is array of Booleans (or has a single integer)
std::vector< bool > bv_introduced
Indicates whether a Boolean variable is introduced by mzn2fzn.
SetValBranch SET_VAL_MIN_EXC(void)
SharedArray< int > IntSharedArray
Arrays of integers that can be shared among several element constraints.
bool done
Flag whether brancher is done.
Passing integer arguments.
Passing Boolean variables.
SetValBranch SET_VAL_MIN_INC(void)
static const IntSet empty
Empty set.
FloatValBranch float_valsel
bool isInt(int &i)
Test if node is int, if yes set i to the value.
bool _optVarIsInt
Whether variable to optimize is integer (or float)
FloatVarBranch FLOAT_VAR_SIZE_MIN(BranchTbl tbl)
Select variable with smallest domain size.
IntSet arg2intset(AST::Node *n)
Convert n to IntSet.
Gecode::FloatVarArray fv_aux
The introduced float variables.
Boolean integer variables.
bool isString(void)
Test if node is a string node.
SetValBranch SET_VAL_MAX_EXC(void)
virtual bool slave(const MetaInfo &mi)
Slave function for restarts.
void init(void)
Initialize the implementation object.
void min(Home home, FloatVar x0, FloatVar x1, FloatVar x2)
Post propagator for .
bool assigned
Whether the variable is assigned.
void update(Space &home, bool share, SharedHandle &sh)
Updating during cloning.
IntValBranch INT_VAL_MAX(void)
Select largest value.
SetValBranch SET_VAL_MAX_INC(void)
IntPropLevel
Propagation levels for integer propagators.
Cutoff generator for constant sequence.
AST::Array * args
Constraint arguments.
int getInt(void)
Cast this node to an integer node.
void print(std::basic_ostream< Char, Traits > &s, bool assigned, IL &lb, IU &ub, unsigned int cardMin, unsigned int cardMax)
Print set view.
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
IntVarBranch INT_VAR_SIZE_MIN(BranchTbl tbl)
Select variable with smallest domain size.
Post propagator for f(x \diamond_{\mathit{op}} y) \sim_r z \f$ void rel(Home home
SetVarBranch SET_VAR_SIZE_MAX(BranchTbl tbl)
void postConstraints(std::vector< ConExpr *> &ces)
Post a constraint specified by ce.
BoolVarBranch BOOL_VAR_AFC_MAX(double d, BranchTbl tbl)
Select variable with largest accumulated failure count with decay factor d.
Exception: Base-class for exceptions
Print statistics for script.
Base class for variables.
IntValBranch INT_VALUES_MIN(void)
Try all values starting from smallest.
void free(T *b, long unsigned int n)
Delete n objects starting at b.
virtual void print(std::ostream &)=0
Output string representation.
Exception signaling type error
BoolVarBranch BOOL_VAR_DEGREE_MAX(BranchTbl tbl)
Select variable with largest degree.
Home operator()(Propagator &p)
Return a home for this space with the information that p is being rewritten.
void print(std::ostream &out, const Printer &p) const
Produce output on out using p.
virtual void archive(Archive &e) const
Archive into e.
Choice for performing commit
unsigned int fail(void) const
bool hasAtom(const std::string &id)
Test if node has atom with id.
bool isFloatVar(void)
Test if node is a float variable node.
void flattenAnnotations(AST::Array *ann, std::vector< AST::Node *> &out)
SetVarBranch SET_VAR_AFC_SIZE_MIN(double d, BranchTbl tbl)
FloatVarBranch FLOAT_VAR_AFC_MAX(double d, BranchTbl tbl)
Select variable with largest accumulated failure count with decay factor d.
Heap heap
The single global heap.
Iterator for the values in the greatest lower bound of a set variable.
IntVarBranch INT_VAR_ACTION_MIN(double d, BranchTbl tbl)
Select variable with lowest action with decay factor d.
BoolVarBranch BOOL_VAR_ACTION_MAX(double d, BranchTbl tbl)
Select variable with highest action with decay factor d.
IntVarBranch INT_VAR_AFC_SIZE_MIN(double d, BranchTbl tbl)
Select variable with smallest accumulated failure count divided by domain size with decay factor d...
Which values to select for assignment.
void rel(Home home, FloatVar x0, FloatRelType frt, FloatVal n)
Propagates .
Exception class for FlatZinc errors
Specification for floating point variables.
FloatVarBranch FLOAT_VAR_ACTION_MIN(double d, BranchTbl tbl)
Select variable with lowest action with decay factor d.
Domain propagation Preferences: prefer speed or memory.
TieBreak< FloatVarBranch > ann2fvarsel(AST::Node *ann, Rnd rnd, double decay)
struct Gecode::Space::@56::@58 c
Data available only during copying.
int bab(Space *root, const Gist::Options &opt)
Create a new stand-alone Gist for branch-and-bound search of root.
AST::Array * _solveAnnotations
Annotations on the solve item.
virtual void inspect(const Space &node)
Use the print method of the template class S to print a space.
unsigned int c_d(void) const
IntValBranch INT_VAL_MED(void)
Select greatest value not greater than the median.
IntVarBranch INT_VAR_ACTION_SIZE_MIN(double d, BranchTbl tbl)
Select variable with smallest action divided by domain size with decay factor d.
~FlatZincSpace(void)
Destructor.
An window for simple text output.
bool needAuxVars
Whether the introduced variables still need to be copied.
void solve(AST::Array *annotation)
Post the solve item.
unsigned int time(void) const
Post propagator for SetVar x
unsigned long int restart
Number of restarts.
AST::Array * solveAnnotations(void) const
Return the solve item annotations.
#define GECODE_HAS_FLOAT_VARS
BoolVarBranch BOOL_VAR_RND(Rnd r)
Select random variable (uniform distribution, for tie breaking)
TieBreak< FloatVarBranch > float_varsel
bool isArray(void)
Test if node is an array node.
bool interrupt(void) const
virtual Actor * copy(Space &home, bool share)
Copy brancher.
void aliasBool2Int(int iv, int bv)
Link integer variable iv to Boolean variable bv.
FloatVarBranch FLOAT_VAR_MIN_MIN(BranchTbl tbl)
Select variable with smallest min.
A space that can be initialized with a FlatZinc model.
Gecode::IntVarArray iv_aux
The introduced integer variables.
void addBoolVarName(const std::string &n)
void shrinkArrays(Space &home, int &optVar, bool optVarIsInt, Gecode::IntVarArray &iv, Gecode::BoolVarArray &bv, Gecode::SetVarArray &sv, Gecode::FloatVarArray &fv)
TieBreak< BoolVarBranch > bool_varsel
CompareStatus compare(I &i, J &j)
Check whether range iterator i is a subset of j, or whether they are disjoint.
Stop * stop
Stop object for stopping search.
class Gecode::Gist::Options::_I inspect
const std::string & setVarName(int i) const
IntValBranch INT_VAL_SPLIT_MIN(void)
Select values not greater than mean of smallest and largest value.
int explore(Space *root, bool bab, const Options &opt)
Create a new stand-alone Gist for root using bab.
void run(std::ostream &out, const Printer &p, const FlatZincOptions &opt, Gecode::Support::Timer &t_total)
Run the search.
Gecode toplevel namespace
void addIntVarName(const std::string &n)
int * iv_boolalias
Indicates whether an integer variable aliases a Boolean variable.
unsigned long int node
Number of nodes expanded.
void maximize(int var, bool isInt, AST::Array *annotation)
Post that integer variable var should be maximized.
int setVarCount
Number of set variables.
Node representing a function call
int intVarCount
Number of integer variables.
unsigned int a_d(void) const
FZPrintingComparator(const Printer &p0)
Constructor.
IntValBranch ann2ivalsel(AST::Node *ann, std::string &r0, std::string &r1, Rnd rnd)
SetVarArgs arg2setvarargs(AST::Node *arg, int offset=0, int doffset=0, const IntSet &od=IntSet::empty)
Convert n to SetVarArgs.
A node in a FlatZinc abstract syntax tree.
SetVarBranch SET_VAR_ACTION_MAX(double d, BranchTbl tbl)
SetVarBranch SET_VAR_MIN_MIN(BranchTbl tbl)
IntArgs arg2boolargs(AST::Node *arg, int offset=0)
Convert arg (array of Booleans) to IntArgs.
FloatVarBranch FLOAT_VAR_ACTION_SIZE_MAX(double d, BranchTbl tbl)
Select variable with largest action divided by domain size with decay factor d.
Which variable to select for branching.
FloatVarBranch FLOAT_VAR_AFC_SIZE_MAX(double d, BranchTbl tbl)
Select variable with largest accumulated failure count divided by domain size with decay factor d...
SetVarBranch SET_VAR_AFC_SIZE_MAX(double d, BranchTbl tbl)
void addFloatVarName(const std::string &n)
unsigned int _lns
Percentage of variables to keep in LNS (or 0 for no LNS)
friend FloatVal max(const FloatVal &x, const FloatVal &y)
iterator end(void)
Return an iterator past the end of the array.
void assign(Home home, const FloatVarArgs &x, FloatAssign fa, FloatBranchFilter bf, FloatVarValPrint vvp)
Assign all x with value selection vals.
FloatVarBranch FLOAT_VAR_MAX_MAX(BranchTbl tbl)
Select variable with largest max.
void varValPrintF(const Space &home, const Brancher &b, unsigned int a, FloatVar, int i, const FloatNumBranch &nl, std::ostream &o)
friend FloatVal min(const FloatVal &x, const FloatVal &y)
Gecode::SetVarArray sv
The set variables.
Home class for posting propagators
FloatVarBranch FLOAT_VAR_ACTION_MAX(double d, BranchTbl tbl)
Select variable with highest action with decay factor d.
double FloatNum
Floating point number base type.
Specification for integer variables.
void compare(Comparator *c)
Add comparator.
SetVarBranch SET_VAR_ACTION_SIZE_MAX(double d, BranchTbl tbl)
const std::string & boolVarName(int i) const
BoolValBranch bool_valsel
bool introduced
Whether the variable was introduced in the mzn2fzn translation.
virtual void finalize(void)
Finalize when Gist exits.
std::string getString(void)
Cast this node to a string node.
Gecode::IntVarArray iv_lns
The integer variables used in LNS.
FloatVar arg2FloatVar(AST::Node *n)
Convert n to FloatVar.
Depth-first search engine.
Branching on the introduced variables.
const Val & some(void) const
SetVarBranch SET_VAR_ACTION_SIZE_MIN(double d, BranchTbl tbl)
IntSharedArray _lnsInitialSolution
Initial solution to start the LNS (or NULL for no LNS)
Registry & registry(void)
Return global registry object.
FloatValArgs arg2floatargs(AST::Node *arg, int offset=0)
Convert n to FloatValArgs.
IntVarBranch INT_VAR_ACTION_SIZE_MAX(double d, BranchTbl tbl)
Select variable with largest action divided by domain size with decay factor d.
Option< AST::SetLit * > upperBound
virtual size_t dispose(Space &)
Delete brancher and return its size.
bool fail
Whether brancher should fail.
TieBreak< IntVarBranch > int_varsel
void init(AST::Array *output)
BoolVar arg2BoolVar(AST::Node *n)
Convert n to BoolVar.
IntSetArgs arg2intsetargs(AST::Node *arg, int offset=0)
Convert arg to IntSetArgs.
SetVarBranch SET_VAR_ACTION_MIN(double d, BranchTbl tbl)
Abstract representation of a constraint.