Go to the documentation of this file.
49 #include <unordered_set>
55 template<>
struct hash<
Gecode::TupleSet> {
64 template<>
struct hash<
Gecode::SharedArray<int> > {
68 size_t seed = static_cast<size_t>(
x.size());
69 for (
int i=
x.size();
i--; )
76 template<>
struct hash<
Gecode::DFA> {
85 namespace Gecode {
namespace FlatZinc {
145 virtual size_t size(
void)
const {
159 #ifdef GECODE_HAS_SET_VARS
163 #ifdef GECODE_HAS_FLOAT_VARS
171 if (
done)
return false;
172 const FlatZincSpace& home = static_cast<const FlatZincSpace&>(_home);
177 #ifdef GECODE_HAS_SET_VARS
181 #ifdef GECODE_HAS_FLOAT_VARS
195 #ifdef GECODE_HAS_SET_VARS
198 #ifdef GECODE_HAS_FLOAT_VARS
205 return new Choice(*
this,
false);
207 return new Choice(*
this,
true);
212 bool fail; e >> fail;
213 return new Choice(*
this, fail);
222 std::ostream& o)
const {
224 << (static_cast<const Choice&>(
c).fail ?
"fail" :
"ok")
260 return sizeof(*this);
269 std::vector<std::string>
n;
270 BI(
void) : r0(
""), r1(
""),
n(0) {}
271 BI(
const std::string& r00,
const std::string& r10,
272 const std::vector<std::string>& n0)
273 : r0(r00), r1(r10),
n(n0) {}
285 const std::string& rel0,
286 const std::string& rel1,
287 const std::vector<std::string>&
n) {
288 v.resize(
std::max(static_cast<unsigned int>(v.size()),bg.
id()+1));
289 v[bg.
id()] = BI(rel0,rel1,
n);
293 unsigned int a,
int i,
int n, std::ostream& o)
const {
294 const BI&
bi = v[
b.group().id()];
295 o <<
bi.n[
i] <<
" " << (
a==0 ?
bi.r0 :
bi.r1) <<
" " <<
n;
297 #ifdef GECODE_HAS_FLOAT_VARS
300 std::ostream& o)
const {
301 const BI&
bi = v[
b.group().id()];
303 << (((
a == 0) == nl.
l) ?
"<=" :
">=") << nl.
n;
316 assert(
object() == NULL);
322 const std::string& rel0,
323 const std::string& rel1,
324 const std::vector<std::string>&
n) {
325 static_cast<BranchInformationO*>(
object())->add(bg,rel0,rel1,
n);
329 int n, std::ostream& o)
const {
330 static_cast<const BranchInformationO*>(
object())->print(
b,
a,
i,
n,o);
332 #ifdef GECODE_HAS_FLOAT_VARS
336 static_cast<const BranchInformationO*>(
object())->print(
b,
a,
i,nl,o);
342 Var,
int i,
const int&
n,
344 static_cast<const FlatZincSpace&>(home).branchInfo.print(
b,
a,
i,
n,o);
347 #ifdef GECODE_HAS_FLOAT_VARS
352 static_cast<const FlatZincSpace&>(home).branchInfo.print(
b,
a,
i,nl,o);
365 int* newdom =
heap.
alloc<
int>(static_cast<unsigned long int>(sl->
s.size()));
366 for (
int i=sl->
s.size();
i--;)
367 newdom[
i] = sl->
s[
i];
368 IntSet ret(newdom, sl->
s.size());
369 heap.
free(newdom, static_cast<unsigned long int>(sl->
s.size()));
401 if (
AST::Atom* s = dynamic_cast<AST::Atom*>(ann)) {
402 if (s->id ==
"input_order")
404 if (s->id ==
"first_fail")
406 if (s->id ==
"anti_first_fail")
408 if (s->id ==
"smallest")
410 if (s->id ==
"largest")
412 if (s->id ==
"occurrence")
414 if (s->id ==
"max_regret")
416 if (s->id ==
"most_constrained")
419 if (s->id ==
"random") {
422 if (s->id ==
"dom_w_deg") {
425 if (s->id ==
"afc_min")
427 if (s->id ==
"afc_max")
429 if (s->id ==
"afc_size_min")
431 if (s->id ==
"afc_size_max") {
434 if (s->id ==
"action_min")
436 if (s->id ==
"action_max")
438 if (s->id ==
"action_size_min")
440 if (s->id ==
"action_size_max")
443 std::cerr <<
"Warning, ignored search annotation: ";
444 ann->
print(std::cerr);
445 std::cerr << std::endl;
451 if (
AST::Atom* s = dynamic_cast<AST::Atom*>(ann)) {
452 if (s->id ==
"indomain_min") {
456 if (s->id ==
"indomain_max") {
460 if (s->id ==
"indomain_median") {
464 if (s->id ==
"indomain_split") {
468 if (s->id ==
"indomain_reverse_split") {
472 if (s->id ==
"indomain_random") {
476 if (s->id ==
"indomain") {
480 if (s->id ==
"indomain_middle") {
481 std::cerr <<
"Warning, replacing unsupported annotation "
482 <<
"indomain_middle with indomain_median" << std::endl;
486 if (s->id ==
"indomain_interval") {
487 std::cerr <<
"Warning, replacing unsupported annotation "
488 <<
"indomain_interval with indomain_split" << std::endl;
493 std::cerr <<
"Warning, ignored search annotation: ";
494 ann->
print(std::cerr);
495 std::cerr << std::endl;
501 if (
AST::Atom* s = dynamic_cast<AST::Atom*>(ann)) {
502 if (s->id ==
"indomain_min")
504 if (s->id ==
"indomain_max")
506 if (s->id ==
"indomain_median")
508 if (s->id ==
"indomain_random") {
512 std::cerr <<
"Warning, ignored search annotation: ";
513 ann->
print(std::cerr);
514 std::cerr << std::endl;
519 if (
AST::Atom* s = dynamic_cast<AST::Atom*>(ann)) {
520 if ((s->id ==
"input_order") ||
521 (s->id ==
"first_fail") ||
522 (s->id ==
"anti_first_fail") ||
523 (s->id ==
"smallest") ||
524 (s->id ==
"largest") ||
525 (s->id ==
"max_regret"))
527 if ((s->id ==
"occurrence") ||
528 (s->id ==
"most_constrained"))
530 if (s->id ==
"random")
532 if ((s->id ==
"afc_min") ||
533 (s->id ==
"afc_size_min"))
535 if ((s->id ==
"afc_max") ||
536 (s->id ==
"afc_size_max") ||
537 (s->id ==
"dom_w_deg"))
539 if ((s->id ==
"action_min") &&
540 (s->id ==
"action_size_min"))
542 if ((s->id ==
"action_max") ||
543 (s->id ==
"action_size_max"))
546 std::cerr <<
"Warning, ignored search annotation: ";
547 ann->
print(std::cerr);
548 std::cerr << std::endl;
554 if (
AST::Atom* s = dynamic_cast<AST::Atom*>(ann)) {
555 if (s->id ==
"indomain_min") {
559 if (s->id ==
"indomain_max") {
563 if (s->id ==
"indomain_median") {
567 if (s->id ==
"indomain_split") {
571 if (s->id ==
"indomain_reverse_split") {
575 if (s->id ==
"indomain_random") {
579 if (s->id ==
"indomain") {
583 if (s->id ==
"indomain_middle") {
584 std::cerr <<
"Warning, replacing unsupported annotation "
585 <<
"indomain_middle with indomain_median" << std::endl;
589 if (s->id ==
"indomain_interval") {
590 std::cerr <<
"Warning, replacing unsupported annotation "
591 <<
"indomain_interval with indomain_split" << std::endl;
596 std::cerr <<
"Warning, ignored search annotation: ";
597 ann->
print(std::cerr);
598 std::cerr << std::endl;
604 if (
AST::Atom* s = dynamic_cast<AST::Atom*>(ann)) {
605 if ((s->id ==
"indomain_min") ||
606 (s->id ==
"indomain_median"))
608 if (s->id ==
"indomain_max")
610 if (s->id ==
"indomain_random") {
614 std::cerr <<
"Warning, ignored search annotation: ";
615 ann->
print(std::cerr);
616 std::cerr << std::endl;
620 #ifdef GECODE_HAS_SET_VARS
622 if (
AST::Atom* s = dynamic_cast<AST::Atom*>(ann)) {
623 if (s->id ==
"input_order")
625 if (s->id ==
"first_fail")
627 if (s->id ==
"anti_first_fail")
629 if (s->id ==
"smallest")
631 if (s->id ==
"largest")
633 if (s->id ==
"afc_min")
635 if (s->id ==
"afc_max")
637 if (s->id ==
"afc_size_min")
639 if (s->id ==
"afc_size_max")
641 if (s->id ==
"action_min")
643 if (s->id ==
"action_max")
645 if (s->id ==
"action_size_min")
647 if (s->id ==
"action_size_max")
649 if (s->id ==
"random") {
653 std::cerr <<
"Warning, ignored search annotation: ";
654 ann->
print(std::cerr);
655 std::cerr << std::endl;
662 if (
AST::Atom* s = dynamic_cast<AST::Atom*>(ann)) {
663 if (s->id ==
"indomain_min") {
664 r0 =
"in"; r1 =
"not in";
667 if (s->id ==
"indomain_max") {
668 r0 =
"in"; r1 =
"not in";
671 if (s->id ==
"outdomain_min") {
672 r1 =
"in"; r0 =
"not in";
675 if (s->id ==
"outdomain_max") {
676 r1 =
"in"; r0 =
"not in";
680 std::cerr <<
"Warning, ignored search annotation: ";
681 ann->
print(std::cerr);
682 std::cerr << std::endl;
683 r0 =
"in"; r1 =
"not in";
688 #ifdef GECODE_HAS_FLOAT_VARS
691 if (
AST::Atom* s = dynamic_cast<AST::Atom*>(ann)) {
692 if (s->id ==
"input_order")
694 if (s->id ==
"first_fail")
696 if (s->id ==
"anti_first_fail")
698 if (s->id ==
"smallest")
700 if (s->id ==
"largest")
702 if (s->id ==
"occurrence")
704 if (s->id ==
"most_constrained")
707 if (s->id ==
"random") {
710 if (s->id ==
"afc_min")
712 if (s->id ==
"afc_max")
714 if (s->id ==
"afc_size_min")
716 if (s->id ==
"afc_size_max")
718 if (s->id ==
"action_min")
720 if (s->id ==
"action_max")
722 if (s->id ==
"action_size_min")
724 if (s->id ==
"action_size_max")
727 std::cerr <<
"Warning, ignored search annotation: ";
728 ann->
print(std::cerr);
729 std::cerr << std::endl;
734 if (
AST::Atom* s = dynamic_cast<AST::Atom*>(ann)) {
735 if (s->id ==
"indomain_split") {
739 if (s->id ==
"indomain_reverse_split") {
744 std::cerr <<
"Warning, ignored search annotation: ";
745 ann->
print(std::cerr);
746 std::cerr << std::endl;
776 _initData(NULL), _random(
f._random),
777 _solveAnnotations(NULL), iv_boolalias(NULL),
781 needAuxVars(
f.needAuxVars) {
794 for (
int i=0;
i<
f.iv_aux.size();
i++) {
795 if (!
f.iv_aux[
i].assigned()) {
797 iva[iva.
size()-1].update(*
this,
f.iv_aux[
i]);
807 for (
int i=0;
i<
f.bv_aux.size();
i++) {
808 if (!
f.bv_aux[
i].assigned()) {
810 bva[bva.
size()-1].update(*
this,
f.bv_aux[
i]);
816 #ifdef GECODE_HAS_SET_VARS
821 for (
int i=0;
i<
f.sv_aux.size();
i++) {
822 if (!
f.sv_aux[
i].assigned()) {
824 sva[sva.
size()-1].update(*
this,
f.sv_aux[
i]);
830 #ifdef GECODE_HAS_FLOAT_VARS
835 for (
int i=0;
i<
f.fv_aux.size();
i++) {
836 if (!
f.fv_aux[
i].assigned()) {
838 fva[fva.
size()-1].update(*
this,
f.fv_aux[
i]);
848 intVarCount(-1), boolVarCount(-1), floatVarCount(-1), setVarCount(-1),
849 _optVar(-1), _optVarIsInt(true), _lns(0), _lnsInitialSolution(0),
851 _solveAnnotations(NULL), needAuxVars(true) {
857 int setVars,
int floatVars) {
868 #ifdef GECODE_HAS_SET_VARS
873 #ifdef GECODE_HAS_FLOAT_VARS
918 #ifdef GECODE_HAS_SET_VARS
930 int* is =
heap.
alloc<
int>(static_cast<unsigned long int>(vsv->s.size()));
931 for (
int i=vsv->s.
size();
i--; )
934 heap.
free(is,static_cast<unsigned long int>(vsv->s.size()));
943 int* is =
heap.
alloc<
int>(static_cast<unsigned long int>(vsv->
s.size()));
944 for (
int i=vsv->
s.size();
i--; )
947 heap.
free(is,static_cast<unsigned long int>(vsv->
s.size()));
965 #ifdef GECODE_HAS_FLOAT_VARS
996 struct ConExprOrder {
997 bool operator() (ConExpr* ce0, ConExpr* ce1) {
998 return ce0->args->a.size() < ce1->args->a.size();
1008 for (
unsigned int i=0;
i<ces.
size();
i++) {
1023 for (
unsigned int i=0;
i<ann->
a.size();
i++) {
1024 if (ann->
a[
i]->isCall(
"seq_search")) {
1026 if (
c->args->isArray())
1029 out.push_back(
c->args);
1031 out.push_back(ann->
a[
i]);
1039 std::ostream& err) {
1041 double decay =
opt.decay();
1042 Rnd rnd(static_cast<unsigned int>(seed));
1046 std::string def_int_rel_left =
"=";
1047 std::string def_int_rel_right =
"!=";
1050 std::string def_bool_rel_left =
"=";
1051 std::string def_bool_rel_right =
"!=";
1052 #ifdef GECODE_HAS_SET_VARS
1055 std::string def_set_rel_left =
"in";
1056 std::string def_set_rel_right =
"not in";
1058 #ifdef GECODE_HAS_FLOAT_VARS
1061 std::string def_float_rel_left =
"<=";
1062 std::string def_float_rel_right =
">";
1065 std::vector<bool> iv_searched(
iv.
size());
1066 for (
unsigned int i=
iv.
size();
i--;)
1067 iv_searched[
i] =
false;
1068 std::vector<bool> bv_searched(
bv.
size());
1069 for (
unsigned int i=
bv.
size();
i--;)
1070 bv_searched[
i] =
false;
1071 #ifdef GECODE_HAS_SET_VARS
1072 std::vector<bool> sv_searched(
sv.
size());
1073 for (
unsigned int i=
sv.
size();
i--;)
1074 sv_searched[
i] =
false;
1076 #ifdef GECODE_HAS_FLOAT_VARS
1077 std::vector<bool> fv_searched(
fv.
size());
1078 for (
unsigned int i=
fv.
size();
i--;)
1079 fv_searched[
i] =
false;
1084 std::vector<AST::Node*> flatAnn;
1088 flatAnn.push_back(ann);
1091 for (
unsigned int i=0;
i<flatAnn.
size();
i++) {
1092 if (flatAnn[
i]->isCall(
"restart_geometric")) {
1096 opt.restart_base(args->
a[0]->getFloat());
1097 opt.restart_scale(args->
a[1]->getInt());
1098 }
else if (flatAnn[
i]->isCall(
"restart_luby")) {
1102 }
else if (flatAnn[
i]->isCall(
"restart_linear")) {
1106 }
else if (flatAnn[
i]->isCall(
"restart_constant")) {
1110 }
else if (flatAnn[
i]->isCall(
"restart_none")) {
1112 }
else if (flatAnn[
i]->isCall(
"relax_and_reconstruct")) {
1115 "Only one relax_and_reconstruct annotation allowed");
1123 _lns = args->
a[1]->getInt();
1125 int k=vars->
a.size();
1126 for (
int i=vars->
a.size();
i--;)
1127 if (vars->
a[
i]->isInt())
1131 for (
unsigned int i=0;
i<vars->
a.size();
i++) {
1132 if (vars->
a[
i]->isInt())
1136 if (args->
a.size()==3) {
1139 for (
unsigned int i=initial->
a.size();
i--;)
1142 }
else if (flatAnn[
i]->isCall(
"gecode_search")) {
1144 branchWithPlugin(
c->args);
1145 }
else if (flatAnn[
i]->isCall(
"int_search")) {
1149 int k=vars->
a.size();
1150 for (
int i=vars->
a.size();
i--;)
1151 if (vars->
a[
i]->isInt())
1154 std::vector<std::string> names;
1156 for (
unsigned int i=0;
i<vars->
a.size();
i++) {
1157 if (vars->
a[
i]->isInt())
1159 va[k++] =
iv[vars->
a[
i]->getIntVar()];
1160 iv_searched[vars->
a[
i]->getIntVar()] =
true;
1161 names.push_back(vars->
a[
i]->getVarName());
1170 &varValPrint<IntVar>);
1173 }
else if (flatAnn[
i]->isCall(
"int_assign")) {
1177 int k=vars->
a.size();
1178 for (
int i=vars->
a.size();
i--;)
1179 if (vars->
a[
i]->isInt())
1183 for (
unsigned int i=0;
i<vars->
a.size();
i++) {
1184 if (vars->
a[
i]->isInt())
1186 va[k++] =
iv[vars->
a[
i]->getIntVar()];
1187 iv_searched[vars->
a[
i]->getIntVar()] =
true;
1190 &varValPrint<IntVar>);
1191 }
else if (flatAnn[
i]->isCall(
"bool_search")) {
1195 int k=vars->
a.size();
1196 for (
int i=vars->
a.size();
i--;)
1197 if (vars->
a[
i]->isBool())
1201 std::vector<std::string> names;
1202 for (
unsigned int i=0;
i<vars->
a.size();
i++) {
1203 if (vars->
a[
i]->isBool())
1205 va[k++] =
bv[vars->
a[
i]->getBoolVar()];
1206 bv_searched[vars->
a[
i]->getBoolVar()] =
true;
1207 names.push_back(vars->
a[
i]->getVarName());
1217 &varValPrint<BoolVar>);
1220 }
else if (flatAnn[
i]->isCall(
"int_default_search")) {
1225 def_int_rel_left,def_int_rel_right,rnd);
1226 }
else if (flatAnn[
i]->isCall(
"bool_default_search")) {
1231 def_bool_rel_left,def_bool_rel_right,
1233 }
else if (flatAnn[
i]->isCall(
"set_search")) {
1234 #ifdef GECODE_HAS_SET_VARS
1238 int k=vars->
a.size();
1239 for (
int i=vars->
a.size();
i--;)
1240 if (vars->
a[
i]->isSet())
1244 std::vector<std::string> names;
1245 for (
unsigned int i=0;
i<vars->
a.size();
i++) {
1246 if (vars->
a[
i]->isSet())
1248 va[k++] =
sv[vars->
a[
i]->getSetVar()];
1249 sv_searched[vars->
a[
i]->getSetVar()] =
true;
1250 names.push_back(vars->
a[
i]->getVarName());
1259 &varValPrint<SetVar>);
1263 if (!ignoreUnknown) {
1264 err <<
"Warning, ignored search annotation: ";
1265 flatAnn[
i]->print(err);
1269 }
else if (flatAnn[
i]->isCall(
"set_default_search")) {
1270 #ifdef GECODE_HAS_SET_VARS
1275 def_set_rel_left,def_set_rel_right,rnd);
1277 if (!ignoreUnknown) {
1278 err <<
"Warning, ignored search annotation: ";
1279 flatAnn[
i]->print(err);
1283 }
else if (flatAnn[
i]->isCall(
"float_default_search")) {
1284 #ifdef GECODE_HAS_FLOAT_VARS
1289 def_float_rel_left,def_float_rel_right);
1291 if (!ignoreUnknown) {
1292 err <<
"Warning, ignored search annotation: ";
1293 flatAnn[
i]->print(err);
1297 }
else if (flatAnn[
i]->isCall(
"float_search")) {
1298 #ifdef GECODE_HAS_FLOAT_VARS
1302 int k=vars->
a.size();
1303 for (
int i=vars->
a.size();
i--;)
1304 if (vars->
a[
i]->isFloat())
1308 std::vector<std::string> names;
1309 for (
unsigned int i=0;
i<vars->
a.size();
i++) {
1310 if (vars->
a[
i]->isFloat())
1312 va[k++] =
fv[vars->
a[
i]->getFloatVar()];
1313 fv_searched[vars->
a[
i]->getFloatVar()] =
true;
1314 names.push_back(vars->
a[
i]->getVarName());
1327 if (!ignoreUnknown) {
1328 err <<
"Warning, ignored search annotation: ";
1329 flatAnn[
i]->print(err);
1334 if (!ignoreUnknown) {
1335 err <<
"Warning, ignored search annotation: ";
1336 flatAnn[
i]->print(err);
1356 std::vector<std::string> iv_sol_names(
iv.
size()-(introduced+funcdep+searched));
1358 std::vector<std::string> iv_tmp_names(introduced);
1360 for (
int i=
iv.
size(), j=0, k=0;
i--;) {
1365 iv_tmp_names[j] =
p.intVarName(
i);
1366 iv_tmp[j++] =
iv[
i];
1369 iv_sol_names[k] =
p.intVarName(
i);
1370 iv_sol[k++] =
iv[
i];
1378 if (bv_searched[
i]) {
1388 std::vector<std::string> bv_sol_names(
bv.
size()-(introduced+funcdep+searched));
1391 std::vector<std::string> bv_tmp_names(introduced);
1392 for (
int i=
bv.
size(), j=0, k=0;
i--;) {
1397 bv_tmp_names[j] =
p.boolVarName(
i);
1398 bv_tmp[j++] =
bv[
i];
1401 bv_sol_names[k] =
p.boolVarName(
i);
1402 bv_sol[k++] =
bv[
i];
1406 if (iv_sol.
size() > 0 && bv_sol.
size() > 0) {
1407 branch(*
this, iv_sol, bv_sol, def_intbool_varsel, def_int_valsel);
1408 }
else if (iv_sol.
size() > 0) {
1410 branch(bg(*
this), iv_sol, def_int_varsel, def_int_valsel,
nullptr,
1411 &varValPrint<IntVar>);
1412 branchInfo.
add(bg,def_int_rel_left,def_int_rel_right,iv_sol_names);
1413 }
else if (bv_sol.
size() > 0) {
1415 branch(bg(*
this), bv_sol, def_bool_varsel, def_bool_valsel,
nullptr,
1416 &varValPrint<BoolVar>);
1417 branchInfo.
add(bg,def_bool_rel_left,def_bool_rel_right,bv_sol_names);
1419 #ifdef GECODE_HAS_FLOAT_VARS
1434 std::vector<std::string> fv_sol_names(
fv.
size()-(introduced+funcdep+searched));
1437 std::vector<std::string> fv_tmp_names(introduced);
1438 for (
int i=
fv.
size(), j=0, k=0;
i--;) {
1443 fv_tmp_names[j] =
p.floatVarName(
i);
1444 fv_tmp[j++] =
fv[
i];
1447 fv_sol_names[k] =
p.floatVarName(
i);
1448 fv_sol[k++] =
fv[
i];
1452 if (fv_sol.
size() > 0) {
1454 branch(bg(*
this), fv_sol, def_float_varsel, def_float_valsel,
nullptr,
1456 branchInfo.
add(bg,def_float_rel_left,def_float_rel_right,fv_sol_names);
1459 #ifdef GECODE_HAS_SET_VARS
1464 if (sv_searched[
i]) {
1474 std::vector<std::string> sv_sol_names(
sv.
size()-(introduced+funcdep+searched));
1477 std::vector<std::string> sv_tmp_names(introduced);
1478 for (
int i=
sv.
size(), j=0, k=0;
i--;) {
1483 sv_tmp_names[j] =
p.setVarName(
i);
1484 sv_tmp[j++] =
sv[
i];
1487 sv_sol_names[k] =
p.setVarName(
i);
1488 sv_sol[k++] =
sv[
i];
1492 if (sv_sol.
size() > 0) {
1494 branch(bg(*
this), sv_sol, def_set_varsel, def_set_valsel,
nullptr,
1495 &varValPrint<SetVar>);
1496 branchInfo.
add(bg,def_set_rel_left,def_set_rel_right,sv_sol_names);
1503 #ifdef GECODE_HAS_SET_VARS
1507 #ifdef GECODE_HAS_FLOAT_VARS
1515 def_bool_varsel, def_bool_valsel
1517 , def_set_varsel, def_set_valsel
1520 , def_float_varsel, def_float_valsel
1526 branch(bg(*
this),
iv_aux,def_int_varsel,def_int_valsel,
nullptr,
1527 &varValPrint<IntVar>);
1528 branchInfo.
add(bg,def_int_rel_left,def_int_rel_right,iv_tmp_names);
1532 branch(bg(*
this),
bv_aux,def_bool_varsel,def_bool_valsel,
nullptr,
1533 &varValPrint<BoolVar>);
1534 branchInfo.
add(bg,def_bool_rel_left,def_bool_rel_right,bv_tmp_names);
1536 #ifdef GECODE_HAS_SET_VARS
1539 branch(bg(*
this),
sv_aux,def_set_varsel,def_set_valsel,
nullptr,
1540 &varValPrint<SetVar>);
1541 branchInfo.
add(bg,def_set_rel_left,def_set_rel_right,sv_tmp_names);
1544 #ifdef GECODE_HAS_FLOAT_VARS
1547 branch(bg(*
this),
fv_aux,def_float_varsel,def_float_valsel,
nullptr,
1549 branchInfo.
add(bg,def_float_rel_left,def_float_rel_right,fv_tmp_names);
1558 std::vector<std::string> names(1);
1562 &varValPrint<IntVar>);
1565 #ifdef GECODE_HAS_FLOAT_VARS
1566 std::vector<std::string> names(1);
1567 names[0] =
p.floatVarName(
_optVar);
1576 std::vector<std::string> names(1);
1580 &varValPrint<IntVar>);
1583 #ifdef GECODE_HAS_FLOAT_VARS
1584 std::vector<std::string> names(1);
1585 names[0] =
p.floatVarName(
_optVar);
1628 #ifdef GECODE_HAS_GIST
1633 template<
class Engine>
1638 template<
typename S>
1652 template<
typename S>
1682 : TextOutput(
"Gecode/FlatZinc"),
p(p0) {}
1688 dynamic_cast<const S&>(node).print(getStream(),
p);
1689 getStream() << std::endl;
1713 :
Gecode::Gist::VarComparator<S>(
"Gecode/FlatZinc"),
p(p0) {}
1720 dynamic_cast<const S&>(s0).compare(dynamic_cast<const S&>(s1),
1721 this->getStream(),
p);
1723 this->getStream() <<
"Exception: " << e.
what();
1725 this->getStream() << std::endl;
1730 template<
template<
class>
class Engine>
1732 FlatZincSpace::runEngine(std::ostream& out,
const Printer&
p,
1735 runMeta<Engine,Driver::EngineToMeta>(out,
p,
opt,t_total);
1737 runMeta<Engine,RBS>(out,
p,
opt,t_total);
1741 #ifdef GECODE_HAS_CPPROFILER
1749 std::stringstream ss;
1750 if (
const FlatZincSpace* fz_space = dynamic_cast<const FlatZincSpace*>(&space)) {
1751 ss <<
"{\n\t\"domains\": \"";
1752 ss << fz_space->getDomains(
p);
1763 os <<
"int: " << name <<
" = " <<
x.val() <<
";";
1764 }
else if (
x.range()) {
1765 os <<
x.min() <<
".." <<
x.max() <<
": " << name <<
";";
1767 os <<
"array_union([";
1770 os <<
r.min() <<
".." <<
r.max();
1775 os <<
"]): " << name <<
";";
1780 os <<
"var bool: " << name;
1782 os <<
" = " << (
b.val() ?
"true" :
"false");
1785 #ifdef GECODE_HAS_FLOAT_VARS
1789 os <<
"float: " << name <<
" = " <<
f.med() <<
";";
1791 os <<
f.min() <<
".." <<
f.max() <<
": " << name <<
";";
1796 std::ostringstream oss;
1804 #ifdef GECODE_HAS_FLOAT_VARS
1808 #ifdef GECODE_HAS_SET_VARS
1810 oss <<
"var " <<
sv[
i] <<
": " <<
p.setVarName(
i) <<
";" << std::endl;
1818 template<
template<
class>
class Engine,
1819 template<
class,
template<
class>
class>
class Meta>
1822 const FlatZincOptions& opt, Support::Timer& t_total) {
1823 #ifdef GECODE_HAS_GIST
1832 unsigned int n_p = 0;
1844 #ifdef GECODE_HAS_CPPROFILER
1847 FlatZincGetInfo* getInfo =
nullptr;
1848 if (
opt.profiler_info())
1849 getInfo =
new FlatZincGetInfo(
p);
1850 o.tracer =
new CPProfilerSearchTracer(
opt.profiler_id(),
1851 opt.name(),
opt.profiler_port(),
1857 #ifdef GECODE_HAS_FLOAT_VARS
1860 o.threads =
opt.threads();
1861 o.nogoods_limit =
opt.nogoods() ?
opt.nogoods_limit() : 0;
1863 if (
opt.interrupt())
1866 Meta<FlatZincSpace,Engine> se(
this,o);
1867 int noOfSolutions =
opt.solutions();
1868 if (noOfSolutions == -1) {
1869 noOfSolutions = (_method == SAT) ? 1 : 0;
1871 bool printAll = _method == SAT ||
opt.allSolutions() || noOfSolutions != 0;
1872 int findSol = noOfSolutions;
1873 FlatZincSpace* sol = NULL;
1874 while (FlatZincSpace* next_sol = se.next()) {
1879 out <<
"----------" << std::endl;
1884 if (sol && !printAll) {
1886 out <<
"----------" << std::endl;
1888 if (!se.stopped()) {
1890 out <<
"==========" << std::endl;
1892 out <<
"=====UNSATISFIABLE=====" << std::endl;
1895 out <<
"=====UNKNOWN=====" << std::endl;
1899 if (
opt.interrupt())
1903 double totalTime = (t_total.
stop() / 1000.0);
1904 double solveTime = (t_solve.
stop() / 1000.0);
1905 double initTime = totalTime - solveTime;
1907 <<
"%%%mzn-stat: initTime=" << initTime
1909 out <<
"%%%mzn-stat: solveTime=" << solveTime
1911 out <<
"%%%mzn-stat: solutions="
1912 <<
std::abs(noOfSolutions - findSol) << std::endl
1913 <<
"%%%mzn-stat: variables="
1914 << (intVarCount + boolVarCount + setVarCount) << std::endl
1915 <<
"%%%mzn-stat: propagators=" << n_p << std::endl
1917 <<
"%%%mzn-stat: nodes=" << stat.
node << std::endl
1918 <<
"%%%mzn-stat: failures=" << stat.
fail << std::endl
1919 <<
"%%%mzn-stat: restarts=" << stat.
restart << std::endl
1920 <<
"%%%mzn-stat: peakDepth=" << stat.
depth << std::endl
1921 <<
"%%%mzn-stat-end" << std::endl
1929 #ifdef GECODE_HAS_QT
1931 FlatZincSpace::branchWithPlugin(AST::Node* ann) {
1932 if (AST::Call*
c = dynamic_cast<AST::Call*>(ann)) {
1933 QString pluginName(
c->id.c_str());
1934 if (QLibrary::isLibrary(pluginName+
".dll")) {
1935 pluginName +=
".dll";
1936 }
else if (QLibrary::isLibrary(pluginName+
".dylib")) {
1937 pluginName =
"lib" + pluginName +
".dylib";
1938 }
else if (QLibrary::isLibrary(pluginName+
".so")) {
1940 pluginName =
"lib" + pluginName +
".so";
1942 QPluginLoader pl(pluginName);
1943 QObject* plugin_o = pl.instance();
1945 throw FlatZinc::Error(
"FlatZinc",
1946 "Error loading plugin "+pluginName.toStdString()+
1947 ": "+pl.errorString().toStdString());
1949 BranchPlugin* pb = qobject_cast<BranchPlugin*>(plugin_o);
1951 throw FlatZinc::Error(
"FlatZinc",
1952 "Error loading plugin "+pluginName.toStdString()+
1953 ": does not contain valid PluginBrancher");
1955 pb->branch(*
this,
c);
1960 FlatZincSpace::branchWithPlugin(AST::Node*) {
1961 throw FlatZinc::Error(
"FlatZinc",
1962 "Branching with plugins not supported (requires Qt support)");
1972 runEngine<BAB>(out,
p,
opt,t_total);
1975 runEngine<DFS>(out,
p,
opt,t_total);
1985 static_cast<const FlatZincSpace*>(&s)->
iv[
_optVar].val());
1988 static_cast<const FlatZincSpace*>(&s)->
iv[
_optVar].val());
1990 #ifdef GECODE_HAS_FLOAT_VARS
1993 static_cast<const FlatZincSpace*>(&s)->
fv[
_optVar].val()-
step);
1996 static_cast<const FlatZincSpace*>(&s)->
fv[
_optVar].val()+
step);
2014 static_cast<const FlatZincSpace&>(*mi.
last());
2059 (void) s; (void) out;
2060 #ifdef GECODE_HAS_GIST
2061 const FlatZincSpace& fs = dynamic_cast<const FlatZincSpace&>(s);
2063 std::stringstream ss;
2064 ss <<
"iv[" <<
i <<
"]";
2067 if (result.length() > 0) out << result << std::endl;
2070 std::stringstream ss;
2071 ss <<
"bv[" <<
i <<
"]";
2074 if (result.length() > 0) out << result << std::endl;
2076 #ifdef GECODE_HAS_SET_VARS
2078 std::stringstream ss;
2079 ss <<
"sv[" <<
i <<
"]";
2082 if (result.length() > 0) out << result << std::endl;
2085 #ifdef GECODE_HAS_FLOAT_VARS
2087 std::stringstream ss;
2088 ss <<
"fv[" <<
i <<
"]";
2091 if (result.length() > 0) out << result << std::endl;
2126 for (
int i=offset;
i--;)
2128 for (
int i=
a->a.size();
i--;)
2129 ia[
i+offset] =
a->a[
i]->getInt();
2134 int noOfTuples =
a.size() == 0 ? 0 : (
a.size()/noOfVars);
2138 for (
int i=0;
i<noOfTuples;
i++) {
2140 for (
int j=0; j<noOfVars; j++) {
2141 t[j] =
a[
i*noOfVars+j];
2176 for (
int i=offset;
i--;)
2178 for (
int i=
a->a.size();
i--;)
2179 ia[
i+offset] =
a->a[
i]->getBool();
2204 int* is = re.
alloc<
int>(static_cast<unsigned long int>(sl->
s.size()));
2205 for (
int i=sl->
s.size();
i--; )
2214 if (
a->a.size() == 0) {
2219 for (
int i=offset;
i--;)
2221 for (
int i=
a->a.size();
i--;) {
2229 if (
a->a.size() == 0) {
2234 for (
int i=offset;
i--;)
2236 for (
int i=
a->a.size();
i--;) {
2237 if (
a->a[
i]->isIntVar()) {
2238 ia[
i+offset] =
iv[
a->a[
i]->getIntVar()];
2240 int value =
a->a[
i]->getInt();
2250 if (
a->a.size() == 0) {
2255 for (
int i=offset;
i--;)
2257 for (
int i=0; i<static_cast<int>(
a->a.size());
i++) {
2260 if (
a->a[
i]->isBool()) {
2261 bool value =
a->a[
i]->getBool();
2264 }
else if (
a->a[
i]->isIntVar() &&
2268 ia[offset++] =
bv[
a->a[
i]->getBoolVar()];
2277 x0 =
BoolVar(*
this,
n->getBool(),
n->getBool());
2280 x0 =
bv[
n->getBoolVar()];
2287 if (
n->isIntVar()) {
2288 x0 =
iv[
n->getIntVar()];
2290 x0 =
IntVar(*
this,
n->getInt(),
n->getInt());
2298 if (
a->a.size() == 0)
2300 for (
int i=
a->a.size();
i--;) {
2301 if (
a->a[
i]->isBoolVar() ||
a->a[
i]->isBool()) {
2302 }
else if (
a->a[
i]->isIntVar()) {
2304 if (singleInt != -1) {
2313 return singleInt==-1 ||
a->a.size() > 1;
2315 #ifdef GECODE_HAS_SET_VARS
2319 if (!
n->isSetVar()) {
2323 x0 =
sv[
n->getSetVar()];
2332 for (
int i=offset;
i--;) {
2336 for (
int i=
a->a.size();
i--;) {
2342 #ifdef GECODE_HAS_FLOAT_VARS
2347 for (
int i=offset;
i--;)
2349 for (
int i=
a->a.size();
i--;)
2350 fa[
i+offset] =
a->a[
i]->getFloat();
2356 if (
a->a.size() == 0) {
2361 for (
int i=offset;
i--;)
2363 for (
int i=
a->a.size();
i--;) {
2364 if (
a->a[
i]->isFloatVar()) {
2365 fa[
i+offset] =
fv[
a->a[
i]->getFloatVar()];
2367 double value =
a->a[
i]->getFloat();
2377 if (
n->isFloatVar()) {
2378 x0 =
fv[
n->getFloatVar()];
2380 x0 =
FloatVar(*
this,
n->getFloat(),
n->getFloat());
2419 Printer::printElem(std::ostream& out,
2439 }
else if (bv[ai->
getBoolVar()].max() == 0) {
2442 out <<
"false..true";
2444 #ifdef GECODE_HAS_SET_VARS
2450 SetVarGlbRanges svr(sv[ai->
getSetVar()]);
2455 int min = svr.min();
2456 int max = svr.max();
2459 SetVarGlbValues svv(sv[ai->
getSetVar()]);
2463 for (; svv(); ++svv)
2464 out <<
", " << svv.val();
2467 out <<
min <<
".." <<
max;
2470 #ifdef GECODE_HAS_FLOAT_VARS
2481 std::ostringstream oss;
2483 oss << std::setprecision(std::numeric_limits<double>::digits10);
2485 if (oss.str().find(
".") == std::string::npos)
2492 }
else if (ai->
isBool()) {
2493 out << (ai->
getBool() ?
"true" :
"false");
2494 }
else if (ai->
isSet()) {
2495 AST::SetLit* s = ai->
getSet();
2497 out << s->
min <<
".." << s->max;
2500 for (
unsigned int i=0;
i<s->s.
size();
i++) {
2501 out << s->s[
i] << (
i < s->s.
size()-1 ?
", " :
"}");
2506 for (
unsigned int i=0;
i<s.
size();
i++) {
2507 if (s[
i] ==
'\\' &&
i<s.
size()-1) {
2509 case 'n': out <<
"\n";
break;
2510 case '\\': out <<
"\\";
break;
2511 case 't': out <<
"\t";
break;
2512 default: out <<
"\\" << s[
i+1];
2523 Printer::printElemDiff(std::ostream& out,
2538 #ifdef GECODE_HAS_GIST
2543 }
else if (ai->isIntVar()) {
2545 iv2[ai->getIntVar()]));
2546 if (res.length() > 0) {
2550 out << iv1[ai->getIntVar()];
2552 }
else if (ai->isBoolVar()) {
2554 bv2[ai->getBoolVar()]));
2555 if (res.length() > 0) {
2559 out << bv1[ai->getBoolVar()];
2561 #ifdef GECODE_HAS_SET_VARS
2562 }
else if (ai->isSetVar()) {
2564 sv2[ai->getSetVar()]));
2565 if (res.length() > 0) {
2569 out << sv1[ai->getSetVar()];
2572 #ifdef GECODE_HAS_FLOAT_VARS
2573 }
else if (ai->isFloatVar()) {
2575 fv2[ai->getFloatVar()]));
2576 if (res.length() > 0) {
2580 out << fv1[ai->getFloatVar()];
2583 }
else if (ai->isBool()) {
2584 out << (ai->getBool() ?
"true" :
"false");
2585 }
else if (ai->isSet()) {
2586 AST::SetLit* s = ai->getSet();
2588 out << s->min <<
".." << s->max;
2591 for (
unsigned int i=0;
i<s->s.
size();
i++) {
2592 out << s->s[
i] << (
i < s->s.
size()-1 ?
", " :
"}");
2595 }
else if (ai->isString()) {
2596 std::string s = ai->getString();
2597 for (
unsigned int i=0;
i<s.
size();
i++) {
2598 if (s[
i] ==
'\\' &&
i<s.
size()-1) {
2600 case 'n': out <<
"\n";
break;
2601 case '\\': out <<
"\\";
break;
2602 case 't': out <<
"\t";
break;
2603 default: out <<
"\\" << s[
i+1];
2618 #ifdef GECODE_HAS_SET_VARS
2622 #ifdef GECODE_HAS_FLOAT_VARS
2643 if (_output == NULL)
2645 for (
unsigned int i=0;
i< _output->
a.size();
i++) {
2649 int size = aia->
a.size();
2651 for (
int j=0; j<
size; j++) {
2652 printElem(out,aia->
a[j],iv,bv
2665 printElem(out,ai,iv,bv
2694 if (_output == NULL)
2696 for (
unsigned int i=0;
i< _output->
a.size();
i++) {
2700 int size = aia->
a.size();
2702 for (
int j=0; j<
size; j++) {
2703 printElemDiff(out,aia->
a[j],iv1,iv2,bv1,bv2
2716 printElemDiff(out,ai,iv1,iv2,bv1,bv2
2730 iv_names.push_back(
n);
2734 bv_names.push_back(
n);
2736 #ifdef GECODE_HAS_FLOAT_VARS
2739 fv_names.push_back(
n);
2742 #ifdef GECODE_HAS_SET_VARS
2745 sv_names.push_back(
n);
2751 std::map<int,int>& iv, std::map<int,int>& bv,
2752 std::map<int,int>& sv, std::map<int,int>& fv) {
2755 if (iv.find(
x->i) == iv.end()) {
2756 int newi = iv.size();
2762 if (bv.find(
x->i) == bv.end()) {
2763 int newi = bv.size();
2769 if (sv.find(
x->i) == sv.end()) {
2770 int newi = sv.size();
2776 if (fv.find(
x->i) == fv.end()) {
2777 int newi = fv.size();
2786 int& optVar,
bool optVarIsInt,
2798 if (_output == NULL) {
2799 if (optVarIsInt && optVar != -1) {
2808 #ifdef GECODE_HAS_SET_VARS
2811 #ifdef GECODE_HAS_FLOAT_VARS
2812 if (!optVarIsInt && optVar != -1) {
2823 std::map<int,int> iv_new;
2824 std::map<int,int> bv_new;
2825 std::map<int,int> sv_new;
2826 std::map<int,int> fv_new;
2836 for (
unsigned int i=0;
i< _output->
a.size();
i++) {
2840 for (
unsigned int j=0; j<aia->
a.size(); j++) {
2849 for (std::map<int,int>::iterator
i=iv_new.
begin();
i != iv_new.
end(); ++
i) {
2850 iva[(*i).second] = iv[(*i).first];
2855 for (std::map<int,int>::iterator
i=bv_new.
begin();
i != bv_new.
end(); ++
i) {
2856 bva[(*i).second] = bv[(*i).first];
2860 #ifdef GECODE_HAS_SET_VARS
2862 for (std::map<int,int>::iterator
i=sv_new.
begin();
i != sv_new.
end(); ++
i) {
2863 sva[(*i).second] = sv[(*i).first];
2868 #ifdef GECODE_HAS_FLOAT_VARS
2870 for (std::map<int,int>::iterator
i=fv_new.
begin();
i != fv_new.
end(); ++
i) {
2871 fva[(*i).second] = fv[(*i).first];
IntVarBranch INT_VAR_SIZE_MAX(BranchTbl tbl)
Select variable with largest domain size.
struct Gecode::@602::NNF::@65::@66 b
For binary nodes (and, or, eqv)
Which integer or Boolean variable to select for branching.
An inspector for printing simple text output.
bool fail
Whether brancher should fail.
IntVarBranch INT_VAR_ACTION_MAX(double d, BranchTbl tbl)
Select variable with highest action with decay factor d.
bool isSetVar(void)
Test if node is a set variable node.
IntArgs arg2intargs(AST::Node *arg, int offset=0)
Convert arg (array of integers) to IntArgs.
A node in a FlatZinc abstract syntax tree.
void post(FlatZincSpace &s, const ConExpr &ce)
Post constraint specified by ce.
FZPrintingComparator(const Printer &p0)
Constructor.
bool l
Whether to try the lower or upper half first.
bool isArray(void)
Test if node is an array node.
void compare(Comparator *c)
Add comparator.
Post propagator for SetVar x
SetVarBranch SET_VAR_ACTION_MIN(double d, BranchTbl tbl)
Exception signaling type error
bool isIntVar(void)
Test if node is an integer variable node.
BoolValBranch bool_valsel
const Gecode::FloatNum step
FloatVarArgs arg2floatvarargs(AST::Node *arg, int offset=0)
Convert n to FloatVarArgs.
Option< std::pair< double, double > > domain
TupleSet & add(const IntArgs &t)
Add tuple t to tuple set.
std::string what(void) const
BoolVar arg2BoolVar(AST::Node *n)
Convert n to BoolVar.
BoolAssign BOOL_ASSIGN_RND(Rnd r)
Select random value.
void shrinkArrays(Printer &p)
Remove all variables not needed for output.
BoolAssign BOOL_ASSIGN_MIN(void)
Select smallest value.
Gecode::SetVarArray sv_aux
The introduced set variables.
std::unordered_set< TupleSet > TupleSetSet
Hash table of tuple sets.
bool hasAtom(const std::string &id)
Test if node has atom with id.
size_t operator()(const Gecode::SharedArray< int > &x) const
Return hash key for x.
Combine variable selection criteria for tie-breaking.
IntVarBranch INT_VAR_RND(Rnd r)
Select random variable (uniform distribution, for tie breaking)
void put(unsigned int i)
Add i to the contents.
Choice(const Brancher &b, bool fail0)
Initialize choice for brancher b.
SetLit * getSet(void)
Cast this node to a set literal node.
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.
void max(Home home, FloatVar x0, FloatVar x1, FloatVar x2)
Post propagator for .
Abstract base class for comparators.
Which values to select for branching first.
FlatZincSpaceInitData(void)
Initialize.
DFASet dfaSet
Hash table of DFAs.
IntVarBranch INT_VAR_NONE(void)
Select first unassigned variable.
Depth-first branch-and-bound search engine.
virtual void inspect(const Space &node)
Use the print method of the template class S to print a space.
void click(Inspector *i)
Add inspector that reacts on node double clicks.
void printBoolVar(std::ostream &os, const std::string name, const BoolVar &b)
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.
Output support class for FlatZinc interpreter.
A space that can be initialized with a FlatZinc model.
TieBreak< BoolVarBranch > ann2bvarsel(AST::Node *ann, Rnd rnd, double decay)
int boolVarCount
Number of Boolean variables.
IntVarBranch INT_VAR_MIN_MIN(BranchTbl tbl)
Select variable with smallest min.
virtual const char * what(void) const
Return information.
T * dfs(T *s, const Search::Options &o)
Invoke depth-first search engine for subclass T of space s with options o.
Passing integer variables.
unsigned int size(I &i)
Size of all ranges of range iterator i.
std::vector< bool > sv_introduced
Indicates whether a set variable is introduced by mzn2fzn.
unsigned long int fail
Number of failed nodes in search tree.
static const IntSet empty
Empty set.
Array * getArgs(unsigned int n)
FloatVarBranch FLOAT_VAR_AFC_MAX(double d, BranchTbl tbl)
Select variable with largest accumulated failure count with decay factor d.
void postConstraints(std::vector< ConExpr * > &ces)
Post a constraint specified by ce.
void minimize(int var, bool isInt, AST::Array *annotation)
Post that integer variable var should be minimized.
Gecode::BoolVarArray bv
The Boolean variables.
const int min
Smallest allowed integer in integer set.
Call * getCall(void)
Return function call.
void branch(Home home, const IntVarArgs &x, const BoolVarArgs &y, IntBoolVarBranch vars, IntValBranch vals)
Branch function for integer and Boolean variables.
Which values to select for branching first.
unsigned int size(Space &home) const
Return number of propagators in a group.
size_t operator()(const Gecode::DFA &d) const
Return hash key for d.
void flattenAnnotations(AST::Array *ann, std::vector< AST::Node * > &out)
Meth _method
Whether to solve as satisfaction or optimization problem.
double stop(void)
Get time since start of timer.
IntValBranch INT_VAL_MED(void)
Select greatest value not greater than the median.
TieBreak< IntVarBranch > int_varsel
virtual void finalize(void)
Finalize when Gist exits.
void newIntVar(IntVarSpec *vs)
Create new integer variable from specification.
int getBoolVar(void)
Cast this node to a Boolean variable node.
virtual void compare(const Space &s0, const Space &s1)=0
Call-back function.
bool isBoolVar(void)
Test if node is a Boolean variable node.
SetValBranch SET_VAL_MIN_EXC(void)
T * alloc(long unsigned int n)
Allocate block of n objects of type T from region.
void init(int intVars, int boolVars, int setVars, int floatVars)
Initialize space with given number of variables.
SharedHandle::Object * object(void) const
Access to the shared object.
Gecode::IntVarArray iv
The integer variables.
BoolVarBranch BOOL_VAR_ACTION_MAX(double d, BranchTbl tbl)
Select variable with highest action with decay factor d.
Meth method(void) const
Return whether to solve a satisfaction or optimization problem.
FloatVarBranch FLOAT_VAR_NONE(void)
Select first unassigned variable.
virtual void print(std::ostream &)=0
Output string representation.
const FloatNum min
Smallest allowed float value.
FloatValBranch FLOAT_VAL_SPLIT_MAX(void)
Select values greater than mean of smallest and largest value.
virtual size_t dispose(Space &)
Delete brancher and return its size.
SetVarBranch SET_VAR_MIN_MIN(BranchTbl tbl)
Abstract base class for inspectors.
IntPropLevel
Propagation levels for integer propagators.
Which values to select for branching first.
bool isInt(int &i)
Test if node is int, if yes set i to the value.
IntSharedArray arg2intsharedarray(AST::Node *arg, int offset=0)
Convert arg (array of integers) to IntSharedArray.
iterator end(void)
Return an iterator past the end of the array.
Base-class for both propagators and branchers.
IntValBranch INT_VAL_MIN(void)
Select smallest value.
bool optVarIsInt(void) const
Return whether variable used for optimization is integer (or float)
Depth-first search engine.
bool isString(void)
Test if node is a string node.
int getIntVar(void)
Cast this node to an integer variable node.
bool isSet(void)
Test if node is a set literal node.
TupleSet arg2tupleset(const IntArgs &a, int noOfVars)
Convert a to TupleSet.
#define GECODE_HAS_FLOAT_VARS
SetVarBranch SET_VAR_NONE(void)
virtual Gecode::Space * copy(void)
Copy function.
BoolValBranch BOOL_VAL_RND(Rnd r)
Select random value.
bool assigned(void) const
Test whether view is assigned.
FloatVarBranch FLOAT_VAR_SIZE_MIN(BranchTbl tbl)
Select variable with smallest domain size.
std::vector< bool > iv_introduced
Indicates whether an integer variable is introduced by mzn2fzn.
static void explore(S *root, const FlatZincOptions &opt, Gist::Inspector *i, Gist::Comparator *c)
TupleSetSet tupleSetSet
Hash table of tuple sets.
SetVarBranch SET_VAR_AFC_SIZE_MAX(double d, BranchTbl tbl)
virtual bool status(const Space &_home) const
Check status of brancher, return true if alternatives left.
static void installCtrlHandler(bool install, bool force=false)
Install handler for catching Ctrl-C.
SetVarBranch SET_VAR_AFC_SIZE_MIN(double d, BranchTbl tbl)
SetVarBranch SET_VAR_AFC_MIN(double d, BranchTbl tbl)
Restart with Luby sequence.
SetVarBranch SET_VAR_AFC_MAX(double d, BranchTbl tbl)
void newBoolVar(BoolVarSpec *vs)
Create new Boolean variable from specification.
unsigned long int depth
Maximum depth of search stack.
bool isBool(void)
Test if node is a Boolean node.
T * alloc(long unsigned int n)
Allocate block of n objects of type T from heap.
int size(void) const
Return size of array (number of elements)
Restart with linear sequence.
void printFloatVar(std::ostream &os, const std::string name, const Float::FloatView &f)
int optVar(void) const
Return index of variable used for optimization.
bool isFloatVar(void)
Test if node is a float variable node.
Gecode::FloatVarArray fv
The float variables.
bool assigned(void) const
Test if all variables are assigned.
Options for running FlatZinc models
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.
int dfs(Space *root, const Gist::Options &opt)
Create a new stand-alone Gist for root.
IntBoolVarBranch INTBOOL_VAR_AFC_SIZE_MAX(double d=1.0)
Select variable with largest accumulated failure count divided by domain size.
Base class for variables.
struct Gecode::Space::@61::@63 c
Data available only during copying.
Gecode toplevel namespace
SetValBranch SET_VAL_MAX_INC(void)
unsigned long int node
Number of nodes expanded.
void newSetVar(SetVarSpec *vs)
Create new set variable from specification.
Specification for integer variables.
TieBreak< FloatVarBranch > ann2fvarsel(AST::Node *ann, Rnd rnd, double decay)
Space * clone(CloneStatistics &stat=unused_clone) const
Clone space.
FlatZincGetInfo(const Printer &printer)
int _optVar
Index of the variable to optimize.
Node representing an atom
IntValBranch ann2ivalsel(AST::Node *ann, std::string &r0, std::string &r1, Rnd rnd)
Restart with geometric sequence.
virtual ExecStatus commit(Space &, const Gecode::Choice &c, unsigned int)
Perform commit for choice c.
bool done
Flag whether brancher is done.
FloatVarBranch FLOAT_VAR_MAX_MAX(BranchTbl tbl)
Select variable with largest max.
IntVar arg2IntVar(AST::Node *n)
Convert n to IntVar.
unsigned int a_d
Create a clone during recomputation if distance is greater than a_d (adaptive distance)
const int max
Largest allowed integer in integer set.
IntSharedArray arg2boolsharedarray(AST::Node *arg, int offset=0)
Convert arg (array of integers) to IntSharedArray.
bool alias
Whether the variable aliases another variable.
Float view for float variables.
SetVar arg2SetVar(AST::Node *n)
Convert n to SetVar.
Option< AST::SetLit * > domain
DFA getSharedDFA(DFA &a)
Share DFA a if possible.
struct Gecode::@602::NNF::@65::@67 a
For atomic nodes.
Print statistics for script.
Node * x
Pointer to corresponding Boolean expression node.
Argument array for non-primitive types.
Which values to select for assignment.
BoolVarArgs arg2boolvarargs(AST::Node *arg, int offset=0, int siv=-1)
Convert arg to BoolVarArgs.
virtual std::string getInfo(const Space &space) const
Return info for a space.
void finalize(void)
Finalize tuple set.
static PropagatorGroup all
Group of all propagators.
struct Gecode::Space::@61::@62 p
Data only available during propagation or branching.
Base-class for branchers.
Registry & registry(void)
Return global registry object.
void varValPrintF(const Space &home, const Brancher &b, unsigned int a, FloatVar, int i, const FloatNumBranch &nl, std::ostream &o)
Passing Boolean variables.
Home class for posting propagators
Gecode::BoolVarArray bv_aux
The introduced Boolean variables.
FloatValBranch FLOAT_VAL_SPLIT_MIN(void)
Select values not greater than mean of smallest and largest value.
IntValBranch INT_VALUES_MIN(void)
Try all values starting from smallest.
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.
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.
void print(std::ostream &out, const Gecode::IntVarArray &iv, const Gecode::BoolVarArray &bv, const Gecode::SetVarArray &sv, const Gecode::FloatVarArray &fv) const
SetValBranch ann2svalsel(AST::Node *ann, std::string r0, std::string r1, Rnd rnd)
IntSet vs2is(IntVarSpec *vs)
Specification for Boolean variables.
void createBranchers(Printer &p, AST::Node *ann, FlatZincOptions &opt, bool ignoreUnknown, std::ostream &err=std::cerr)
Create branchers corresponding to the solve item annotations.
FZPrintingInspector(const Printer &p0)
Constructor.
Array * getArray(void)
Cast this node to an array node.
BoolVarBranch BOOL_VAR_DEGREE_MAX(BranchTbl tbl)
Select variable with largest degree.
IntVarBranch INT_VAR_REGRET_MIN_MAX(BranchTbl tbl)
Select variable with largest min-regret.
#define GECODE_HAS_SET_VARS
Specification for floating point variables.
void dom(Home home, FloatVar x, FloatVal n)
Propagates .
Abstract representation of a constraint.
Post propagator for SetVar SetOpType SetVar SetRelType r
double FloatNum
Floating point number base type.
Boolean integer variables.
Domain propagation Options: basic versus advanced propagation.
virtual void constrain(const Space &s)
Implement optimization.
class Gecode::Gist::Options::_I inspect
SetValBranch SET_VAL_MIN_INC(void)
void sort(TaskViewArray< TaskView > &t)
Sort task view array t according to sto and inc (increasing or decreasing)
Traits class for search engines.
virtual Choice * choice(const Space &, Archive &e)
Return choice.
int getSetVar(void)
Cast this node to a set variable node.
void newFloatVar(FloatVarSpec *vs)
Create new float variable from specification.
size_t operator()(const Gecode::TupleSet &x) const
Return hash key for x.
unsigned int id(void) const
Return a unique id for the group.
Value description class for branching.
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)
FloatNum n
The middle value for branching.
Restart with constant sequence.
unsigned int c_d
Create a clone after every c_d commits (commit distance)
void assign(Home home, const FloatVarArgs &x, FloatVarBranch vars, FloatAssign vals, FloatBranchFilter bf, FloatVarValPrint vvp)
Assign all x with variable selection vars and value selection vals.
FloatVarBranch FLOAT_VAR_AFC_MIN(double d, BranchTbl tbl)
Select variable with smallest accumulated failure count with decay factor d.
const int max
Largest allowed integer value.
IntVarBranch INT_VAR_DEGREE_MAX(BranchTbl tbl)
Select variable with largest degree.
IntSet arg2intset(AST::Node *n)
Convert n to IntSet.
IntAssign INT_ASSIGN_MAX(void)
Select largest value.
bool _optVarIsInt
Whether variable to optimize is integer (or float)
Gecode::FloatVarArray fv_aux
The introduced float variables.
BoolValBranch BOOL_VAL_MAX(void)
Select largest value.
FlatZincSpaceInitData * _initData
Initialisation data (only used for posting constraints)
virtual bool slave(const MetaInfo &mi)
Slave function for restarts.
virtual size_t size(void) const
Report size occupied.
virtual void archive(Archive &e) const
Archive into e.
void addSetVarName(const std::string &n)
IntAssign INT_ASSIGN_RND(Rnd r)
Select random value.
SetVarBranch SET_VAR_ACTION_MAX(double d, BranchTbl tbl)
bool funcDep
Whether the variable functionally depends on another variable.
BoolValBranch BOOL_VAL_MIN(void)
Select smallest value.
virtual Actor * copy(Space &home)
Copy brancher.
Class represeting a set of tuples.
static void explore(S *root, const FlatZincOptions &opt, Gist::Inspector *i, Gist::Comparator *c)
BoolVarBranch BOOL_VAR_AFC_MIN(double d, BranchTbl tbl)
Select variable with smallest accumulated failure count with decay factor d.
Specification for set variables.
IntVarArgs arg2intvarargs(AST::Node *arg, int offset=0)
Convert arg to IntVarArgs.
FloatVarBranch FLOAT_VAR_MIN_MIN(BranchTbl tbl)
Select variable with smallest min.
void abs(Home home, FloatVar x0, FloatVar x1)
Post propagator for .
void print(std::ostream &out, const Printer &p) const
Produce output on out using p.
std::unordered_set< SharedArray< int > > IntSharedArraySet
Hash table of shared integer arrays.
int explore(Space *root, bool bab, const Options &opt)
Create a new stand-alone Gist for root using bab.
BoolVarBranch BOOL_VAR_AFC_MAX(double d, BranchTbl tbl)
Select variable with largest accumulated failure count with decay factor d.
IntVarBranch INT_VAR_ACTION_SIZE_MIN(double d, BranchTbl tbl)
Select variable with smallest action divided by domain size with decay factor d.
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.
Heap heap
The single global heap.
Choice that only signals failure or success
void cmb_hash(std::size_t &seed, const T h)
Combine hash value h into seed.
TieBreak< BoolVarBranch > bool_varsel
Search::Cutoff * createCutoff(const Options &o)
Create cutoff object from options.
Exception class for FlatZinc errors
void fail(void)
Fail space.
FlatZincSpace(FlatZincSpace &)
Copy constructor.
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.
IntVarBranch INT_VAR_SIZE_MIN(BranchTbl tbl)
Select variable with smallest domain size.
FloatVarBranch FLOAT_VAR_SIZE_MAX(BranchTbl tbl)
Select variable with largest domain size.
SetVarBranch SET_VAR_SIZE_MAX(BranchTbl tbl)
bool assigned
Whether the variable is assigned.
Deterministic finite automaton (DFA)
unsigned long int propagate
Number of propagator executions.
void rel(Home home, FloatVar x0, FloatRelType frt, FloatVal n)
Propagates .
Rnd defrnd(0)
Uninitialized default random number generator.
void printIntVar(std::ostream &os, const std::string name, const Int::IntView &x)
static Search::Stop * create(unsigned int node, unsigned int fail, unsigned int time, bool intr)
Create appropriate stop-object.
AST::Array * _solveAnnotations
Annotations on the solve item.
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
SetVarBranch SET_VAR_RND(Rnd r)
int size(void) const
Return size of array (number of elements)
SetVarBranch SET_VAR_ACTION_SIZE_MAX(double d, BranchTbl tbl)
Simple propagation levels.
bool needAuxVars
Whether the introduced variables still need to be copied.
AuxVarBrancher(Space &home, AuxVarBrancher &b)
Copy constructor.
Run script with CP-profiler.
Branching on the introduced variables.
SharedArray< int > IntSharedArray
Arrays of integers that can be shared among several element constraints.
BoolValBranch ann2bvalsel(AST::Node *ann, std::string &r0, std::string &r1, Rnd rnd)
AST::Array * solveAnnotations(void) const
Return the solve item annotations.
IntVarBranch INT_VAR_MAX_MAX(BranchTbl tbl)
Select variable with largest max.
void start(void)
Start timer.
void free(T *b, long unsigned int n)
Delete n objects starting at b.
IntAssign INT_ASSIGN_MED(void)
Select greatest value not greater than the median.
void aliasBool2Int(int iv, int bv)
Link integer variable iv to Boolean variable bv.
Statistics for execution of status
Integer view for integer variables.
IntVarBranch INT_VAR_AFC_MIN(double d, BranchTbl tbl)
Select variable with smallest accumulated failure count with decay factor d.
BoolAssign BOOL_ASSIGN_MAX(void)
Select largest value.
void addBoolVarName(const std::string &n)
BoolVarBranch BOOL_VAR_ACTION_MIN(double d, BranchTbl tbl)
Select variable with lowest action with decay factor d.
SetVarBranch ann2svarsel(AST::Node *ann, Rnd rnd, double decay)
FloatVarBranch FLOAT_VAR_ACTION_MIN(double d, BranchTbl tbl)
Select variable with lowest action with decay factor d.
void run(std::ostream &out, const Printer &p, const FlatZincOptions &opt, Gecode::Support::Timer &t_total)
Run the search.
FloatVarBranch FLOAT_VAR_DEGREE_MAX(BranchTbl tbl)
Select variable with largest degree.
int getFloatVar(void)
Cast this node to a Float variable node.
void varValPrint(const Space &home, const Brancher &b, unsigned int a, Var, int i, const int &n, std::ostream &o)
void maximize(int var, bool isInt, AST::Array *annotation)
Post that integer variable var should be maximized.
SetVarBranch SET_VAR_MAX_MAX(BranchTbl tbl)
SetValBranch SET_VAL_MAX_EXC(void)
int setVarCount
Number of set variables.
Node representing a function call
int intVarCount
Number of integer variables.
const int min
Smallest allowed integer value.
int bab(Space *root, const Gist::Options &opt)
Create a new stand-alone Gist for branch-and-bound search of root.
~FlatZincSpace(void)
Destructor.
Option< AST::SetLit * > domain
int vs2bsl(BoolVarSpec *bs)
IntVarBranch INT_VAR_ACTION_SIZE_MAX(double d, BranchTbl tbl)
Select variable with largest action divided by domain size with decay factor d.
void solve(AST::Array *annotation)
Post the solve item.
IntValBranch INT_VAL_SPLIT_MIN(void)
Select values not greater than mean of smallest and largest value.
void addFloatVarName(const std::string &n)
SetVarBranch SET_VAR_SIZE_MIN(BranchTbl tbl)
virtual void print(const Space &, const Gecode::Choice &c, unsigned int, std::ostream &o) const
Print explanation.
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.
The Gecode Interactive Search Tool.
int size(void) const
Return number of elements.
IntAssign ann2asnivalsel(AST::Node *ann, Rnd rnd)
void min(Home home, FloatVar x0, FloatVar x1, FloatVar x2)
Post propagator for .
Gecode::SetVarArray sv
The set variables.
Gecode::FloatNum step
Step by which a next solution has to have lower cost.
Option< AST::SetLit * > upperBound
Post propagator for f(x \diamond_{\mathit{op}} y) \sim_r z \f$ void rel(Home home
Which values to select for assignment.
unsigned long int restart
Number of restarts.
FloatVarBranch FLOAT_VAR_ACTION_SIZE_MIN(double d, BranchTbl tbl)
Select variable with smallest action divided by domain size with decay factor d.
FloatValBranch float_valsel
Rnd _random
Random number generator.
Gecode::FloatVal c(-8, 8)
Gecode::IntVarArray iv_aux
The introduced integer variables.
void shrinkArrays(Space &home, int &optVar, bool optVarIsInt, Gecode::IntVarArray &iv, Gecode::BoolVarArray &bv, Gecode::SetVarArray &sv, Gecode::FloatVarArray &fv)
BoolAssign ann2asnbvalsel(AST::Node *ann, Rnd rnd)
TieBreak< IntVarBranch > ann2ivarsel(AST::Node *ann, Rnd rnd, double decay)
FloatValBranch ann2fvalsel(AST::Node *ann, std::string r0, std::string r1)
IntSharedArraySet intSharedArraySet
Hash table of shared integer arrays.
virtual Choice * choice(Space &home)
Return choice.
int n
Number of negative literals for node type.
Gecode::IntVarArray iv_lns
The integer variables used in LNS.
FloatVar arg2FloatVar(AST::Node *n)
Convert n to FloatVar.
Choice for performing commit
Execution has resulted in failure.
IntSharedArray _lnsInitialSolution
Initial solution to start the LNS (or NULL for no LNS)
int vs2bsh(BoolVarSpec *bs)
std::unordered_set< DFA > DFASet
Hash table of DFAs.
int * iv_boolalias
Indicates whether an integer variable aliases a Boolean variable.
int getInt(void)
Cast this node to an integer node.
void addIntVarName(const std::string &n)
Passing integer arguments.
CompareStatus compare(I &i, J &j)
Check whether range iterator i is a subset of j, or whether they are disjoint.
FloatValArgs arg2floatargs(AST::Node *arg, int offset=0)
Convert n to FloatValArgs.
const Val & some(void) const
SetVarArgs arg2setvarargs(AST::Node *arg, int offset=0, int doffset=0, const IntSet &od=IntSet::empty)
Convert n to SetVarArgs.
SetVarBranch SET_VAR_ACTION_SIZE_MIN(double d, BranchTbl tbl)
Gecode::IntArgs i({1, 2, 3, 4})
FloatVarBranch FLOAT_VAR_RND(Rnd r)
Select random variable (uniform distribution, for tie breaking)
IntArgs arg2boolargs(AST::Node *arg, int offset=0)
Convert arg (array of Booleans) to IntArgs.
std::string getString(void)
Cast this node to a string node.
bool getBool(void)
Cast this node to a Boolean node.
int p
Number of positive literals for node type.
unsigned int _lns
Percentage of variables to keep in LNS (or 0 for no LNS)
BoolVarBranch BOOL_VAR_NONE(void)
Select first unassigned variable.
IntSetArgs arg2intsetargs(AST::Node *arg, int offset=0)
Convert arg to IntSetArgs.
void init(AST::Array *output)
virtual void archive(Archive &e) const
Archive into e.
const FloatNum max
Largest allowed float value.
iterator begin(void)
Return an iterator at the beginning of the array.
virtual void compare(const Space &s0, const Space &s1)
Use the compare method of the template class S to compare two spaces.
IntValBranch INT_VAL_MAX(void)
Select largest value.
TieBreak< FloatVarBranch > float_varsel
BoolVarBranch BOOL_VAR_RND(Rnd r)
Select random variable (uniform distribution, for tie breaking)
FloatVarBranch FLOAT_VAR_ACTION_SIZE_MAX(double d, BranchTbl tbl)
Select variable with largest action divided by domain size with decay factor d.
std::string getDomains(const Printer &p) const
Get string representing the domains of variables (for cpprofiler)
void update(Space &home, VarArray< Var > &a)
Update array to be a clone of array a.
int floatVarCount
Number of float variables.
unsigned int seed
The random seed to be used.
Which variable to select for branching.
Class to send solution information to CPProfiler.
IntValBranch INT_VAL_SPLIT_MAX(void)
Select values greater than mean of smallest and largest value.
An window for simple text output.
Exception: Base-class for exceptions
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.
bool introduced
Whether the variable was introduced in the mzn2fzn translation.
void finalize(void)
Clean up when Gist exits.
IntVarBranch INT_VAR_AFC_MAX(double d, BranchTbl tbl)
Select variable with largest accumulated failure count with decay factor d.
Which values to select for branching first.
IntValBranch INT_VAL_RND(Rnd r)
Select random value.
IntAssign INT_ASSIGN_MIN(void)
Select smallest value.
FloatVarBranch FLOAT_VAR_ACTION_MAX(double d, BranchTbl tbl)
Select variable with highest action with decay factor d.
IntVarBranch INT_VAR_ACTION_MIN(double d, BranchTbl tbl)
Select variable with lowest action with decay factor d.