53 #include <unordered_set> 59 template<>
struct hash<
Gecode::TupleSet> {
68 template<>
struct hash<
Gecode::SharedArray<int> > {
72 size_t seed =
static_cast<size_t>(x.
size());
73 for (
int i=x.
size();
i--; )
80 template<>
struct hash<
Gecode::DFA> {
89 namespace Gecode {
namespace FlatZinc {
127 int_varsel(int_varsel0), int_valsel(int_valsel0),
128 bool_varsel(bool_varsel0), bool_valsel(bool_valsel0)
129 #ifdef GECODE_HAS_SET_VARS
130 , set_varsel(set_varsel0), set_valsel(set_valsel0)
132 #ifdef GECODE_HAS_FLOAT_VARS
133 , float_varsel(float_varsel0), float_valsel(float_valsel0)
138 :
Brancher(home, b), done(b.done) {}
149 virtual size_t size(
void)
const {
163 #ifdef GECODE_HAS_SET_VARS 167 #ifdef GECODE_HAS_FLOAT_VARS 175 if (done)
return false;
181 #ifdef GECODE_HAS_SET_VARS 185 #ifdef GECODE_HAS_FLOAT_VARS 199 #ifdef GECODE_HAS_SET_VARS 202 #ifdef GECODE_HAS_FLOAT_VARS 209 return new Choice(*
this,
false);
211 return new Choice(*
this,
true);
216 bool fail; e >> fail;
217 return new Choice(*
this, fail);
226 std::ostream& o)
const {
228 << (
static_cast<const Choice&
>(
c).fail ?
"fail" :
"ok")
253 bool_varsel, bool_valsel
254 #ifdef GECODE_HAS_SET_VARS
255 , set_varsel, set_valsel
257 #ifdef GECODE_HAS_FLOAT_VARS
258 , float_varsel, float_valsel
264 return sizeof(*this);
273 std::vector<std::string>
n;
274 BI(
void) : r0(
""), r1(
""),
n(0) {}
275 BI(
const std::string& r00,
const std::string& r10,
276 const std::vector<std::string>& n0)
277 : r0(r00), r1(r10),
n(n0) {}
289 const std::string& rel0,
290 const std::string& rel1,
291 const std::vector<std::string>&
n) {
292 v.resize(
std::max(static_cast<unsigned int>(v.size()),bg.
id()+1));
293 v[bg.
id()] = BI(rel0,rel1,n);
297 unsigned int a,
int i,
int n, std::ostream& o)
const {
299 o << bi.n[
i] <<
" " << (a==0 ? bi.r0 : bi.r1) <<
" " << n;
301 #ifdef GECODE_HAS_FLOAT_VARS 304 std::ostream& o)
const {
307 << (((a == 0) == nl.
l) ?
"<=" :
">=") << nl.
n;
312 BranchInformation::BranchInformation(
void)
320 assert(
object() == NULL);
326 const std::string& rel0,
327 const std::string& rel1,
328 const std::vector<std::string>&
n) {
333 int n, std::ostream& o)
const {
336 #ifdef GECODE_HAS_FLOAT_VARS 346 Var,
int i,
const int&
n,
351 #ifdef GECODE_HAS_FLOAT_VARS 369 int* newdom =
heap.
alloc<
int>(
static_cast<unsigned long int>(sl->
s.size()));
370 for (
int i=sl->
s.size();
i--;)
371 newdom[
i] = sl->
s[
i];
372 IntSet ret(newdom, sl->
s.size());
373 heap.
free(newdom, static_cast<unsigned long int>(sl->
s.size()));
405 if (
AST::Atom* s = dynamic_cast<AST::Atom*>(ann)) {
406 if (s->id ==
"input_order")
408 if (s->id ==
"first_fail")
410 if (s->id ==
"anti_first_fail")
412 if (s->id ==
"smallest")
414 if (s->id ==
"largest")
416 if (s->id ==
"occurrence")
418 if (s->id ==
"max_regret")
420 if (s->id ==
"most_constrained")
423 if (s->id ==
"random") {
426 if (s->id ==
"dom_w_deg") {
429 if (s->id ==
"afc_min")
431 if (s->id ==
"afc_max")
433 if (s->id ==
"afc_size_min")
435 if (s->id ==
"afc_size_max") {
438 if (s->id ==
"action_min")
440 if (s->id ==
"action_max")
442 if (s->id ==
"action_size_min")
444 if (s->id ==
"action_size_max")
447 std::cerr <<
"Warning, ignored search annotation: ";
448 ann->
print(std::cerr);
449 std::cerr << std::endl;
455 if (
AST::Atom* s = dynamic_cast<AST::Atom*>(ann)) {
456 if (s->id ==
"indomain_min") {
460 if (s->id ==
"indomain_max") {
464 if (s->id ==
"indomain_median") {
468 if (s->id ==
"indomain_split") {
472 if (s->id ==
"indomain_reverse_split") {
476 if (s->id ==
"indomain_random") {
480 if (s->id ==
"indomain") {
484 if (s->id ==
"indomain_middle") {
485 std::cerr <<
"Warning, replacing unsupported annotation " 486 <<
"indomain_middle with indomain_median" << std::endl;
490 if (s->id ==
"indomain_interval") {
491 std::cerr <<
"Warning, replacing unsupported annotation " 492 <<
"indomain_interval with indomain_split" << std::endl;
497 std::cerr <<
"Warning, ignored search annotation: ";
498 ann->
print(std::cerr);
499 std::cerr << std::endl;
505 if (
AST::Atom* s = dynamic_cast<AST::Atom*>(ann)) {
506 if (s->id ==
"indomain_min")
508 if (s->id ==
"indomain_max")
510 if (s->id ==
"indomain_median")
512 if (s->id ==
"indomain_random") {
516 std::cerr <<
"Warning, ignored search annotation: ";
517 ann->
print(std::cerr);
518 std::cerr << std::endl;
523 if (
AST::Atom* s = dynamic_cast<AST::Atom*>(ann)) {
524 if ((s->id ==
"input_order") ||
525 (s->id ==
"first_fail") ||
526 (s->id ==
"anti_first_fail") ||
527 (s->id ==
"smallest") ||
528 (s->id ==
"largest") ||
529 (s->id ==
"max_regret"))
531 if ((s->id ==
"occurrence") ||
532 (s->id ==
"most_constrained"))
534 if (s->id ==
"random")
536 if ((s->id ==
"afc_min") ||
537 (s->id ==
"afc_size_min"))
539 if ((s->id ==
"afc_max") ||
540 (s->id ==
"afc_size_max") ||
541 (s->id ==
"dom_w_deg"))
543 if ((s->id ==
"action_min") &&
544 (s->id ==
"action_size_min"))
546 if ((s->id ==
"action_max") ||
547 (s->id ==
"action_size_max"))
550 std::cerr <<
"Warning, ignored search annotation: ";
551 ann->
print(std::cerr);
552 std::cerr << std::endl;
558 if (
AST::Atom* s = dynamic_cast<AST::Atom*>(ann)) {
559 if (s->id ==
"indomain_min") {
563 if (s->id ==
"indomain_max") {
567 if (s->id ==
"indomain_median") {
571 if (s->id ==
"indomain_split") {
575 if (s->id ==
"indomain_reverse_split") {
579 if (s->id ==
"indomain_random") {
583 if (s->id ==
"indomain") {
587 if (s->id ==
"indomain_middle") {
588 std::cerr <<
"Warning, replacing unsupported annotation " 589 <<
"indomain_middle with indomain_median" << std::endl;
593 if (s->id ==
"indomain_interval") {
594 std::cerr <<
"Warning, replacing unsupported annotation " 595 <<
"indomain_interval with indomain_split" << std::endl;
600 std::cerr <<
"Warning, ignored search annotation: ";
601 ann->
print(std::cerr);
602 std::cerr << std::endl;
608 if (
AST::Atom* s = dynamic_cast<AST::Atom*>(ann)) {
609 if ((s->id ==
"indomain_min") ||
610 (s->id ==
"indomain_median"))
612 if (s->id ==
"indomain_max")
614 if (s->id ==
"indomain_random") {
618 std::cerr <<
"Warning, ignored search annotation: ";
619 ann->
print(std::cerr);
620 std::cerr << std::endl;
624 #ifdef GECODE_HAS_SET_VARS 626 if (
AST::Atom* s = dynamic_cast<AST::Atom*>(ann)) {
627 if (s->id ==
"input_order")
629 if (s->id ==
"first_fail")
631 if (s->id ==
"anti_first_fail")
633 if (s->id ==
"smallest")
635 if (s->id ==
"largest")
637 if (s->id ==
"afc_min")
639 if (s->id ==
"afc_max")
641 if (s->id ==
"afc_size_min")
643 if (s->id ==
"afc_size_max")
645 if (s->id ==
"action_min")
647 if (s->id ==
"action_max")
649 if (s->id ==
"action_size_min")
651 if (s->id ==
"action_size_max")
653 if (s->id ==
"random") {
657 std::cerr <<
"Warning, ignored search annotation: ";
658 ann->
print(std::cerr);
659 std::cerr << std::endl;
666 if (
AST::Atom* s = dynamic_cast<AST::Atom*>(ann)) {
667 if (s->id ==
"indomain_min") {
668 r0 =
"in"; r1 =
"not in";
671 if (s->id ==
"indomain_max") {
672 r0 =
"in"; r1 =
"not in";
675 if (s->id ==
"outdomain_min") {
676 r1 =
"in"; r0 =
"not in";
679 if (s->id ==
"outdomain_max") {
680 r1 =
"in"; r0 =
"not in";
684 std::cerr <<
"Warning, ignored search annotation: ";
685 ann->
print(std::cerr);
686 std::cerr << std::endl;
687 r0 =
"in"; r1 =
"not in";
692 #ifdef GECODE_HAS_FLOAT_VARS 695 if (
AST::Atom* s = dynamic_cast<AST::Atom*>(ann)) {
696 if (s->id ==
"input_order")
698 if (s->id ==
"first_fail")
700 if (s->id ==
"anti_first_fail")
702 if (s->id ==
"smallest")
704 if (s->id ==
"largest")
706 if (s->id ==
"occurrence")
708 if (s->id ==
"most_constrained")
711 if (s->id ==
"random") {
714 if (s->id ==
"afc_min")
716 if (s->id ==
"afc_max")
718 if (s->id ==
"afc_size_min")
720 if (s->id ==
"afc_size_max")
722 if (s->id ==
"action_min")
724 if (s->id ==
"action_max")
726 if (s->id ==
"action_size_min")
728 if (s->id ==
"action_size_max")
731 std::cerr <<
"Warning, ignored search annotation: ";
732 ann->
print(std::cerr);
733 std::cerr << std::endl;
738 if (
AST::Atom* s = dynamic_cast<AST::Atom*>(ann)) {
739 if (s->id ==
"indomain_split") {
743 if (s->id ==
"indomain_reverse_split") {
748 std::cerr <<
"Warning, ignored search annotation: ";
749 ann->
print(std::cerr);
750 std::cerr << std::endl;
780 _initData(NULL), _random(f._random),
781 _solveAnnotations(NULL), iv_boolalias(NULL),
785 needAuxVars(f.needAuxVars) {
820 #ifdef GECODE_HAS_SET_VARS 834 #ifdef GECODE_HAS_FLOAT_VARS 861 int setVars,
int floatVars) {
872 #ifdef GECODE_HAS_SET_VARS 877 #ifdef GECODE_HAS_FLOAT_VARS 922 #ifdef GECODE_HAS_SET_VARS 934 int* is =
heap.
alloc<
int>(
static_cast<unsigned long int>(vsv->s.size()));
935 for (
int i=vsv->s.
size();
i--; )
938 heap.
free(is,static_cast<unsigned long int>(vsv->s.size()));
947 int* is =
heap.
alloc<
int>(
static_cast<unsigned long int>(vsv->
s.size()));
948 for (
int i=vsv->
s.size();
i--; )
951 heap.
free(is,static_cast<unsigned long int>(vsv->
s.size()));
969 #ifdef GECODE_HAS_FLOAT_VARS 1000 struct ConExprOrder {
1002 return ce0->
args->
a.size() < ce1->
args->
a.size();
1012 for (
unsigned int i=0;
i<ces.
size();
i++) {
1027 for (
unsigned int i=0;
i<ann->
a.size();
i++) {
1028 if (ann->
a[
i]->isCall(
"seq_search")) {
1033 out.push_back(c->
args);
1035 out.push_back(ann->
a[
i]);
1044 std::ostream& err) {
1045 Rnd rnd(static_cast<unsigned int>(seed));
1049 std::string def_int_rel_left =
"=";
1050 std::string def_int_rel_right =
"!=";
1053 std::string def_bool_rel_left =
"=";
1054 std::string def_bool_rel_right =
"!=";
1055 #ifdef GECODE_HAS_SET_VARS 1058 std::string def_set_rel_left =
"in";
1059 std::string def_set_rel_right =
"not in";
1061 #ifdef GECODE_HAS_FLOAT_VARS 1064 std::string def_float_rel_left =
"<=";
1065 std::string def_float_rel_right =
">";
1068 std::vector<bool> iv_searched(
iv.
size());
1069 for (
unsigned int i=
iv.
size();
i--;)
1070 iv_searched[
i] =
false;
1071 std::vector<bool> bv_searched(
bv.
size());
1072 for (
unsigned int i=
bv.
size();
i--;)
1073 bv_searched[
i] =
false;
1074 #ifdef GECODE_HAS_SET_VARS 1075 std::vector<bool> sv_searched(
sv.
size());
1076 for (
unsigned int i=
sv.
size();
i--;)
1077 sv_searched[
i] =
false;
1079 #ifdef GECODE_HAS_FLOAT_VARS 1080 std::vector<bool> fv_searched(
fv.
size());
1081 for (
unsigned int i=
fv.
size();
i--;)
1082 fv_searched[
i] =
false;
1087 std::vector<AST::Node*> flatAnn;
1091 flatAnn.push_back(ann);
1094 for (
unsigned int i=0;
i<flatAnn.
size();
i++) {
1095 if (flatAnn[
i]->isCall(
"relax_and_reconstruct")) {
1098 "Only one relax_and_reconstruct annotation allowed");
1106 _lns = args->
a[1]->getInt();
1108 int k=vars->
a.size();
1109 for (
int i=vars->
a.size();
i--;)
1110 if (vars->
a[
i]->isInt())
1114 for (
unsigned int i=0;
i<vars->
a.size();
i++) {
1115 if (vars->
a[
i]->isInt())
1119 if (args->
a.size()==3) {
1122 for (
unsigned int i=initial->
a.size();
i--;)
1125 }
else if (flatAnn[
i]->isCall(
"gecode_search")) {
1127 branchWithPlugin(c->
args);
1128 }
else if (flatAnn[
i]->isCall(
"int_search")) {
1132 int k=vars->
a.size();
1133 for (
int i=vars->
a.size();
i--;)
1134 if (vars->
a[
i]->isInt())
1137 std::vector<std::string> names;
1139 for (
unsigned int i=0;
i<vars->
a.size();
i++) {
1140 if (vars->
a[
i]->isInt())
1142 va[k++] =
iv[vars->
a[
i]->getIntVar()];
1143 iv_searched[vars->
a[
i]->getIntVar()] =
true;
1144 names.push_back(vars->
a[
i]->getVarName());
1153 &varValPrint<IntVar>);
1156 }
else if (flatAnn[
i]->isCall(
"int_assign")) {
1160 int k=vars->
a.size();
1161 for (
int i=vars->
a.size();
i--;)
1162 if (vars->
a[
i]->isInt())
1166 for (
unsigned int i=0;
i<vars->
a.size();
i++) {
1167 if (vars->
a[
i]->isInt())
1169 va[k++] =
iv[vars->
a[
i]->getIntVar()];
1170 iv_searched[vars->
a[
i]->getIntVar()] =
true;
1173 &varValPrint<IntVar>);
1174 }
else if (flatAnn[
i]->isCall(
"bool_search")) {
1178 int k=vars->
a.size();
1179 for (
int i=vars->
a.size();
i--;)
1180 if (vars->
a[
i]->isBool())
1184 std::vector<std::string> names;
1185 for (
unsigned int i=0;
i<vars->
a.size();
i++) {
1186 if (vars->
a[
i]->isBool())
1188 va[k++] =
bv[vars->
a[
i]->getBoolVar()];
1189 bv_searched[vars->
a[
i]->getBoolVar()] =
true;
1190 names.push_back(vars->
a[
i]->getVarName());
1200 &varValPrint<BoolVar>);
1203 }
else if (flatAnn[
i]->isCall(
"int_default_search")) {
1208 def_int_rel_left,def_int_rel_right,rnd);
1209 }
else if (flatAnn[
i]->isCall(
"bool_default_search")) {
1214 def_bool_rel_left,def_bool_rel_right,
1216 }
else if (flatAnn[
i]->isCall(
"set_search")) {
1217 #ifdef GECODE_HAS_SET_VARS 1221 int k=vars->
a.size();
1222 for (
int i=vars->
a.size();
i--;)
1223 if (vars->
a[
i]->isSet())
1227 std::vector<std::string> names;
1228 for (
unsigned int i=0;
i<vars->
a.size();
i++) {
1229 if (vars->
a[
i]->isSet())
1231 va[k++] =
sv[vars->
a[
i]->getSetVar()];
1232 sv_searched[vars->
a[
i]->getSetVar()] =
true;
1233 names.push_back(vars->
a[
i]->getVarName());
1242 &varValPrint<SetVar>);
1246 if (!ignoreUnknown) {
1247 err <<
"Warning, ignored search annotation: ";
1248 flatAnn[
i]->print(err);
1252 }
else if (flatAnn[
i]->isCall(
"set_default_search")) {
1253 #ifdef GECODE_HAS_SET_VARS 1258 def_set_rel_left,def_set_rel_right,rnd);
1260 if (!ignoreUnknown) {
1261 err <<
"Warning, ignored search annotation: ";
1262 flatAnn[
i]->print(err);
1266 }
else if (flatAnn[
i]->isCall(
"float_default_search")) {
1267 #ifdef GECODE_HAS_FLOAT_VARS 1272 def_float_rel_left,def_float_rel_right);
1274 if (!ignoreUnknown) {
1275 err <<
"Warning, ignored search annotation: ";
1276 flatAnn[
i]->print(err);
1280 }
else if (flatAnn[
i]->isCall(
"float_search")) {
1281 #ifdef GECODE_HAS_FLOAT_VARS 1285 int k=vars->
a.size();
1286 for (
int i=vars->
a.size();
i--;)
1287 if (vars->
a[
i]->isFloat())
1291 std::vector<std::string> names;
1292 for (
unsigned int i=0;
i<vars->
a.size();
i++) {
1293 if (vars->
a[
i]->isFloat())
1295 va[k++] =
fv[vars->
a[
i]->getFloatVar()];
1296 fv_searched[vars->
a[
i]->getFloatVar()] =
true;
1297 names.push_back(vars->
a[
i]->getVarName());
1310 if (!ignoreUnknown) {
1311 err <<
"Warning, ignored search annotation: ";
1312 flatAnn[
i]->print(err);
1317 if (!ignoreUnknown) {
1318 err <<
"Warning, ignored search annotation: ";
1319 flatAnn[
i]->print(err);
1339 std::vector<std::string> iv_sol_names(
iv.
size()-(introduced+funcdep+searched));
1341 std::vector<std::string> iv_tmp_names(introduced);
1343 for (
int i=
iv.
size(), j=0, k=0;
i--;) {
1349 iv_tmp[j++] =
iv[
i];
1353 iv_sol[k++] =
iv[
i];
1361 if (bv_searched[
i]) {
1371 std::vector<std::string> bv_sol_names(
bv.
size()-(introduced+funcdep+searched));
1374 std::vector<std::string> bv_tmp_names(introduced);
1375 for (
int i=
bv.
size(), j=0, k=0;
i--;) {
1381 bv_tmp[j++] =
bv[
i];
1385 bv_sol[k++] =
bv[
i];
1389 if (iv_sol.
size() > 0 && bv_sol.
size() > 0) {
1390 branch(*
this, iv_sol, bv_sol, def_intbool_varsel, def_int_valsel);
1391 }
else if (iv_sol.
size() > 0) {
1393 branch(bg(*
this), iv_sol, def_int_varsel, def_int_valsel,
nullptr,
1394 &varValPrint<IntVar>);
1395 branchInfo.
add(bg,def_int_rel_left,def_int_rel_right,iv_sol_names);
1396 }
else if (bv_sol.
size() > 0) {
1398 branch(bg(*
this), bv_sol, def_bool_varsel, def_bool_valsel,
nullptr,
1399 &varValPrint<BoolVar>);
1400 branchInfo.
add(bg,def_bool_rel_left,def_bool_rel_right,bv_sol_names);
1402 #ifdef GECODE_HAS_FLOAT_VARS 1417 std::vector<std::string> fv_sol_names(
fv.
size()-(introduced+funcdep+searched));
1420 std::vector<std::string> fv_tmp_names(introduced);
1421 for (
int i=
fv.
size(), j=0, k=0;
i--;) {
1427 fv_tmp[j++] =
fv[
i];
1431 fv_sol[k++] =
fv[
i];
1435 if (fv_sol.
size() > 0) {
1437 branch(bg(*
this), fv_sol, def_float_varsel, def_float_valsel,
nullptr,
1439 branchInfo.
add(bg,def_float_rel_left,def_float_rel_right,fv_sol_names);
1442 #ifdef GECODE_HAS_SET_VARS 1447 if (sv_searched[
i]) {
1457 std::vector<std::string> sv_sol_names(
sv.
size()-(introduced+funcdep+searched));
1460 std::vector<std::string> sv_tmp_names(introduced);
1461 for (
int i=
sv.
size(), j=0, k=0;
i--;) {
1467 sv_tmp[j++] =
sv[
i];
1471 sv_sol[k++] =
sv[
i];
1475 if (sv_sol.
size() > 0) {
1477 branch(bg(*
this), sv_sol, def_set_varsel, def_set_valsel,
nullptr,
1478 &varValPrint<SetVar>);
1479 branchInfo.
add(bg,def_set_rel_left,def_set_rel_right,sv_sol_names);
1486 #ifdef GECODE_HAS_SET_VARS 1490 #ifdef GECODE_HAS_FLOAT_VARS 1498 def_bool_varsel, def_bool_valsel
1500 , def_set_varsel, def_set_valsel
1503 , def_float_varsel, def_float_valsel
1509 branch(bg(*
this),
iv_aux,def_int_varsel,def_int_valsel,
nullptr,
1510 &varValPrint<IntVar>);
1511 branchInfo.
add(bg,def_int_rel_left,def_int_rel_right,iv_tmp_names);
1515 branch(bg(*
this),
bv_aux,def_bool_varsel,def_bool_valsel,
nullptr,
1516 &varValPrint<BoolVar>);
1517 branchInfo.
add(bg,def_bool_rel_left,def_bool_rel_right,bv_tmp_names);
1519 #ifdef GECODE_HAS_SET_VARS 1522 branch(bg(*
this),
sv_aux,def_set_varsel,def_set_valsel,
nullptr,
1523 &varValPrint<SetVar>);
1524 branchInfo.
add(bg,def_set_rel_left,def_set_rel_right,sv_tmp_names);
1527 #ifdef GECODE_HAS_FLOAT_VARS 1530 branch(bg(*
this),
fv_aux,def_float_varsel,def_float_valsel,
nullptr,
1532 branchInfo.
add(bg,def_float_rel_left,def_float_rel_right,fv_tmp_names);
1541 std::vector<std::string> names(1);
1545 &varValPrint<IntVar>);
1548 #ifdef GECODE_HAS_FLOAT_VARS 1549 std::vector<std::string> names(1);
1559 std::vector<std::string> names(1);
1563 &varValPrint<IntVar>);
1566 #ifdef GECODE_HAS_FLOAT_VARS 1567 std::vector<std::string> names(1);
1611 #ifdef GECODE_HAS_GIST 1616 template<
class Engine>
1621 template<
typename S>
1635 template<
typename S>
1658 virtual void inspect(
const Space& node);
1660 virtual void finalize(
void);
1665 : TextOutput(
"Gecode/FlatZinc"),
p(p0) {}
1696 :
Gecode::Gist::VarComparator<S>(
"Gecode/FlatZinc"),
p(p0) {}
1703 dynamic_cast<const S&
>(s0).
compare(dynamic_cast<const S&>(s1),
1713 template<
template<
class>
class Engine>
1715 FlatZincSpace::runEngine(std::ostream& out,
const Printer& p,
1718 runMeta<Engine,Driver::EngineToMeta>(out,p,
opt,t_total);
1720 runMeta<Engine,RBS>(out,p,
opt,t_total);
1724 #ifdef GECODE_HAS_CPPROFILER 1732 std::stringstream ss;
1733 if (
const FlatZincSpace* fz_space = dynamic_cast<const FlatZincSpace*>(&space)) {
1734 ss <<
"{domains = \"";
1735 ss << fz_space->getDomains(p);
1746 os <<
"int: " << name <<
" = " << x.
val() <<
";";
1747 }
else if (x.
range()) {
1748 os << x.
min() <<
".." << x.
max() <<
": " << name <<
";";
1750 os <<
"array_union([";
1753 os << r.
min() <<
".." << r.
max();
1758 os <<
"]): " << name <<
";";
1763 os <<
"var bool: " <<
name;
1765 os <<
" = " << (b.
val() ?
"true" :
"false");
1768 #ifdef GECODE_HAS_FLOAT_VARS 1772 os <<
"float: " << name <<
" = " << f.
med() <<
";";
1774 os << f.
min() <<
".." << f.
max() <<
": " << name <<
";";
1779 std::ostringstream oss;
1781 for (
int i = 0;
i < iv.
size();
i++)
1784 for (
int i = 0;
i < bv.
size();
i++)
1787 #ifdef GECODE_HAS_FLOAT_VARS 1788 for (
int i = 0;
i < fv.
size();
i++)
1791 #ifdef GECODE_HAS_SET_VARS 1792 for (
int i = 0;
i < sv.
size();
i++)
1793 oss <<
"var " << sv[
i] <<
": " << p.
setVarName(
i) <<
";" << std::endl;
1801 template<
template<
class>
class Engine,
1802 template<
class,
template<
class>
class>
class Meta>
1804 FlatZincSpace::runMeta(std::ostream& out, const Printer& p,
1805 const FlatZincOptions& opt, Support::Timer& t_total) {
1806 #ifdef GECODE_HAS_GIST 1815 unsigned int n_p = 0;
1827 #ifdef GECODE_HAS_CPPROFILER 1840 #ifdef GECODE_HAS_FLOAT_VARS 1848 Meta<FlatZincSpace,Engine> se(
this,o);
1850 if (noOfSolutions == -1) {
1851 noOfSolutions = (_method == SAT) ? 1 : 0;
1853 bool printAll = _method == SAT || opt.
allSolutions() || noOfSolutions != 0;
1854 int findSol = noOfSolutions;
1855 FlatZincSpace* sol = NULL;
1856 while (FlatZincSpace* next_sol = se.next()) {
1861 out <<
"----------" << std::endl;
1866 if (sol && !printAll) {
1868 out <<
"----------" << std::endl;
1870 if (!se.stopped()) {
1872 out <<
"==========" << std::endl;
1874 out <<
"=====UNSATISFIABLE=====" << std::endl;
1877 out <<
"=====UNKNOWN=====" << std::endl;
1889 <<
"%% solvetime: ";
1893 <<
std::abs(noOfSolutions - findSol) << std::endl
1895 << (intVarCount + boolVarCount + setVarCount) << std::endl
1896 <<
"%% propagators: " << n_p << std::endl
1898 <<
"%% nodes: " << stat.
node << std::endl
1899 <<
"%% failures: " << stat.
fail << std::endl
1900 <<
"%% restarts: " << stat.
restart << std::endl
1901 <<
"%% peak depth: " << stat.
depth << std::endl
1908 #ifdef GECODE_HAS_QT 1910 FlatZincSpace::branchWithPlugin(
AST::Node* ann) {
1911 if (
AST::Call*
c = dynamic_cast<AST::Call*>(ann)) {
1912 QString pluginName(
c->id.c_str());
1913 if (QLibrary::isLibrary(pluginName+
".dll")) {
1914 pluginName +=
".dll";
1915 }
else if (QLibrary::isLibrary(pluginName+
".dylib")) {
1916 pluginName =
"lib" + pluginName +
".dylib";
1917 }
else if (QLibrary::isLibrary(pluginName+
".so")) {
1919 pluginName =
"lib" + pluginName +
".so";
1921 QPluginLoader pl(pluginName);
1922 QObject* plugin_o = pl.instance();
1925 "Error loading plugin "+pluginName.toStdString()+
1926 ": "+pl.errorString().toStdString());
1928 BranchPlugin* pb = qobject_cast<BranchPlugin*>(plugin_o);
1931 "Error loading plugin "+pluginName.toStdString()+
1932 ": does not contain valid PluginBrancher");
1934 pb->branch(*
this,
c);
1939 FlatZincSpace::branchWithPlugin(
AST::Node*) {
1941 "Branching with plugins not supported (requires Qt support)");
1951 runEngine<BAB>(out,p,
opt,t_total);
1954 runEngine<DFS>(out,p,
opt,t_total);
1964 static_cast<const FlatZincSpace*>(&s)->iv[_optVar].val());
1965 else if (_method == MAX)
1967 static_cast<const FlatZincSpace*>(&s)->iv[_optVar].val());
1969 #ifdef GECODE_HAS_FLOAT_VARS 1972 static_cast<const FlatZincSpace*>(&s)->fv[_optVar].val()-
step);
1973 else if (_method == MAX)
1975 static_cast<const FlatZincSpace*>(&s)->fv[_optVar].val()+
step);
1983 (_lns > 0) && (mi.
last()==NULL) && (_lnsInitialSolution.size()>0)) {
1984 for (
unsigned int i=iv_lns.
size();
i--;) {
1985 if (_random(99) <= _lns) {
1986 rel(*
this, iv_lns[
i],
IRT_EQ, _lnsInitialSolution[i]);
1991 (_lns > 0) && mi.
last()) {
1992 const FlatZincSpace& last =
1993 static_cast<const FlatZincSpace&
>(*mi.
last());
1994 for (
unsigned int i=iv_lns.
size();
i--;) {
1995 if (_random(99) <= _lns) {
2006 return new FlatZincSpace(*
this);
2021 return _optVarIsInt;
2038 (void) s; (void) out;
2039 #ifdef GECODE_HAS_GIST 2040 const FlatZincSpace& fs =
dynamic_cast<const FlatZincSpace&
>(s);
2041 for (
int i = 0;
i < iv.
size(); ++
i) {
2042 std::stringstream ss;
2043 ss <<
"iv[" <<
i <<
"]";
2046 if (result.length() > 0) out << result << std::endl;
2048 for (
int i = 0;
i < bv.
size(); ++
i) {
2049 std::stringstream ss;
2050 ss <<
"bv[" <<
i <<
"]";
2053 if (result.length() > 0) out << result << std::endl;
2055 #ifdef GECODE_HAS_SET_VARS 2056 for (
int i = 0;
i < sv.
size(); ++
i) {
2057 std::stringstream ss;
2058 ss <<
"sv[" <<
i <<
"]";
2061 if (result.length() > 0) out << result << std::endl;
2064 #ifdef GECODE_HAS_FLOAT_VARS 2065 for (
int i = 0;
i < fv.
size(); ++
i) {
2066 std::stringstream ss;
2067 ss <<
"fv[" <<
i <<
"]";
2070 if (result.length() > 0) out << result << std::endl;
2105 for (
int i=offset;
i--;)
2107 for (
int i=a->
a.size();
i--;)
2108 ia[
i+offset] = a->
a[
i]->getInt();
2114 int noOfTuples = a->
a.size() == 0 ? 0 : (a->
a.size()/noOfVars);
2118 for (
int i=0;
i<noOfTuples;
i++) {
2120 for (
int j=0; j<noOfVars; j++) {
2121 t[j] = a->
a[
i*noOfVars+j]->getInt();
2128 FlatZincSpaceInitData::TupleSetSet::iterator it = _initData->tupleSetSet.find(ts);
2129 if (it != _initData->tupleSetSet.end()) {
2132 _initData->tupleSetSet.insert(ts);
2140 IntArgs ia(arg2intargs(arg,offset));
2143 FlatZincSpaceInitData::IntSharedArraySet::iterator it = _initData->intSharedArraySet.find(sia);
2144 if (it != _initData->intSharedArraySet.end()) {
2147 _initData->intSharedArraySet.insert(sia);
2156 for (
int i=offset;
i--;)
2158 for (
int i=a->
a.size();
i--;)
2159 ia[
i+offset] = a->
a[
i]->getBool();
2164 IntArgs ia(arg2boolargs(arg,offset));
2167 FlatZincSpaceInitData::IntSharedArraySet::iterator it = _initData->intSharedArraySet.find(sia);
2168 if (it != _initData->intSharedArraySet.end()) {
2171 _initData->intSharedArraySet.insert(sia);
2184 int* is = re.
alloc<
int>(
static_cast<unsigned long int>(sl->
s.size()));
2185 for (
int i=sl->
s.size();
i--; )
2194 if (a->
a.size() == 0) {
2199 for (
int i=offset;
i--;)
2201 for (
int i=a->
a.size();
i--;) {
2202 ia[
i+offset] = arg2intset(a->
a[
i]);
2209 if (a->
a.size() == 0) {
2214 for (
int i=offset;
i--;)
2216 for (
int i=a->
a.size();
i--;) {
2217 if (a->
a[
i]->isIntVar()) {
2218 ia[
i+offset] = iv[a->
a[
i]->getIntVar()];
2220 int value = a->
a[
i]->getInt();
2221 IntVar iv(*
this, value, value);
2230 if (a->
a.size() == 0) {
2235 for (
int i=offset;
i--;)
2237 for (
int i=0; i<static_cast<int>(a->
a.size());
i++) {
2240 if (a->
a[
i]->isBool()) {
2241 bool value = a->
a[
i]->getBool();
2242 BoolVar iv(*
this, value, value);
2244 }
else if (a->
a[
i]->isIntVar() &&
2245 aliasBool2Int(a->
a[
i]->getIntVar()) != -1) {
2246 ia[offset++] = bv[aliasBool2Int(a->
a[
i]->getIntVar())];
2248 ia[offset++] = bv[a->
a[
i]->getBoolVar()];
2278 if (a->
a.size() == 0)
2280 for (
int i=a->
a.size();
i--;) {
2281 if (a->
a[
i]->isBoolVar() || a->
a[
i]->isBool()) {
2282 }
else if (a->
a[
i]->isIntVar()) {
2283 if (aliasBool2Int(a->
a[
i]->getIntVar()) == -1) {
2284 if (singleInt != -1) {
2293 return singleInt==-1 || a->
a.size() > 1;
2295 #ifdef GECODE_HAS_SET_VARS 2301 x0 =
SetVar(*
this, d, d);
2312 for (
int i=offset;
i--;) {
2316 for (
int i=a->
a.size();
i--;) {
2317 ia[
i+offset] = arg2SetVar(a->
a[
i]);
2322 #ifdef GECODE_HAS_FLOAT_VARS 2327 for (
int i=offset;
i--;)
2329 for (
int i=a->
a.size();
i--;)
2330 fa[
i+offset] = a->
a[
i]->getFloat();
2336 if (a->
a.size() == 0) {
2341 for (
int i=offset;
i--;)
2343 for (
int i=a->
a.size();
i--;) {
2344 if (a->
a[
i]->isFloatVar()) {
2345 fa[
i+offset] = fv[a->
a[
i]->getFloatVar()];
2347 double value = a->
a[
i]->getFloat();
2384 FlatZincSpaceInitData::DFASet::iterator it = _initData->dfaSet.find(a);
2385 if (it != _initData->dfaSet.end()) {
2388 _initData->dfaSet.insert(a);
2399 Printer::printElem(std::ostream& out,
2419 }
else if (bv[ai->
getBoolVar()].max() == 0) {
2422 out <<
"false..true";
2424 #ifdef GECODE_HAS_SET_VARS 2435 int min = svr.min();
2436 int max = svr.max();
2443 for (; svv(); ++svv)
2444 out <<
", " << svv.val();
2447 out << min <<
".." <<
max;
2450 #ifdef GECODE_HAS_FLOAT_VARS 2461 std::ostringstream oss;
2463 oss << std::setprecision(std::numeric_limits<double>::digits10);
2465 if (oss.str().find(
".") == std::string::npos)
2472 }
else if (ai->
isBool()) {
2473 out << (ai->
getBool() ?
"true" :
"false");
2474 }
else if (ai->
isSet()) {
2477 out << s->
min <<
".." << s->
max;
2480 for (
unsigned int i=0;
i<s->
s.size();
i++) {
2481 out << s->
s[
i] << (
i < s->
s.size()-1 ?
", " :
"}");
2486 for (
unsigned int i=0;
i<s.
size();
i++) {
2487 if (s[
i] ==
'\\' &&
i<s.
size()-1) {
2489 case 'n': out <<
"\n";
break;
2490 case '\\': out <<
"\\";
break;
2491 case 't': out <<
"\t";
break;
2492 default: out <<
"\\" << s[
i+1];
2503 Printer::printElemDiff(std::ostream& out,
2509 #ifdef GECODE_HAS_SET_VARS
2513 #ifdef GECODE_HAS_FLOAT_VARS
2518 #ifdef GECODE_HAS_GIST 2526 if (res.length() > 0) {
2535 if (res.length() > 0) {
2541 #ifdef GECODE_HAS_SET_VARS 2545 if (res.length() > 0) {
2552 #ifdef GECODE_HAS_FLOAT_VARS 2556 if (res.length() > 0) {
2563 }
else if (ai->
isBool()) {
2564 out << (ai->
getBool() ?
"true" :
"false");
2565 }
else if (ai->
isSet()) {
2568 out << s->
min <<
".." << s->
max;
2571 for (
unsigned int i=0;
i<s->
s.size();
i++) {
2572 out << s->
s[
i] << (
i < s->
s.size()-1 ?
", " :
"}");
2577 for (
unsigned int i=0;
i<s.
size();
i++) {
2578 if (s[
i] ==
'\\' &&
i<s.
size()-1) {
2580 case 'n': out <<
"\n";
break;
2581 case '\\': out <<
"\\";
break;
2582 case 't': out <<
"\t";
break;
2583 default: out <<
"\\" << s[
i+1];
2598 #ifdef GECODE_HAS_SET_VARS 2602 #ifdef GECODE_HAS_FLOAT_VARS 2614 #ifdef GECODE_HAS_SET_VARS
2618 #ifdef GECODE_HAS_FLOAT_VARS
2623 if (_output == NULL)
2625 for (
unsigned int i=0;
i< _output->
a.size();
i++) {
2629 int size = aia->
a.size();
2631 for (
int j=0; j<
size; j++) {
2632 printElem(out,aia->
a[j],iv,bv
2633 #ifdef GECODE_HAS_SET_VARS
2636 #ifdef GECODE_HAS_FLOAT_VARS
2645 printElem(out,ai,iv,bv
2646 #ifdef GECODE_HAS_SET_VARS
2649 #ifdef GECODE_HAS_FLOAT_VARS
2663 #ifdef GECODE_HAS_SET_VARS
2668 #ifdef GECODE_HAS_FLOAT_VARS
2674 if (_output == NULL)
2676 for (
unsigned int i=0;
i< _output->
a.size();
i++) {
2680 int size = aia->
a.size();
2682 for (
int j=0; j<
size; j++) {
2683 printElemDiff(out,aia->
a[j],iv1,iv2,bv1,bv2
2684 #ifdef GECODE_HAS_SET_VARS
2687 #ifdef GECODE_HAS_FLOAT_VARS
2696 printElemDiff(out,ai,iv1,iv2,bv1,bv2
2697 #ifdef GECODE_HAS_SET_VARS
2700 #ifdef GECODE_HAS_FLOAT_VARS
2710 iv_names.push_back(n);
2714 bv_names.push_back(n);
2716 #ifdef GECODE_HAS_FLOAT_VARS 2719 fv_names.push_back(n);
2722 #ifdef GECODE_HAS_SET_VARS 2725 sv_names.push_back(n);
2731 std::map<int,int>& iv, std::map<int,int>& bv,
2732 std::map<int,int>& sv, std::map<int,int>& fv) {
2735 if (iv.find(x->
i) == iv.end()) {
2736 int newi = iv.size();
2742 if (bv.find(x->
i) == bv.end()) {
2743 int newi = bv.size();
2749 if (sv.find(x->
i) == sv.end()) {
2750 int newi = sv.size();
2756 if (fv.find(x->
i) == fv.end()) {
2757 int newi = fv.size();
2766 int& optVar,
bool optVarIsInt,
2769 #ifdef GECODE_HAS_SET_VARS
2773 #ifdef GECODE_HAS_FLOAT_VARS
2778 if (_output == NULL) {
2779 if (optVarIsInt && optVar != -1) {
2788 #ifdef GECODE_HAS_SET_VARS 2791 #ifdef GECODE_HAS_FLOAT_VARS 2792 if (!optVarIsInt && optVar != -1) {
2803 std::map<int,int> iv_new;
2804 std::map<int,int> bv_new;
2805 std::map<int,int> sv_new;
2806 std::map<int,int> fv_new;
2816 for (
unsigned int i=0;
i< _output->
a.size();
i++) {
2820 for (
unsigned int j=0; j<aia->
a.size(); j++) {
2821 shrinkElement(aia->
a[j],iv_new,bv_new,sv_new,fv_new);
2824 shrinkElement(ai,iv_new,bv_new,sv_new,fv_new);
2829 for (std::map<int,int>::iterator
i=iv_new.
begin();
i != iv_new.
end(); ++
i) {
2830 iva[(*i).second] = iv[(*i).first];
2835 for (std::map<int,int>::iterator
i=bv_new.
begin();
i != bv_new.
end(); ++
i) {
2836 bva[(*i).second] = bv[(*i).first];
2840 #ifdef GECODE_HAS_SET_VARS 2842 for (std::map<int,int>::iterator
i=sv_new.
begin();
i != sv_new.
end(); ++
i) {
2843 sva[(*i).second] = sv[(*i).first];
2848 #ifdef GECODE_HAS_FLOAT_VARS 2850 for (std::map<int,int>::iterator
i=fv_new.
begin();
i != fv_new.
end(); ++
i) {
2851 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.
int val(void) const
Return assigned value (only if assigned)
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.
FlatZincGetInfo(const Printer &printer)
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.
FloatNum med(void) const
Return median of domain (closest representation)
void finalize(void)
Finalize tuple set.
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.
void cmb_hash(std::size_t &seed, int h)
Combine hash value h into seed.
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.
std::vector< bool > sv_introduced
Indicates whether a set variable is introduced by mzn2fzn.
Class to send solution information to CPProfiler.
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.
Gecode::BoolVarArray bv
The Boolean variables.
size_t operator()(const Gecode::DFA &d) const
Return hash key for d.
void put(unsigned int i)
Add i to the contents.
void update(Space &home, VarArray< Var > &a)
Update array to be a clone of array a.
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 .
FlatZincSpaceInitData(void)
Initialize.
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.
bool assigned(void) const
Test whether view is assigned.
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.
size_t operator()(const Gecode::SharedArray< int > &x) const
Return hash key for x.
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.
std::size_t hash(void) const
Return hash key.
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)
DFASet dfaSet
Hash table of DFAs.
bool profiler_info(void) const
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)
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)
Class to record search trace info for CPProfiler.
void varValPrint(const Space &home, const Brancher &b, unsigned int a, Var, int i, const int &n, std::ostream &o)
void printIntVar(std::ostream &os, const std::string name, const Int::IntView &x)
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.
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.
IntSharedArray arg2intsharedarray(AST::Node *arg, int offset=0)
Convert arg (array of integers) to IntSharedArray.
unsigned int profiler_port(void) const
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
virtual Gecode::Space * copy(void)
Copy function.
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.
IntSharedArray arg2boolsharedarray(AST::Node *arg, int offset=0)
Convert arg (array of integers) to IntSharedArray.
bool alias
Whether the variable aliases another variable.
SetVarBranch ann2svarsel(AST::Node *ann, Rnd rnd, double decay)
void start(void)
Start timer.
DFA getSharedDFA(DFA &a)
Share DFA a if possible.
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.
Gecode::FloatVal c(-8, 8)
int profiler_id(void) const
std::size_t hash(void) const
Return hash key.
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)
size_t operator()(const Gecode::TupleSet &x) const
Return hash key for x.
SetVarBranch SET_VAR_AFC_MAX(double d, BranchTbl tbl)
Deterministic finite automaton (DFA)
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.
#define GECODE_HAS_SET_VARS
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
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.
int size(void) const
Return number of elements.
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.
Space * clone(CloneStatistics &stat=unused_clone) const
Clone space.
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.
FloatNum min(void) const
Return minimum of domain.
Which integer or Boolean variable to select for branching.
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.
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.
struct Gecode::Space::@58::@59 p
Data only available during propagation or branching.
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)
virtual ExecStatus commit(Space &, const Gecode::Choice &c, unsigned int)
Perform commit for choice c.
int min(void) const
Return smallest value of range.
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.
const char * name(void) const
Return name of script.
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.
struct Gecode::Space::@58::@60 c
Data available only during copying.
void branch(Home home, const IntVarArgs &x, const BoolVarArgs &y, IntBoolVarBranch vars, IntValBranch vals)
Branch function for integer and Boolean variables.
bool clone
Whether engines create a clone when being initialized.
int min(void) const
Return minimum of domain.
void print(std::ostream &out, const Gecode::IntVarArray &iv, const Gecode::BoolVarArray &bv, const Gecode::SetVarArray &sv, const Gecode::FloatVarArray &fv) const
Array * getArgs(unsigned int n)
BoolAssign BOOL_ASSIGN_RND(Rnd r)
Select random value.
FlatZincSpaceInitData * _initData
Initialisation data (only used for posting constraints)
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 std::string getInfo(const Space &space) const
Return info for a space.
virtual void compare(const Space &s0, const Space &s1)=0
Call-back function.
Choice that only signals failure or success
bool range(void) const
Test whether domain is a range.
SetVarBranch SET_VAR_RND(Rnd r)
IntSharedArraySet intSharedArraySet
Hash table of shared integer arrays.
unsigned int node(void) const
Option< AST::SetLit *> domain
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.
SearchTracer * tracer
Tracer object for tracing search.
bool isIntVar(void)
Test if node is an integer variable node.
std::unordered_set< SharedArray< int > > IntSharedArraySet
Hash table of shared integer arrays.
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.
Float view for float variables.
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)
Post propagator for SetVar SetOpType SetVar SetRelType r
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 .
Class represeting a set of tuples.
bool assigned
Whether the variable is assigned.
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.
struct Gecode::@585::NNF::@62::@63 b
For binary nodes (and, or, eqv)
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
Integer view for integer variables.
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.
bool assigned(void) const
Test whether view is assigned.
Exception: Base-class for exceptions
Print statistics for script.
Base class for variables.
IntValBranch INT_VALUES_MIN(void)
Try all values starting from smallest.
Run script with CP-profiler.
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
Node * x
Pointer to corresponding Boolean expression node.
BoolVarBranch BOOL_VAR_DEGREE_MAX(BranchTbl tbl)
Select variable with largest degree.
FloatNum max(void) const
Return maximum of domain.
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.
struct Gecode::@585::NNF::@62::@64 a
For atomic nodes.
Choice for performing commit
unsigned int fail(void) const
bool hasAtom(const std::string &id)
Test if node has atom with id.
virtual Actor * copy(Space &home)
Copy brancher.
bool isFloatVar(void)
Test if node is a float variable node.
IntBoolVarBranch INTBOOL_VAR_AFC_SIZE_MAX(double d=1.0)
Select variable with largest accumulated failure count divided by domain size.
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.
FlatZincSpace(FlatZincSpace &)
Copy constructor.
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.
std::unordered_set< TupleSet > TupleSetSet
Hash table of tuple sets.
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 Options: basic versus advanced propagation.
TieBreak< FloatVarBranch > ann2fvarsel(AST::Node *ann, Rnd rnd, double decay)
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.
std::unordered_set< DFA > DFASet
Hash table of DFAs.
IntVarBranch INT_VAR_ACTION_SIZE_MIN(double d, BranchTbl tbl)
Select variable with smallest action divided by domain size with decay factor d.
void printFloatVar(std::ostream &os, const std::string name, const Float::FloatView &f)
~FlatZincSpace(void)
Destructor.
An window for simple text output.
bool needAuxVars
Whether the introduced variables still need to be copied.
virtual std::string name(void)
Return name.
void printBoolVar(std::ostream &os, const std::string name, const BoolVar &b)
int max(void) const
Return largest value of range.
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.
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
TupleSet & add(const IntArgs &t)
Add tuple t to tuple set.
void aliasBool2Int(int iv, int bv)
Link integer variable iv to Boolean variable bv.
Rnd _random
Random number generator.
FloatVarBranch FLOAT_VAR_MIN_MIN(BranchTbl tbl)
Select variable with smallest min.
#define GECODE_HAS_FLOAT_VARS
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
int max(void) const
Return maximum of domain.
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.
TupleSet arg2tupleset(AST::Node *n, int noOfVars)
Convert n to TupleSet.
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.
std::string getDomains(const Printer &p) const
Get string representing the domains of variables (for cpprofiler)
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.
TupleSetSet tupleSetSet
Hash table of tuple sets.
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.
AuxVarBrancher(Space &home, AuxVarBrancher &b)
Copy constructor.
TieBreak< IntVarBranch > int_varsel
int val(void) const
Return assigned value.
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.
Rnd defrnd
Uninitialized default random number generator.
SetVarBranch SET_VAR_ACTION_MIN(double d, BranchTbl tbl)
Abstract representation of a constraint.