Generated on for Gecode by doxygen 1.17.0
options.cpp
Go to the documentation of this file.
1/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2/*
3 * Main authors:
4 * Christian Schulte <schulte@gecode.dev>
5 *
6 * Copyright:
7 * Christian Schulte, 2004
8 *
9 * This file is part of Gecode, the generic constraint
10 * development environment:
11 * http://www.gecode.dev
12 *
13 *
14 * Permission is hereby granted, free of charge, to any person obtaining
15 * a copy of this software and associated documentation files (the
16 * "Software"), to deal in the Software without restriction, including
17 * without limitation the rights to use, copy, modify, merge, publish,
18 * distribute, sublicense, and/or sell copies of the Software, and to
19 * permit persons to whom the Software is furnished to do so, subject to
20 * the following conditions:
21 *
22 * The above copyright notice and this permission notice shall be
23 * included in all copies or substantial portions of the Software.
24 *
25 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
28 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
29 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
30 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
31 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 *
33 */
34
35#include <gecode/driver.hh>
36
37#include <sys/stat.h>
38
39#include <fstream>
40#include <iostream>
41#include <iomanip>
42
43#include <cctype>
44#include <cstdlib>
45#include <cstring>
46
47namespace Gecode {
48
49 namespace Driver {
50
51 /*
52 * Option baseclass
53 *
54 */
55 char*
56 BaseOption::strdup(const char* s) {
57 if (s == nullptr)
58 return nullptr;
59 size_t l = strlen(s) + 1;
60 char* d = static_cast<char*>(heap.ralloc(l));
61 (void) memcpy(d,s,l);
62 return d;
63 }
64
65 char*
66 BaseOption::stredup(const char* s) {
67 if (s == nullptr)
68 return nullptr;
69 size_t l = strlen(s) + 1;
70 char* d = static_cast<char*>(heap.ralloc(l+1));
71 d[0] = '-';
72 (void) memcpy(d+1,s,l);
73 return d;
74 }
75
76 void
77 BaseOption::strdel(const char* s) {
78 if (s == nullptr)
79 return;
80 heap.rfree(const_cast<char*>(s));
81 }
82
83 char*
84 BaseOption::argument(int argc, char* argv[]) const {
85 if (argc < 2)
86 return nullptr;
87 const char* s = argv[1];
88 if (s[0] == '-') {
89 s++;
90 if (s[0] == '-')
91 s++;
92 } else {
93 return nullptr;
94 }
95 if (strcmp(s,eopt))
96 return nullptr;
97 if (argc == 2) {
98 std::cerr << "Missing argument for option \"" << iopt << "\""
99 << std::endl;
100 exit(EXIT_FAILURE);
101 }
102 return argv[2];
103 }
104
105 BaseOption::BaseOption(const char* o, const char* e)
106 : eopt(strdup(o)), iopt(stredup(o)), exp(strdup(e)) {}
107
109 strdel(eopt);
110 strdel(iopt);
111 strdel(exp);
112 }
113
114
115 StringValueOption::StringValueOption(const char* o, const char* e,
116 const char* v)
117 : BaseOption(o,e), cur(strdup(v)) {}
118 void
120 strdel(cur);
121 cur = strdup(v);
122 }
123 int
124 StringValueOption::parse(int argc, char* argv[]) {
125 if (char* a = argument(argc,argv)) {
126 cur = strdup(a);
127 return 2;
128 }
129 return 0;
130 }
131 void
133 std::cerr << '\t' << iopt << " (string) default: "
134 << ((cur == nullptr) ? "NONE" : cur) << std::endl
135 << "\t\t" << exp << std::endl;
136 }
140
141
142 StringListOption::StringListOption(const char* o, const char* e)
143 : StringValueOption(o,e) {}
144 int
145 StringListOption::parse(int argc, char* argv[]) {
146 if (char* a = argument(argc,argv)) {
147 if (cur == nullptr) {
148 cur = strdup(a);
149 } else {
150 std::string v = std::string(cur) + "," + a;
151 strdel(cur);
152 cur = strdup(v.c_str());
153 }
154 return 2;
155 }
156 return 0;
157 }
158
159
160
161 void
162 StringOption::add(int v, const char* o, const char* h) {
163 Value* n = new Value;
164 n->val = v;
165 n->opt = strdup(o);
166 n->help = strdup(h);
167 n->next = nullptr;
168 if (fst == nullptr) {
169 fst = n;
170 } else {
171 lst->next = n;
172 }
173 lst = n;
174 }
175 int
176 StringOption::parse(int argc, char* argv[]) {
177 if (char* a = argument(argc,argv)) {
178 for (Value* v = fst; v != nullptr; v = v->next)
179 if (!strcmp(a,v->opt)) {
180 cur = v->val;
181 return 2;
182 }
183 std::cerr << "Wrong argument \"" << a
184 << "\" for option \"" << iopt << "\""
185 << std::endl;
186 exit(EXIT_FAILURE);
187 }
188 return 0;
189 }
190 void
192 if (fst == nullptr)
193 return;
194 std::cerr << '\t' << iopt << " (";
195 const char* d = nullptr;
196 for (Value* v = fst; v != nullptr; v = v->next) {
197 std::cerr << v->opt << ((v->next != nullptr) ? ", " : "");
198 if (v->val == cur)
199 d = v->opt;
200 }
201 std::cerr << ")";
202 if (d != nullptr)
203 std::cerr << " default: " << d;
204 std::cerr << std::endl << "\t\t" << exp << std::endl;
205 for (Value* v = fst; v != nullptr; v = v->next)
206 if (v->help != nullptr)
207 std::cerr << "\t\t " << v->opt << ": " << v->help << std::endl;
208 }
209
211 Value* v = fst;
212 while (v != nullptr) {
213 strdel(v->opt);
214 strdel(v->help);
215 Value* n = v->next;
216 delete v;
217 v = n;
218 }
219 }
220
221
222 int
223 IntOption::parse(int argc, char* argv[]) {
224 if (char* a = argument(argc,argv)) {
225 cur = atoi(a);
226 return 2;
227 }
228 return 0;
229 }
230
231 void
233 std::cerr << '\t' << iopt << " (int) default: " << cur << std::endl
234 << "\t\t" << exp << std::endl;
235 }
236
237
238 int
239 UnsignedIntOption::parse(int argc, char* argv[]) {
240 if (char* a = argument(argc,argv)) {
241 cur = static_cast<unsigned int>(atoi(a));
242 return 2;
243 }
244 return 0;
245 }
246
247 void
249 std::cerr << '\t' << iopt << " (unsigned int) default: "
250 << cur << std::endl
251 << "\t\t" << exp << std::endl;
252 }
253
254
255 int
256 UnsignedLongLongIntOption::parse(int argc, char* argv[]) {
257 if (char* a = argument(argc,argv)) {
258 cur = static_cast<unsigned int>(atoll(a));
259 return 2;
260 }
261 return 0;
262 }
263
264 void
266 std::cerr << '\t' << iopt << " (unsigned long long int) default: "
267 << cur << std::endl
268 << "\t\t" << exp << std::endl;
269 }
270
271
272 int
273 DoubleOption::parse(int argc, char* argv[]) {
274 if (char* a = argument(argc,argv)) {
275 cur = atof(a);
276 return 2;
277 }
278 return 0;
279 }
280
281 void
283 using namespace std;
284 cerr << '\t' << iopt << " (double) default: " << cur << endl
285 << "\t\t" << exp << endl;
286 }
287
288
289 int
290 BoolOption::parse(int argc, char* argv[]) {
291 if (argc < 2)
292 return 0;
293 const char* s = argv[1];
294 if (s[0] == '-') {
295 s++;
296 if (s[0] == '-')
297 s++;
298 } else {
299 return 0;
300 }
301 if (strcmp(s,eopt))
302 return 0;
303 if (argc == 2) {
304 // Option without argument
305 cur = true;
306 return 1;
307 } else if (!strcmp(argv[2],"true") || !strcmp(argv[2],"1")) {
308 cur = true;
309 return 2;
310 } else if (!strcmp(argv[2],"false") || !strcmp(argv[2],"0")) {
311 cur = false;
312 return 2;
313 } else {
314 // Option without argument
315 cur = true;
316 return 1;
317 }
318 return 0;
319 }
320
321 void
323 using namespace std;
324 cerr << '\t' << iopt << " (optional: false, 0, true, 1) default: "
325 << (cur ? "true" : "false") << endl
326 << "\t\t" << exp << endl;
327 }
328
329 /*
330 * Integer propagation level option
331 *
332 */
334 : BaseOption("ipl","integer propagation level (comma-separated list)"),
335 cur(ipl) {}
336
337 int
338 IplOption::parse(int argc, char* argv[]) {
339 if (char* a = argument(argc,argv)) {
340 int b = IPL_DEF;
341 int m = IPL_DEF;
342 do {
343 // Search for a comma
344 char* c = a;
345 while ((*c != ',') && (*c != 0))
346 c++;
347 unsigned int e = static_cast<unsigned int>(c-a);
348 if (!strncmp("def",a,e)) { b = IPL_DEF; }
349 else if (!strncmp("val",a,e)) { b = IPL_VAL; }
350 else if (!strncmp("bnd",a,e)) { b = IPL_BND; }
351 else if (!strncmp("dom",a,e)) { b = IPL_DOM; }
352 else if (!strncmp("basic",a,e)) { m |= IPL_BASIC; }
353 else if (!strncmp("advanced",a,e)) { m |= IPL_ADVANCED; }
354 else if (!strncmp("full",a,e)) { m |= IPL_FULL; }
355 else {
356 std::cerr << "Wrong argument \"" << a
357 << "\" for option \"" << iopt << "\""
358 << std::endl;
359 exit(EXIT_FAILURE);
360 }
361
362 if (*c == ',') a = c+1; else a = c;
363
364 } while (*a != 0);
365
366 cur = static_cast<IntPropLevel>(b | m);
367 return 2;
368 }
369 return 0;
370 }
371
372 void
374 using namespace std;
375 cerr << '\t' << iopt
376 << " (def,val,bnd,dom,basic,advanced,full)" << endl
377 << "\t\tdefault: ";
378 switch (vbd(cur)) {
379 case IPL_DEF: cerr << "def"; break;
380 case IPL_VAL: cerr << "val"; break;
381 case IPL_BND: cerr << "bnd"; break;
382 case IPL_DOM: cerr << "dom"; break;
383 default: GECODE_NEVER;
384 }
385 if ((cur & IPL_FULL) == IPL_FULL)
386 cerr << ",full";
387 else {
388 if (cur & IPL_BASIC) cerr << ",basic";
389 if (cur & IPL_ADVANCED) cerr << ",advanced";
390 }
391 cerr << endl << "\t\t" << exp << endl;
392 }
393
394
395 /*
396 * Trace flag option
397 *
398 */
400 : BaseOption("trace","trace flags (comma-separated list)"),
401 cur(f) {}
402
403 int
404 TraceOption::parse(int argc, char* argv[]) {
405 if (char* a = argument(argc,argv)) {
406 cur = 0;
407 do {
408 // Search for a comma
409 char* c = a;
410 while ((*c != ',') && (*c != 0))
411 c++;
412 unsigned int e = static_cast<unsigned int>(c-a);
413 if (!strncmp("init",a,e)) { cur |= TE_INIT; }
414 else if (!strncmp("prune",a,e)) { cur |= TE_PRUNE; }
415 else if (!strncmp("fix",a,e)) { cur |= TE_FIX; }
416 else if (!strncmp("fail",a,e)) { cur |= TE_FAIL; }
417 else if (!strncmp("done",a,e)) { cur |= TE_DONE ; }
418 else if (!strncmp("propagate",a,e)) { cur |= TE_PROPAGATE; }
419 else if (!strncmp("commit",a,e)) { cur |= TE_COMMIT; }
420 else if (!strncmp("post",a,e)) { cur |= TE_POST; }
421 else if (!strncmp("none",a,e) ||
422 !strncmp("false",a,e) ||
423 !strncmp("0",a,e)) { cur = 0; }
424 else if (!strncmp("all",a,e) ||
425 !strncmp("1",a,e)) { cur = (TE_INIT |
426 TE_PRUNE |
427 TE_FIX |
428 TE_FAIL |
429 TE_DONE |
431 TE_COMMIT |
432 TE_POST); }
433 else if (!strncmp("variable",a,e)) { cur = (TE_INIT |
434 TE_PRUNE |
435 TE_FIX |
436 TE_FAIL |
437 TE_DONE); }
438 else if (!strncmp("general",a,e)) { cur = (TE_PROPAGATE |
439 TE_COMMIT |
440 TE_POST); }
441 else {
442 std::cerr << "Wrong argument \"" << a
443 << "\" for option \"" << iopt << "\""
444 << std::endl;
445 exit(EXIT_FAILURE);
446 }
447
448 if (*c == ',') a = c+1; else a = c;
449
450 } while (*a != 0);
451
452 return 2;
453 }
454 return 0;
455 }
456
457 void
459 using namespace std;
460 cerr << '\t' << iopt
461 << " (init,prune,fix,fail,done,propagate,commit,post,none,all,variable,general)"
462 << " default: ";
463 if (cur == 0) {
464 cerr << "none";
465 } else if (cur == (TE_INIT | TE_PRUNE | TE_FIX | TE_FAIL | TE_DONE |
467 cerr << "all";
468 } else if (cur == (TE_INIT | TE_PRUNE | TE_FIX | TE_FAIL | TE_DONE)) {
469 cerr << "variable";
470 } else if (cur == (TE_PROPAGATE | TE_COMMIT | TE_POST)) {
471 cerr << "general";
472 } else {
473 int f = cur;
474 if ((f & TE_INIT) != 0) {
475 cerr << "init";
476 f -= TE_INIT;
477 if (f != 0) cerr << ',';
478 }
479 if ((f & TE_PRUNE) != 0) {
480 cerr << "prune";
481 f -= TE_PRUNE;
482 if (f != 0) cerr << ',';
483 }
484 if ((f & TE_FIX) != 0) {
485 cerr << "fix";
486 f -= TE_FIX;
487 if (f != 0) cerr << ',';
488 }
489 if ((f & TE_FAIL) != 0) {
490 cerr << "fail";
491 f -= TE_FAIL;
492 if (f != 0) cerr << ',';
493 }
494 if ((f & TE_DONE) != 0) {
495 cerr << "done";
496 f -= TE_DONE;
497 if (f != 0) cerr << ',';
498 }
499 if ((f & TE_PROPAGATE) != 0) {
500 cerr << "propagate";
501 f -= TE_PROPAGATE;
502 if (f != 0) cerr << ',';
503 }
504 if ((f & TE_COMMIT) != 0) {
505 cerr << "commit";
506 f -= TE_COMMIT;
507 if (f != 0) cerr << ',';
508 }
509 if ((f & TE_POST) != 0) {
510 cerr << "post";
511 }
512 }
513 cerr << endl << "\t\t" << exp << endl;
514 }
515
516
517 int ProfilerOption::parse(int argc, char* argv[]) {
518 if (char* a = argument(argc, argv)) {
519 char* sep = strchr(a, ',');
520 if (!sep) {
521 std::cerr << "Wrong argument \"" << a << "\" for option \"" << iopt << "\"" << std::endl;
522 exit(EXIT_FAILURE);
523 }
524 cur_execution_id = static_cast<unsigned int>(atoi(a));
525 cur_port = atoi(sep + 1);
526 return 2;
527 }
528 return 0;
529 }
530
531 void ProfilerOption::help(void) { std::cerr << '\t' << iopt << " (unsigned int,int) default: " << cur_port << "," << cur_execution_id << std::endl << "\t\t" << exp << std::endl; }
532
533
534 }
535
536 void
538 o.next = nullptr;
539 if (fst == nullptr) {
540 fst=&o;
541 } else {
542 lst->next=&o;
543 }
544 lst=&o;
545 }
547 : fst(nullptr), lst(nullptr),
548 _name(Driver::BaseOption::strdup(n)) {}
549
550 void
555
556 void
558 std::cerr << "Gecode configuration information:" << std::endl
559 << " - Version: " << GECODE_VERSION << std::endl
560 << " - Variable types: ";
561#ifdef GECODE_HAS_INT_VARS
562 std::cerr << "BoolVar IntVar ";
563#endif
564#ifdef GECODE_HAS_SET_VARS
565 std::cerr << "SetVar ";
566#endif
567#ifdef GECODE_HAS_FLOAT_VARS
568 std::cerr << "FloatVar "
569 << std::endl
570 << " - Trigonometric and transcendental float constraints: ";
571#ifdef GECODE_HAS_MPFR
572 std::cerr << "enabled";
573#else
574 std::cerr << "disabled";
575#endif
576#endif
577 std::cerr << std::endl;
578 std::cerr << " - Thread support: ";
579#ifdef GECODE_HAS_THREADS
580 if (Support::Thread::npu() == 1)
581 std::cerr << "enabled (1 processing unit)";
582 else
583 std::cerr << "enabled (" << Support::Thread::npu()
584 << " processing units)";
585#else
586 std::cerr << "disabled";
587#endif
588 std::cerr << std::endl
589 << " - Gist support: ";
590#ifdef GECODE_HAS_GIST
591 std::cerr << "enabled";
592#else
593 std::cerr << "disabled";
594#endif
595 std::cerr << std::endl
596 << " - CPProfiler support: ";
597#ifdef GECODE_HAS_CPPROFILER
598 std::cerr << "enabled";
599#else
600 std::cerr << "disabled";
601#endif
602 std::cerr << std::endl << std::endl
603 << "Options for " << name() << ":" << std::endl
604 << "\t-help, --help, -?" << std::endl
605 << "\t\tprint this help message" << std::endl;
606 for (Driver::BaseOption* o = fst; o != nullptr; o = o->next)
607 o->help();
608 }
609
610 void
611 BaseOptions::parse(int& argc, char* argv[]) {
612 int c = argc;
613 char** v = argv;
614 next:
615 for (Driver::BaseOption* o = fst; o != nullptr; o = o->next)
616 if (int a = o->parse(c,v)) {
617 c -= a; v += a;
618 goto next;
619 }
620 if (c >= 2) {
621 if (!strcmp(v[1],"-help") || !strcmp(v[1],"--help") ||
622 !strcmp(v[1],"-?")) {
623 help();
624 exit(EXIT_SUCCESS);
625 }
626 }
627 // Copy remaining arguments
628 argc = c;
629 for (int i=1; i<argc; i++)
630 argv[i] = v[i];
631 return;
632 }
633
634 namespace {
636 void
637 unrecognised(BaseOptions& o, const char* a) {
638 std::cerr << "Unrecognised argument \"" << a << "\"" << std::endl;
639 o.help();
640 exit(EXIT_FAILURE);
641 }
642 }
643
644 void
645 BaseOptions::parse(int& argc, char* argv[], bool strict) {
646 parse(argc,argv);
647 if (strict && (argc > 1))
648 unrecognised(*this,argv[1]);
649 }
650
654
655
656 Options::Options(const char* n)
657 : BaseOptions(n),
658
659 _model("model","model variants"),
660 _symmetry("symmetry","symmetry variants"),
661 _propagation("propagation","propagation variants"),
662 _branching("branching","branching variants"),
663 _decay("decay","decay factor",1.0),
664 _seed("seed","random number generator seed",1U),
665 _step("step","step distance for float optimization",0.0),
666
667 _search("search","search engine variants"),
668 _solutions("solutions","number of solutions (0 = all)",1),
669 _threads("threads","number of threads (0 = #processing units)",
670 Search::Config::threads),
671 _c_d("c-d","recomputation commit distance",Search::Config::c_d),
672 _a_d("a-d","recomputation adaptation distance",Search::Config::a_d),
673 _d_l("d-l","discrepancy limit for LDS",Search::Config::d_l),
674 _node("node","node cutoff (0 = none, solution mode)"),
675 _fail("fail","failure cutoff (0 = none, solution mode)"),
676 _time("time","time (in ms) cutoff (0 = none, solution mode)"),
677 _assets("assets","#portfolio assets (#engines)",0),
678 _slice("slice","portfolio slice (in #failures)",Search::Config::slice),
679 _restart("restart","restart sequence type",RM_NONE),
680 _r_base("restart-base","base for geometric restart sequence",
681 Search::Config::base),
682 _r_scale("restart-scale","scale factor for restart sequence",
683 Search::Config::slice),
684 _r_limit("restart-limit","restart cutoff (0 = none, solution mode)"),
685 _nogoods("nogoods","whether to use no-goods from restarts",false),
686 _nogoods_limit("nogoods-limit","depth limit for no-good extraction",
687 Search::Config::nogoods_limit),
688 _relax("relax","probability for relaxing variable", 0.0),
689 _interrupt("interrupt","whether to catch Ctrl-C (true) or not (false)",
690 true),
691
692#ifdef GECODE_HAS_EXPERIMENTAL
693 _guidance(nullptr),
694#endif
695 _mode("mode","how to execute script",SM_SOLUTION),
696 _samples("samples","how many samples (time mode)",1),
697 _iterations("iterations","iterations per sample (time mode)",1),
698 _print_last("print-last",
699 "whether to only print the last solution (solution mode)",
700 false),
701 _out_file("file-sol", "where to print solutions "
702 "(supports stdout, stdlog, stderr)","stdout"),
703 _log_file("file-stat", "where to print statistics "
704 "(supports stdout, stdlog, stderr)","stdout"),
705 _trace(0)
706
708 ,
709 _profiler("cp-profiler", "use this execution id and port (comma separated) with CP-profiler")
710#endif
711 {
712
713 _mode.add(SM_SOLUTION, "solution");
714 _mode.add(SM_TIME, "time");
715 _mode.add(SM_STAT, "stat");
716 _mode.add(SM_GIST, "gist");
717
718 _restart.add(RM_NONE,"none");
719 _restart.add(RM_CONSTANT,"constant");
720 _restart.add(RM_LINEAR,"linear");
721 _restart.add(RM_LUBY,"luby");
722 _restart.add(RM_GEOMETRIC,"geometric");
723
727 add(_d_l);
732 add(_relax);
735#ifdef GECODE_HAS_CPPROFILER
736 add(_profiler);
737#endif
738 }
739
740
742 : Options(e), _size(0) {}
743
744 void
747 std::cerr << "\t(unsigned int) default: " << size() << std::endl
748 << "\t\twhich version/size for script" << std::endl;
749 }
750
751 void
752 SizeOptions::parse(int& argc, char* argv[]) {
753 Options::parse(argc,argv);
754 if (argc < 2)
755 return;
756 size(static_cast<unsigned int>(atoi(argv[1])));
757 }
758
759 void
760 SizeOptions::parse(int& argc, char* argv[], bool strict) {
761 if (!strict) {
762 parse(argc,argv);
763 return;
764 }
765 Options::parse(argc,argv);
766 if (argc < 2)
767 return;
768 // The only remaining argument must be the size
769 const char* s = argv[1];
770 bool number = (*s != 0);
771 for (const char* c = s; *c != 0; c++)
772 if (!isdigit(static_cast<unsigned char>(*c)))
773 number = false;
774 if (!number)
775 unrecognised(*this,argv[1]);
776 if (argc > 2)
777 unrecognised(*this,argv[2]);
778 size(static_cast<unsigned int>(atoi(argv[1])));
779 }
780
781
782
784 : Options(e), _inst(nullptr), _spec(nullptr),
785 _spec_file("spec","file with a reader spec for instance files (default: the script's own spec)"),
786 _param("param","parameter for the reader spec (name=value; repeat or separate by commas for several)") {}
787
788 InstanceOptions::InstanceOptions(const char* e, const char* s)
789 : InstanceOptions(e) {
791 spec(s);
792 }
793
794 void
796 _data.reset();
797 }
798
799 void
805
806 void
812
813 void
815 _spec_file.value(f);
816 forget();
817 }
818
819 void
820 InstanceOptions::param(const char* p) {
821 _param.value(p);
822 forget();
823 }
824
825 void
828 std::cerr << "\t(string) default: " << ((instance() == nullptr) ? "NONE" : instance()) << std::endl
829 << "\t\twhich instance for script (name or file)" << std::endl;
830 }
831
832 void
833 InstanceOptions::parse(int& argc, char* argv[]) {
834 Options::parse(argc,argv);
835 // The spec file and parameters may have changed
836 forget();
837 if (argc < 2)
838 return;
839 instance(argv[1]);
840 }
841
842 void
843 InstanceOptions::parse(int& argc, char* argv[], bool strict) {
844 if (!strict) {
845 parse(argc,argv);
846 return;
847 }
848 Options::parse(argc,argv);
849 // The spec file and parameters may have changed
850 forget();
851 if (argc < 2)
852 return;
853 // The only remaining argument must be the instance, not an option
854 if ((argv[1][0] == '-') && (argv[1][1] != 0))
855 unrecognised(*this,argv[1]);
856 if (argc > 2)
857 unrecognised(*this,argv[2]);
858 instance(argv[1]);
859 }
860
861 bool
862 InstanceOptions::builtin(unsigned int& i) const {
863 const char* s = instance();
864 // At most nine digits, so that the conversion cannot overflow
865 if ((s == nullptr) || (*s == 0) || (strlen(s) > 9))
866 return false;
867 for (const char* c = s; *c != 0; c++)
868 if (!isdigit(static_cast<unsigned char>(*c)))
869 return false;
870 i = static_cast<unsigned int>(atoi(s));
871 return true;
872 }
873
875 static bool
876 is_directory(const char* f) {
877 struct stat st;
878 return (stat(f, &st) == 0) && ((st.st_mode & S_IFMT) == S_IFDIR);
879 }
880
881 bool
883 if (instance() == nullptr)
884 return false;
885 // Directories can be opened on some systems, but not read
886 if (is_directory(instance()))
887 return false;
888 std::ifstream f(instance());
889 return f.good();
890 }
891
894 if (_data)
895 return *_data;
896 if (instance() == nullptr)
897 throw Instance::Error("no instance file given");
899 if (param() != nullptr)
900 p.set(param());
902 if (spec_file() != nullptr)
904 else if (spec() != nullptr)
905 r = Instance::Spec::parse(spec(), std::string(name()) + " spec");
906 else
907 throw Instance::Error("no reader spec for instance files");
908 _data = std::make_unique<Instance::Data>(r.read(instance(), p));
909 return *_data;
910 }
911
916
917}
918
919// STATISTICS: driver-any
Base class for script options.
Definition driver.hh:391
BaseOptions(const char *s)
Initialize options for script with name s.
Definition options.cpp:546
void add(Driver::BaseOption &o)
Add new option o.
Definition options.cpp:537
const char * _name
Script name.
Definition driver.hh:395
virtual ~BaseOptions(void)
Destructor.
Definition options.cpp:651
Driver::BaseOption * fst
First registered option.
Definition driver.hh:393
Driver::BaseOption * lst
Last registered option.
Definition driver.hh:394
const char * name(void) const
Return name of script.
Definition options.hpp:204
virtual void help(void)
Print help text.
Definition options.cpp:557
void parse(int &argc, char *argv[])
Parse options from arguments argv (number is argc).
Definition options.cpp:611
Base class for options.
Definition driver.hh:123
static void strdel(const char *s)
Delete heap-allocated copy of string s.
Definition options.cpp:77
static char * stredup(const char *s)
Create heap-allocated copy of string s with hyphen added.
Definition options.cpp:66
const char * eopt
String for option (excluding hyphen).
Definition driver.hh:126
virtual ~BaseOption(void)
Destructor.
Definition options.cpp:108
char * argument(int argc, char *argv[]) const
Definition options.cpp:84
static char * strdup(const char *s)
Create heap-allocated copy of string s.
Definition options.cpp:56
const char * exp
Short explanation.
Definition driver.hh:128
const char * iopt
String for option (including hyphen).
Definition driver.hh:127
BaseOption(const char *o, const char *e)
Initialize for option o and explanation e.
Definition options.cpp:105
BaseOption * next
Next option Check for option and return its argument.
Definition driver.hh:129
bool cur
Current value.
Definition driver.hh:307
virtual int parse(int argc, char *argv[])
Parse option at first position and return number of parsed arguments.
Definition options.cpp:290
virtual void help(void)
Print help text.
Definition options.cpp:322
virtual int parse(int argc, char *argv[])
Parse option at first position and return number of parsed arguments.
Definition options.cpp:273
double cur
Current value.
Definition driver.hh:287
virtual void help(void)
Print help text.
Definition options.cpp:282
virtual void help(void)
Print help text.
Definition options.cpp:232
int cur
Current value.
Definition driver.hh:226
virtual int parse(int argc, char *argv[])
Parse option at first position and return number of parsed arguments.
Definition options.cpp:223
IntPropLevel cur
Current value.
Definition driver.hh:327
virtual int parse(int argc, char *argv[])
Parse option at first position and return number of parsed arguments.
Definition options.cpp:338
IplOption(IntPropLevel ipl=IPL_DEF)
Initialize with default value ipl.
Definition options.cpp:333
virtual void help(void)
Print help text.
Definition options.cpp:373
int cur_execution_id
Current execution ID.
Definition driver.hh:368
unsigned int cur_port
Current port.
Definition driver.hh:367
virtual int parse(int argc, char *argv[])
Parse option at first position and return number of parsed arguments.
Definition options.cpp:517
virtual void help(void)
Print help text.
Definition options.cpp:531
StringListOption(const char *o, const char *e)
Initialize for option o and explanation e.
Definition options.cpp:142
virtual int parse(int argc, char *argv[])
Parse option at first position and return number of parsed arguments.
Definition options.cpp:145
const char * help
Optional help text.
Definition driver.hh:196
Value * next
Next option value.
Definition driver.hh:197
int val
Value for an option value.
Definition driver.hh:194
const char * opt
String for option value.
Definition driver.hh:195
virtual ~StringOption(void)
Destructor.
Definition options.cpp:210
virtual int parse(int argc, char *argv[])
Parse option at first position and return number of parsed arguments.
Definition options.cpp:176
int cur
Current value.
Definition driver.hh:199
void add(int v, const char *o, const char *h=nullptr)
Add option value for value v, string o, and help text h.
Definition options.cpp:162
virtual void help(void)
Print help text.
Definition options.cpp:191
Value * lst
Last option value.
Definition driver.hh:201
Value * fst
First option value.
Definition driver.hh:200
virtual void help(void)
Print help text.
Definition options.cpp:132
virtual ~StringValueOption(void)
Destructor.
Definition options.cpp:137
StringValueOption(const char *o, const char *e, const char *v=nullptr)
Initialize for option o and explanation e and default value v.
Definition options.cpp:115
const char * value(void) const
Return current option value.
Definition options.hpp:46
const char * cur
Current value.
Definition driver.hh:155
virtual int parse(int argc, char *argv[])
Parse option at first position and return number of parsed arguments.
Definition options.cpp:124
virtual void help(void)
Print help text.
Definition options.cpp:458
int cur
Current value.
Definition driver.hh:347
TraceOption(int f=0)
Initialize with no tracing.
Definition options.cpp:399
virtual int parse(int argc, char *argv[])
Parse option at first position and return number of parsed arguments.
Definition options.cpp:404
virtual int parse(int argc, char *argv[])
Parse option at first position and return number of parsed arguments.
Definition options.cpp:239
unsigned int cur
Current value.
Definition driver.hh:246
virtual void help(void)
Print help text.
Definition options.cpp:248
virtual int parse(int argc, char *argv[])
Parse option at first position and return number of parsed arguments.
Definition options.cpp:256
unsigned long long int cur
Current value.
Definition driver.hh:266
virtual void help(void)
Print help text.
Definition options.cpp:265
bool builtin(unsigned int &i) const
Test whether the instance is the number of a built-in instance.
Definition options.cpp:862
const char * _inst
Instance string.
Definition driver.hh:836
bool is_file(void) const
Test whether the instance names a readable file.
Definition options.cpp:882
void parse(int &argc, char *argv[])
Parse options from arguments argv (number is argc).
Definition options.cpp:833
void instance(const char *s)
Set default instance name.
Definition options.cpp:800
virtual void help(void)
Print help text.
Definition options.cpp:826
Driver::StringListOption _param
Parameters for the spec.
Definition driver.hh:839
void forget(void) const
Definition options.cpp:795
const char * instance(void) const
Return instance name.
Definition options.hpp:666
const char * spec(void) const
Return the reader spec for instance files (may be null).
Definition options.hpp:671
const char * _spec
Reader spec for instance files.
Definition driver.hh:837
Instance::Data data(void) const
Read the instance file.
Definition options.cpp:893
~InstanceOptions(void)
Destructor.
Definition options.cpp:912
const char * param(void) const
Return the spec parameters (may be null).
Definition options.hpp:681
std::unique_ptr< Instance::Data > _data
Data read, or null Forget the data read.
Definition driver.hh:840
InstanceOptions(const char *s)
Initialize options for script with name s.
Definition options.cpp:783
Driver::StringValueOption _spec_file
File with a reader spec.
Definition driver.hh:838
const char * spec_file(void) const
Return the file with a reader spec (may be null).
Definition options.hpp:676
Named values read from an instance.
Definition instance.hh:406
Exception for errors in specs and instance files
Definition instance.hh:337
Values for the param statements of a spec.
Definition instance.hh:364
void set(const std::string &name, const std::string &value)
Set parameter name to value.
Definition data.cpp:64
Reader spec for a textual instance format.
Definition instance.hh:470
static Spec load(const std::string &path)
Load the spec in file path.
Definition spec.cpp:1275
static Spec parse(const std::string &text, const std::string &origin="<spec>")
Parse spec text, using origin in error messages.
Definition spec.cpp:1268
Driver::DoubleOption _relax
Probability to relax variable.
Definition driver.hh:484
Driver::StringValueOption _log_file
Where to print statistics.
Definition driver.hh:499
void c_d(unsigned int d)
Set default copy recomputation distance.
Definition options.hpp:350
Driver::StringOption _model
General model options.
Definition driver.hh:451
Driver::StringOption _mode
Script mode to run.
Definition driver.hh:494
Driver::DoubleOption _decay
Decay option.
Definition driver.hh:456
Driver::UnsignedIntOption _nogoods_limit
Limit for no-good extraction.
Definition driver.hh:483
void a_d(unsigned int d)
Set default adaptive recomputation distance.
Definition options.hpp:359
Driver::BoolOption _nogoods
Whether to use no-goods.
Definition driver.hh:482
Driver::UnsignedIntOption _slice
Size of a portfolio slice.
Definition driver.hh:476
Driver::UnsignedLongLongIntOption _r_limit
Cutoff for number of restarts.
Definition driver.hh:481
Driver::TraceOption _trace
Trace flags for tracing.
Definition driver.hh:500
Driver::UnsignedLongLongIntOption _fail
Cutoff for number of failures.
Definition driver.hh:473
Driver::UnsignedIntOption _d_l
Discrepancy limit for LDS.
Definition driver.hh:469
void slice(unsigned int n)
Set default slice size in a portfolio.
Definition options.hpp:413
Driver::UnsignedIntOption _assets
Number of assets in a portfolio.
Definition driver.hh:475
Driver::UnsignedLongLongIntOption _node
Cutoff for number of nodes.
Definition driver.hh:471
Driver::UnsignedIntOption _iterations
How many iterations per sample.
Definition driver.hh:496
Driver::StringOption _search
Search options.
Definition driver.hh:463
Driver::StringOption _propagation
Propagation options.
Definition driver.hh:453
Driver::IplOption _ipl
Integer propagation level.
Definition driver.hh:454
Driver::UnsignedLongLongIntOption _solutions
How many solutions.
Definition driver.hh:465
Options(const char *s)
Initialize options for script with name s.
Definition options.cpp:656
Driver::BoolOption _print_last
Print only last solution found.
Definition driver.hh:497
Driver::UnsignedIntOption _c_d
Copy recomputation distance.
Definition driver.hh:467
void nogoods_limit(unsigned int l)
Set default nogoods depth limit.
Definition options.hpp:467
const Search::HeuristicGuidance * _guidance
Guidance for heuristic search.
Definition driver.hh:488
Driver::ProfilerOption _profiler
Options for the CP Profiler.
Definition driver.hh:503
Driver::DoubleOption _threads
How many threads to use.
Definition driver.hh:466
Driver::StringOption _branching
Branching options.
Definition driver.hh:455
Driver::StringOption _restart
Restart method option.
Definition driver.hh:477
Driver::UnsignedIntOption _seed
Seed option.
Definition driver.hh:457
Driver::DoubleOption _step
Step option.
Definition driver.hh:458
Driver::UnsignedIntOption _r_scale
Restart scale factor.
Definition driver.hh:479
Driver::DoubleOption _time
Cutoff for time.
Definition driver.hh:474
Driver::BoolOption _interrupt
Whether to catch SIGINT.
Definition driver.hh:485
void d_l(unsigned int d)
Set default discrepancy limit for LDS.
Definition options.hpp:368
Driver::UnsignedIntOption _a_d
Adaptive recomputation distance.
Definition driver.hh:468
Driver::DoubleOption _r_base
Restart base.
Definition driver.hh:478
Driver::StringOption _symmetry
General symmetry options.
Definition driver.hh:452
Driver::StringValueOption _out_file
Where to print solutions.
Definition driver.hh:498
Driver::UnsignedIntOption _samples
How many samples.
Definition driver.hh:495
void threads(double n)
Set number of parallel threads.
Definition options.hpp:330
unsigned int size(void) const
Return size.
Definition options.hpp:648
virtual void help(void)
Print help text.
Definition options.cpp:745
SizeOptions(const char *s)
Initialize options for script with name s.
Definition options.cpp:741
unsigned int _size
Size value.
Definition driver.hh:776
void parse(int &argc, char *argv[])
Parse options from arguments argv (number is argc).
Definition options.cpp:752
static unsigned int npu(void)
Return number of processing units (1 if information not available).
Definition thread.hpp:164
Heap heap
The single global heap.
Definition heap.cpp:44
@ SM_STAT
Print statistics for script.
Definition driver.hh:100
@ SM_SOLUTION
Print solution and some statistics.
Definition driver.hh:98
@ SM_GIST
Run script in Gist.
Definition driver.hh:101
@ SM_TIME
Measure average runtime.
Definition driver.hh:99
@ RM_CONSTANT
Restart with constant sequence.
Definition driver.hh:110
@ RM_LINEAR
Restart with linear sequence.
Definition driver.hh:111
@ RM_LUBY
Restart with Luby sequence.
Definition driver.hh:112
@ RM_NONE
No restarts.
Definition driver.hh:109
@ RM_GEOMETRIC
Restart with geometric sequence.
Definition driver.hh:113
IntPropLevel
Propagation levels for integer propagators.
Definition int.hh:1274
@ IPL_BASIC
Use basic propagation algorithm.
Definition int.hh:1281
@ IPL_DOM
Domain propagation Options: basic versus advanced propagation.
Definition int.hh:1279
@ IPL_FULL
Use full propagation.
Definition int.hh:1284
@ IPL_VAL
Value propagation.
Definition int.hh:1277
@ IPL_ADVANCED
Use advanced propagation algorithm.
Definition int.hh:1282
@ IPL_DEF
Simple propagation levels.
Definition int.hh:1276
@ IPL_BND
Bounds propagation.
Definition int.hh:1278
@ TE_INIT
Trace init events.
Definition recorder.hpp:43
@ TE_POST
Trace propagator posting.
Definition recorder.hpp:52
@ TE_COMMIT
Trace commit operations by branchers.
Definition recorder.hpp:51
@ TE_PRUNE
Trace prune events.
Definition recorder.hpp:44
@ TE_PROPAGATE
Trace propagator executions.
Definition recorder.hpp:50
@ TE_FIX
Trace fixpoint events.
Definition recorder.hpp:45
@ TE_FAIL
Trace fail events.
Definition recorder.hpp:46
@ TE_DONE
Trace done events.
Definition recorder.hpp:47
Script commandline driver.
Search engines
Gecode toplevel namespace
IntPropLevel vbd(IntPropLevel ipl)
Extract value, bounds, or domain propagation from propagation level.
Definition ipl.hpp:37
#define GECODE_VERSION
Definition config.hpp:138
#define GECODE_HAS_CPPROFILER
Definition config.hpp:69
#define GECODE_NEVER
Assert that this command is never executed.
Definition macros.hpp:56