59 size_t l = strlen(s) + 1;
60 char* d =
static_cast<char*
>(
heap.ralloc(l));
69 size_t l = strlen(s) + 1;
70 char* d =
static_cast<char*
>(
heap.ralloc(l+1));
72 (void) memcpy(d+1,s,l);
80 heap.rfree(
const_cast<char*
>(s));
87 const char* s = argv[1];
98 std::cerr <<
"Missing argument for option \"" <<
iopt <<
"\""
125 if (
char* a =
argument(argc,argv)) {
133 std::cerr <<
'\t' <<
iopt <<
" (string) default: "
134 << ((
cur ==
nullptr) ?
"NONE" :
cur) << std::endl
135 <<
"\t\t" <<
exp << std::endl;
146 if (
char* a =
argument(argc,argv)) {
147 if (
cur ==
nullptr) {
150 std::string v = std::string(
cur) +
"," + a;
168 if (
fst ==
nullptr) {
177 if (
char* a =
argument(argc,argv)) {
178 for (
Value* v =
fst; v !=
nullptr; v = v->next)
179 if (!strcmp(a,v->opt)) {
183 std::cerr <<
"Wrong argument \"" << a
184 <<
"\" for option \"" <<
iopt <<
"\""
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) ?
", " :
"");
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;
212 while (v !=
nullptr) {
224 if (
char* a =
argument(argc,argv)) {
233 std::cerr <<
'\t' <<
iopt <<
" (int) default: " <<
cur << std::endl
234 <<
"\t\t" <<
exp << std::endl;
240 if (
char* a =
argument(argc,argv)) {
241 cur =
static_cast<unsigned int>(atoi(a));
249 std::cerr <<
'\t' <<
iopt <<
" (unsigned int) default: "
251 <<
"\t\t" <<
exp << std::endl;
257 if (
char* a =
argument(argc,argv)) {
258 cur =
static_cast<unsigned int>(atoll(a));
266 std::cerr <<
'\t' <<
iopt <<
" (unsigned long long int) default: "
268 <<
"\t\t" <<
exp << std::endl;
274 if (
char* a =
argument(argc,argv)) {
284 cerr <<
'\t' <<
iopt <<
" (double) default: " <<
cur << endl
285 <<
"\t\t" <<
exp << endl;
293 const char* s = argv[1];
307 }
else if (!strcmp(argv[2],
"true") || !strcmp(argv[2],
"1")) {
310 }
else if (!strcmp(argv[2],
"false") || !strcmp(argv[2],
"0")) {
324 cerr <<
'\t' <<
iopt <<
" (optional: false, 0, true, 1) default: "
325 << (
cur ?
"true" :
"false") << endl
326 <<
"\t\t" <<
exp << endl;
334 :
BaseOption(
"ipl",
"integer propagation level (comma-separated list)"),
339 if (
char* a =
argument(argc,argv)) {
345 while ((*c !=
',') && (*c != 0))
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; }
356 std::cerr <<
"Wrong argument \"" << a
357 <<
"\" for option \"" <<
iopt <<
"\""
362 if (*c ==
',') a = c+1;
else a = c;
376 <<
" (def,val,bnd,dom,basic,advanced,full)" << endl
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;
391 cerr << endl <<
"\t\t" <<
exp << endl;
400 :
BaseOption(
"trace",
"trace flags (comma-separated list)"),
405 if (
char* a =
argument(argc,argv)) {
410 while ((*c !=
',') && (*c != 0))
412 unsigned int e =
static_cast<unsigned int>(c-a);
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 ; }
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) ||
433 else if (!strncmp(
"variable",a,e)) {
cur = (
TE_INIT |
442 std::cerr <<
"Wrong argument \"" << a
443 <<
"\" for option \"" <<
iopt <<
"\""
448 if (*c ==
',') a = c+1;
else a = c;
461 <<
" (init,prune,fix,fail,done,propagate,commit,post,none,all,variable,general)"
477 if (f != 0) cerr <<
',';
482 if (f != 0) cerr <<
',';
487 if (f != 0) cerr <<
',';
492 if (f != 0) cerr <<
',';
497 if (f != 0) cerr <<
',';
502 if (f != 0) cerr <<
',';
507 if (f != 0) cerr <<
',';
513 cerr << endl <<
"\t\t" <<
exp << endl;
518 if (
char* a =
argument(argc, argv)) {
519 char* sep = strchr(a,
',');
521 std::cerr <<
"Wrong argument \"" << a <<
"\" for option \"" <<
iopt <<
"\"" << std::endl;
539 if (
fst ==
nullptr) {
547 :
fst(nullptr),
lst(nullptr),
558 std::cerr <<
"Gecode configuration information:" << std::endl
560 <<
" - Variable types: ";
561#ifdef GECODE_HAS_INT_VARS
562 std::cerr <<
"BoolVar IntVar ";
564#ifdef GECODE_HAS_SET_VARS
565 std::cerr <<
"SetVar ";
567#ifdef GECODE_HAS_FLOAT_VARS
568 std::cerr <<
"FloatVar "
570 <<
" - Trigonometric and transcendental float constraints: ";
571#ifdef GECODE_HAS_MPFR
572 std::cerr <<
"enabled";
574 std::cerr <<
"disabled";
577 std::cerr << std::endl;
578 std::cerr <<
" - Thread support: ";
579#ifdef GECODE_HAS_THREADS
581 std::cerr <<
"enabled (1 processing unit)";
584 <<
" processing units)";
586 std::cerr <<
"disabled";
588 std::cerr << std::endl
589 <<
" - Gist support: ";
590#ifdef GECODE_HAS_GIST
591 std::cerr <<
"enabled";
593 std::cerr <<
"disabled";
595 std::cerr << std::endl
596 <<
" - CPProfiler support: ";
597#ifdef GECODE_HAS_CPPROFILER
598 std::cerr <<
"enabled";
600 std::cerr <<
"disabled";
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;
616 if (
int a = o->parse(c,v)) {
621 if (!strcmp(v[1],
"-help") || !strcmp(v[1],
"--help") ||
622 !strcmp(v[1],
"-?")) {
629 for (
int i=1; i<argc; i++)
638 std::cerr <<
"Unrecognised argument \"" << a <<
"\"" << std::endl;
647 if (strict && (argc > 1))
648 unrecognised(*
this,argv[1]);
659 _model(
"model",
"model variants"),
660 _symmetry(
"symmetry",
"symmetry 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),
667 _search(
"search",
"search engine variants"),
668 _solutions(
"solutions",
"number of solutions (0 = all)",1),
669 _threads(
"threads",
"number of threads (0 = #processing units)",
671 _c_d(
"c-d",
"recomputation commit distance",
Search::Config::
c_d),
672 _a_d(
"a-d",
"recomputation adaptation distance",
Search::Config::
a_d),
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),
680 _r_base(
"restart-base",
"base for geometric restart sequence",
682 _r_scale(
"restart-scale",
"scale factor for restart sequence",
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",
688 _relax(
"relax",
"probability for relaxing variable", 0.0),
689 _interrupt(
"interrupt",
"whether to catch Ctrl-C (true) or not (false)",
692#ifdef GECODE_HAS_EXPERIMENTAL
696 _samples(
"samples",
"how many samples (time mode)",1),
697 _iterations(
"iterations",
"iterations per sample (time mode)",1),
699 "whether to only print the last solution (solution mode)",
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"),
709 _profiler(
"cp-profiler",
"use this execution id and port (comma separated) with CP-profiler")
735#ifdef GECODE_HAS_CPPROFILER
747 std::cerr <<
"\t(unsigned int) default: " <<
size() << std::endl
748 <<
"\t\twhich version/size for script" << std::endl;
756 size(
static_cast<unsigned int>(atoi(argv[1])));
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)))
775 unrecognised(*
this,argv[1]);
777 unrecognised(*
this,argv[2]);
778 size(
static_cast<unsigned int>(atoi(argv[1])));
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)") {}
828 std::cerr <<
"\t(string) default: " << ((
instance() ==
nullptr) ?
"NONE" :
instance()) << std::endl
829 <<
"\t\twhich instance for script (name or file)" << std::endl;
854 if ((argv[1][0] ==
'-') && (argv[1][1] != 0))
855 unrecognised(*
this,argv[1]);
857 unrecognised(*
this,argv[2]);
865 if ((s ==
nullptr) || (*s == 0) || (strlen(s) > 9))
867 for (
const char* c = s; *c != 0; c++)
868 if (!isdigit(
static_cast<unsigned char>(*c)))
870 i =
static_cast<unsigned int>(atoi(s));
876 is_directory(
const char* f) {
878 return (stat(f, &st) == 0) && ((st.st_mode & S_IFMT) == S_IFDIR);
899 if (
param() !=
nullptr)
904 else if (
spec() !=
nullptr)
908 _data = std::make_unique<Instance::Data>(r.read(
instance(), p));
Base class for script options.
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.
StringListOption(const char *o, const char *e)
Initialize for option o and explanation e.
virtual int parse(int argc, char *argv[])
Parse option at first position and return number of parsed arguments.
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.
bool builtin(unsigned int &i) const
Test whether the instance is the number of a built-in instance.
const char * _inst
Instance string.
bool is_file(void) const
Test whether the instance names a readable file.
void parse(int &argc, char *argv[])
Parse options from arguments argv (number is argc).
void instance(const char *s)
Set default instance name.
virtual void help(void)
Print help text.
Driver::StringListOption _param
Parameters for the spec.
const char * instance(void) const
Return instance name.
const char * spec(void) const
Return the reader spec for instance files (may be null).
const char * _spec
Reader spec for instance files.
Instance::Data data(void) const
Read the instance file.
~InstanceOptions(void)
Destructor.
const char * param(void) const
Return the spec parameters (may be null).
std::unique_ptr< Instance::Data > _data
Data read, or null Forget the data read.
InstanceOptions(const char *s)
Initialize options for script with name s.
Driver::StringValueOption _spec_file
File with a reader spec.
const char * spec_file(void) const
Return the file with a reader spec (may be null).
Named values read from an instance.
Exception for errors in specs and instance files
Values for the param statements of a spec.
void set(const std::string &name, const std::string &value)
Set parameter name to value.
Reader spec for a textual instance format.
static Spec load(const std::string &path)
Load the spec in file path.
static Spec parse(const std::string &text, const std::string &origin="<spec>")
Parse spec text, using origin in error messages.
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.
const Search::HeuristicGuidance * _guidance
Guidance for heuristic search.
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.