55 size_t l = strlen(s) + 1;
56 char* d =
static_cast<char*
>(
heap.ralloc(l));
65 size_t l = strlen(s) + 1;
66 char* d =
static_cast<char*
>(
heap.ralloc(l+1));
68 (void) memcpy(d+1,s,l);
76 heap.rfree(
const_cast<char*
>(s));
83 const char* s = argv[1];
94 std::cerr <<
"Missing argument for option \"" <<
iopt <<
"\""
121 if (
char* a =
argument(argc,argv)) {
129 std::cerr <<
'\t' <<
iopt <<
" (string) default: "
130 << ((
cur ==
nullptr) ?
"NONE" :
cur) << std::endl
131 <<
"\t\t" <<
exp << std::endl;
146 if (
fst ==
nullptr) {
155 if (
char* a =
argument(argc,argv)) {
156 for (
Value* v =
fst; v !=
nullptr; v = v->next)
157 if (!strcmp(a,v->opt)) {
161 std::cerr <<
"Wrong argument \"" << a
162 <<
"\" for option \"" <<
iopt <<
"\""
172 std::cerr <<
'\t' <<
iopt <<
" (";
173 const char* d =
nullptr;
174 for (
Value* v =
fst; v !=
nullptr; v = v->next) {
175 std::cerr << v->opt << ((v->next !=
nullptr) ?
", " :
"");
181 std::cerr <<
" default: " << d;
182 std::cerr << std::endl <<
"\t\t" <<
exp << std::endl;
183 for (
Value* v =
fst; v !=
nullptr; v = v->next)
184 if (v->help !=
nullptr)
185 std::cerr <<
"\t\t " << v->opt <<
": " << v->help << std::endl;
190 while (v !=
nullptr) {
202 if (
char* a =
argument(argc,argv)) {
211 std::cerr <<
'\t' <<
iopt <<
" (int) default: " <<
cur << std::endl
212 <<
"\t\t" <<
exp << std::endl;
218 if (
char* a =
argument(argc,argv)) {
219 cur =
static_cast<unsigned int>(atoi(a));
227 std::cerr <<
'\t' <<
iopt <<
" (unsigned int) default: "
229 <<
"\t\t" <<
exp << std::endl;
235 if (
char* a =
argument(argc,argv)) {
236 cur =
static_cast<unsigned int>(atoll(a));
244 std::cerr <<
'\t' <<
iopt <<
" (unsigned long long int) default: "
246 <<
"\t\t" <<
exp << std::endl;
252 if (
char* a =
argument(argc,argv)) {
262 cerr <<
'\t' <<
iopt <<
" (double) default: " <<
cur << endl
263 <<
"\t\t" <<
exp << endl;
271 const char* s = argv[1];
285 }
else if (!strcmp(argv[2],
"true") || !strcmp(argv[2],
"1")) {
288 }
else if (!strcmp(argv[2],
"false") || !strcmp(argv[2],
"0")) {
302 cerr <<
'\t' <<
iopt <<
" (optional: false, 0, true, 1) default: "
303 << (
cur ?
"true" :
"false") << endl
304 <<
"\t\t" <<
exp << endl;
312 :
BaseOption(
"ipl",
"integer propagation level (comma-separated list)"),
317 if (
char* a =
argument(argc,argv)) {
323 while ((*c !=
',') && (*c != 0))
325 unsigned int e =
static_cast<unsigned int>(c-a);
326 if (!strncmp(
"def",a,e)) { b =
IPL_DEF; }
327 else if (!strncmp(
"val",a,e)) { b =
IPL_VAL; }
328 else if (!strncmp(
"bnd",a,e)) { b =
IPL_BND; }
329 else if (!strncmp(
"dom",a,e)) { b =
IPL_DOM; }
330 else if (!strncmp(
"basic",a,e)) { m |=
IPL_BASIC; }
331 else if (!strncmp(
"advanced",a,e)) { m |=
IPL_ADVANCED; }
332 else if (!strncmp(
"full",a,e)) { m |=
IPL_FULL; }
334 std::cerr <<
"Wrong argument \"" << a
335 <<
"\" for option \"" <<
iopt <<
"\""
340 if (*c ==
',') a = c+1;
else a = c;
354 <<
" (def,val,bnd,dom,basic,advanced,full)" << endl
357 case IPL_DEF: cerr <<
"def";
break;
358 case IPL_VAL: cerr <<
"val";
break;
359 case IPL_BND: cerr <<
"bnd";
break;
360 case IPL_DOM: cerr <<
"dom";
break;
369 cerr << endl <<
"\t\t" <<
exp << endl;
378 :
BaseOption(
"trace",
"trace flags (comma-separated list)"),
383 if (
char* a =
argument(argc,argv)) {
388 while ((*c !=
',') && (*c != 0))
390 unsigned int e =
static_cast<unsigned int>(c-a);
392 else if (!strncmp(
"prune",a,e)) {
cur |=
TE_PRUNE; }
393 else if (!strncmp(
"fix",a,e)) {
cur |=
TE_FIX; }
394 else if (!strncmp(
"fail",a,e)) {
cur |=
TE_FAIL; }
395 else if (!strncmp(
"done",a,e)) {
cur |=
TE_DONE ; }
398 else if (!strncmp(
"post",a,e)) {
cur |=
TE_POST; }
399 else if (!strncmp(
"none",a,e) ||
400 !strncmp(
"false",a,e) ||
401 !strncmp(
"0",a,e)) {
cur = 0; }
402 else if (!strncmp(
"all",a,e) ||
411 else if (!strncmp(
"variable",a,e)) {
cur = (
TE_INIT |
420 std::cerr <<
"Wrong argument \"" << a
421 <<
"\" for option \"" <<
iopt <<
"\""
426 if (*c ==
',') a = c+1;
else a = c;
439 <<
" (init,prune,fix,fail,done,propagate,commit,post,none,all,variable,general)"
455 if (f != 0) cerr <<
',';
460 if (f != 0) cerr <<
',';
465 if (f != 0) cerr <<
',';
470 if (f != 0) cerr <<
',';
475 if (f != 0) cerr <<
',';
480 if (f != 0) cerr <<
',';
485 if (f != 0) cerr <<
',';
491 cerr << endl <<
"\t\t" <<
exp << endl;
496 if (
char* a =
argument(argc, argv)) {
497 char* sep = strchr(a,
',');
499 std::cerr <<
"Wrong argument \"" << a <<
"\" for option \"" <<
iopt <<
"\"" << std::endl;
517 if (
fst ==
nullptr) {
525 :
fst(nullptr),
lst(nullptr),
536 std::cerr <<
"Gecode configuration information:" << std::endl
538 <<
" - Variable types: ";
539#ifdef GECODE_HAS_INT_VARS
540 std::cerr <<
"BoolVar IntVar ";
542#ifdef GECODE_HAS_SET_VARS
543 std::cerr <<
"SetVar ";
545#ifdef GECODE_HAS_FLOAT_VARS
546 std::cerr <<
"FloatVar "
548 <<
" - Trigonometric and transcendental float constraints: ";
549#ifdef GECODE_HAS_MPFR
550 std::cerr <<
"enabled";
552 std::cerr <<
"disabled";
555 std::cerr << std::endl;
556 std::cerr <<
" - Thread support: ";
557#ifdef GECODE_HAS_THREADS
559 std::cerr <<
"enabled (1 processing unit)";
562 <<
" processing units)";
564 std::cerr <<
"disabled";
566 std::cerr << std::endl
567 <<
" - Gist support: ";
568#ifdef GECODE_HAS_GIST
569 std::cerr <<
"enabled";
571 std::cerr <<
"disabled";
573 std::cerr << std::endl
574 <<
" - CPProfiler support: ";
575#ifdef GECODE_HAS_CPPROFILER
576 std::cerr <<
"enabled";
578 std::cerr <<
"disabled";
580 std::cerr << std::endl << std::endl
581 <<
"Options for " <<
name() <<
":" << std::endl
582 <<
"\t-help, --help, -?" << std::endl
583 <<
"\t\tprint this help message" << std::endl;
594 if (
int a = o->parse(c,v)) {
599 if (!strcmp(v[1],
"-help") || !strcmp(v[1],
"--help") ||
600 !strcmp(v[1],
"-?")) {
607 for (
int i=1; i<argc; i++)
620 _model(
"model",
"model variants"),
621 _symmetry(
"symmetry",
"symmetry variants"),
624 _decay(
"decay",
"decay factor",1.0),
625 _seed(
"seed",
"random number generator seed",1U),
626 _step(
"step",
"step distance for float optimization",0.0),
628 _search(
"search",
"search engine variants"),
629 _solutions(
"solutions",
"number of solutions (0 = all)",1),
630 _threads(
"threads",
"number of threads (0 = #processing units)",
632 _c_d(
"c-d",
"recomputation commit distance",
Search::Config::
c_d),
633 _a_d(
"a-d",
"recomputation adaptation distance",
Search::Config::
a_d),
635 _node(
"node",
"node cutoff (0 = none, solution mode)"),
636 _fail(
"fail",
"failure cutoff (0 = none, solution mode)"),
637 _time(
"time",
"time (in ms) cutoff (0 = none, solution mode)"),
638 _assets(
"assets",
"#portfolio assets (#engines)",0),
641 _r_base(
"restart-base",
"base for geometric restart sequence",
643 _r_scale(
"restart-scale",
"scale factor for restart sequence",
645 _r_limit(
"restart-limit",
"restart cutoff (0 = none, solution mode)"),
646 _nogoods(
"nogoods",
"whether to use no-goods from restarts",false),
647 _nogoods_limit(
"nogoods-limit",
"depth limit for no-good extraction",
649 _relax(
"relax",
"probability for relaxing variable", 0.0),
650 _interrupt(
"interrupt",
"whether to catch Ctrl-C (true) or not (false)",
654 _samples(
"samples",
"how many samples (time mode)",1),
655 _iterations(
"iterations",
"iterations per sample (time mode)",1),
657 "whether to only print the last solution (solution mode)",
659 _out_file(
"file-sol",
"where to print solutions "
660 "(supports stdout, stdlog, stderr)",
"stdout"),
661 _log_file(
"file-stat",
"where to print statistics "
662 "(supports stdout, stdlog, stderr)",
"stdout"),
667 _profiler(
"cp-profiler",
"use this execution id and port (comma separated) with CP-profiler")
693#ifdef GECODE_HAS_CPPROFILER
705 std::cerr <<
"\t(unsigned int) default: " <<
size() << std::endl
706 <<
"\t\twhich version/size for script" << std::endl;
714 size(
static_cast<unsigned int>(atoi(argv[1])));
731 std::cerr <<
"\t(string) default: " <<
instance() << std::endl
732 <<
"\t\twhich instance for script" << std::endl;
BaseOptions(const char *s)
Initialize options for script with name s.
void add(Driver::BaseOption &o)
Add new option o.
const char * _name
Script name.
virtual ~BaseOptions(void)
Destructor.
Driver::BaseOption * fst
First registered option.
Driver::BaseOption * lst
Last registered option.
const char * name(void) const
Return name of script.
virtual void help(void)
Print help text.
void parse(int &argc, char *argv[])
Parse options from arguments argv (number is argc).
static void strdel(const char *s)
Delete heap-allocated copy of string s.
static char * stredup(const char *s)
Create heap-allocated copy of string s with hyphen added.
const char * eopt
String for option (excluding hyphen).
virtual ~BaseOption(void)
Destructor.
char * argument(int argc, char *argv[]) const
static char * strdup(const char *s)
Create heap-allocated copy of string s.
const char * exp
Short explanation.
const char * iopt
String for option (including hyphen).
BaseOption(const char *o, const char *e)
Initialize for option o and explanation e.
BaseOption * next
Next option Check for option and return its argument.
virtual int parse(int argc, char *argv[])
Parse option at first position and return number of parsed arguments.
virtual void help(void)
Print help text.
virtual int parse(int argc, char *argv[])
Parse option at first position and return number of parsed arguments.
virtual void help(void)
Print help text.
virtual void help(void)
Print help text.
virtual int parse(int argc, char *argv[])
Parse option at first position and return number of parsed arguments.
IntPropLevel cur
Current value.
virtual int parse(int argc, char *argv[])
Parse option at first position and return number of parsed arguments.
IplOption(IntPropLevel ipl=IPL_DEF)
Initialize with default value ipl.
virtual void help(void)
Print help text.
int cur_execution_id
Current execution ID.
unsigned int cur_port
Current port.
virtual int parse(int argc, char *argv[])
Parse option at first position and return number of parsed arguments.
virtual void help(void)
Print help text.
const char * help
Optional help text.
Value * next
Next option value.
int val
Value for an option value.
const char * opt
String for option value.
virtual ~StringOption(void)
Destructor.
virtual int parse(int argc, char *argv[])
Parse option at first position and return number of parsed arguments.
void add(int v, const char *o, const char *h=nullptr)
Add option value for value v, string o, and help text h.
virtual void help(void)
Print help text.
Value * lst
Last option value.
Value * fst
First option value.
virtual void help(void)
Print help text.
virtual ~StringValueOption(void)
Destructor.
StringValueOption(const char *o, const char *e, const char *v=nullptr)
Initialize for option o and explanation e and default value v.
const char * value(void) const
Return current option value.
const char * cur
Current value.
virtual int parse(int argc, char *argv[])
Parse option at first position and return number of parsed arguments.
virtual void help(void)
Print help text.
TraceOption(int f=0)
Initialize with no tracing.
virtual int parse(int argc, char *argv[])
Parse option at first position and return number of parsed arguments.
virtual int parse(int argc, char *argv[])
Parse option at first position and return number of parsed arguments.
unsigned int cur
Current value.
virtual void help(void)
Print help text.
virtual int parse(int argc, char *argv[])
Parse option at first position and return number of parsed arguments.
unsigned long long int cur
Current value.
virtual void help(void)
Print help text.
const char * _inst
Instance string.
void parse(int &argc, char *argv[])
Parse options from arguments argv (number is argc).
virtual void help(void)
Print help text.
const char * instance(void) const
Return instance name.
~InstanceOptions(void)
Destructor.
InstanceOptions(const char *s)
Initialize options for script with name s.
Driver::DoubleOption _relax
Probability to relax variable.
Driver::StringValueOption _log_file
Where to print statistics.
void c_d(unsigned int d)
Set default copy recomputation distance.
Driver::StringOption _model
General model options.
Driver::StringOption _mode
Script mode to run.
Driver::DoubleOption _decay
Decay option.
Driver::UnsignedIntOption _nogoods_limit
Limit for no-good extraction.
void a_d(unsigned int d)
Set default adaptive recomputation distance.
Driver::BoolOption _nogoods
Whether to use no-goods.
Driver::UnsignedIntOption _slice
Size of a portfolio slice.
Driver::UnsignedLongLongIntOption _r_limit
Cutoff for number of restarts.
Driver::TraceOption _trace
Trace flags for tracing.
Driver::UnsignedLongLongIntOption _fail
Cutoff for number of failures.
Driver::UnsignedIntOption _d_l
Discrepancy limit for LDS.
void slice(unsigned int n)
Set default slice size in a portfolio.
Driver::UnsignedIntOption _assets
Number of assets in a portfolio.
Driver::UnsignedLongLongIntOption _node
Cutoff for number of nodes.
Driver::UnsignedIntOption _iterations
How many iterations per sample.
Driver::StringOption _search
Search options.
Driver::StringOption _propagation
Propagation options.
Driver::IplOption _ipl
Integer propagation level.
Driver::UnsignedLongLongIntOption _solutions
How many solutions.
Options(const char *s)
Initialize options for script with name s.
Driver::BoolOption _print_last
Print only last solution found.
Driver::UnsignedIntOption _c_d
Copy recomputation distance.
void nogoods_limit(unsigned int l)
Set default nogoods depth limit.
Driver::ProfilerOption _profiler
Options for the CP Profiler.
Driver::DoubleOption _threads
How many threads to use.
Driver::StringOption _branching
Branching options.
Driver::StringOption _restart
Restart method option.
Driver::UnsignedIntOption _seed
Seed option.
Driver::DoubleOption _step
Step option.
Driver::UnsignedIntOption _r_scale
Restart scale factor.
Driver::DoubleOption _time
Cutoff for time.
Driver::BoolOption _interrupt
Whether to catch SIGINT.
void d_l(unsigned int d)
Set default discrepancy limit for LDS.
Driver::UnsignedIntOption _a_d
Adaptive recomputation distance.
Driver::DoubleOption _r_base
Restart base.
Driver::StringOption _symmetry
General symmetry options.
Driver::StringValueOption _out_file
Where to print solutions.
Driver::UnsignedIntOption _samples
How many samples.
void threads(double n)
Set number of parallel threads.
unsigned int size(void) const
Return size.
virtual void help(void)
Print help text.
SizeOptions(const char *s)
Initialize options for script with name s.
unsigned int _size
Size value.
void parse(int &argc, char *argv[])
Parse options from arguments argv (number is argc).
static unsigned int npu(void)
Return number of processing units (1 if information not available).
Heap heap
The single global heap.
@ SM_STAT
Print statistics for script.
@ SM_SOLUTION
Print solution and some statistics.
@ SM_GIST
Run script in Gist.
@ SM_TIME
Measure average runtime.
@ RM_CONSTANT
Restart with constant sequence.
@ RM_LINEAR
Restart with linear sequence.
@ RM_LUBY
Restart with Luby sequence.
@ RM_GEOMETRIC
Restart with geometric sequence.
IntPropLevel
Propagation levels for integer propagators.
@ IPL_BASIC
Use basic propagation algorithm.
@ IPL_DOM
Domain propagation Options: basic versus advanced propagation.
@ IPL_FULL
Use full propagation.
@ IPL_VAL
Value propagation.
@ IPL_ADVANCED
Use advanced propagation algorithm.
@ IPL_DEF
Simple propagation levels.
@ IPL_BND
Bounds propagation.
@ TE_INIT
Trace init events.
@ TE_POST
Trace propagator posting.
@ TE_COMMIT
Trace commit operations by branchers.
@ TE_PRUNE
Trace prune events.
@ TE_PROPAGATE
Trace propagator executions.
@ TE_FIX
Trace fixpoint events.
@ TE_FAIL
Trace fail events.
@ TE_DONE
Trace done events.
Script commandline driver.
Gecode toplevel namespace
IntPropLevel vbd(IntPropLevel ipl)
Extract value, bounds, or domain propagation from propagation level.
#define GECODE_HAS_CPPROFILER
#define GECODE_NEVER
Assert that this command is never executed.