11. Script commandline driver¶
The commandline driver (see Script commandline driver) provides support for passing common commandline options to programs and a sub-class for spaces called Script that can take advantage of the options.
Overview. Commandline options summarizes the commandline options supported by the commandline driver. The base classes for scripts that work together with the commandline driver are sketched in Scripts.
Important
Do not forget to add
#include <gecode/driver.hh>
to your program when you want to use the script commandline driver.
11.1. Commandline options¶
option |
type |
explanation |
|---|---|---|
propagation options |
||
|
|
integer propagation level |
branching options |
||
|
|
decay-factor |
|
|
seed for random numbers |
search options |
||
|
|
how many solutions ( |
|
|
how many threads |
|
|
commit recomputation distance |
|
|
adaptive recomputation distance |
|
|
discrepancy limit for |
|
|
cutoff for number of nodes |
|
|
cutoff for number of failures |
|
|
cutoff for time in milliseconds |
|
|
improvement step for floats |
restart-based and portfolio search options |
||
|
|
enable restarts, define cutoff |
|
|
scale-factor for cutoff values |
|
|
base for geometric cutoff values |
|
|
whether to post no-goods |
|
|
depth limit for no-good recording |
|
|
number of assets in a portfolio |
Figure 11.1 Predefined commandline options¶
option |
type |
explanation |
|---|---|---|
execution options |
||
|
|
script mode to run |
|
|
how many samples |
|
|
how many iterations per sample |
|
|
whether to only print last solution |
|
|
where to print solutions |
|
|
where to print statistics |
|
|
whether driver catches Ctrl-C |
|
|
which events to trace |
|
|
Comma separated pair of execution id and port number to connect to CPProfiler. |
Figure 11.2 Predefined commandline options, continued¶
option |
type |
explanation |
|---|---|---|
|
string |
branching options |
|
string |
general model options |
|
string |
propagation options |
|
string |
symmetry breaking options |
|
string |
search options |
Figure 11.3 User-definable commandline options¶
The commandline driver provides classes Options, SizeOptions, and InstanceOptions that support parsing commandline options. All classes support the options as summarized in Figure 11.1, Figure 11.2, and Figure 11.3. Here, for a commandline option with name -name, the option classes provide two functions with name name(): one that takes no argument and returns the current value of the option, and one that takes an argument of the listed type and sets the option to that value. If the commandline options contains a hyphen -, then the member function contain an underscore _ instead. For example, for the options -c-d, -a-d, and -d-l the member functions are named c_d(), a_d(), d_l().
The values for -threads are interpreted as described in Search options.
Note that all commanline options can also be used with a starting double hyphen -- instead of a single hyphen.
Invoking help. The only option for which no value exists is -help: it prints some configuration information and a help text for the options and stops program execution.
Size and instance options. The class SizeOptions accepts an unsigned integer as the last value on the commandline (of course, without an option). The value can be retrieved or set by member functions size().
The class InstanceOptions accepts a string as the last value on the commandline (of course, without an option). The value can be retrieved or set by member functions instance().
Integer propagation level options. The command line option -ipl accepts a comma separated list of the basic integer propagation levels: def for the default level, val for value propagation, bnd for bounds propagation, and dom for domain propagation. In addition it accepts the modifiers speed, memory, basic, and advanced that are used by some constraints and can be given in addition to a basic integer propagation level.
Mode options. The different modes passed as argument for the option -mode have the following meaning:
solutionprints solutions together with some runtime statistics.timecan be used for benchmarking: average runtime and coefficient of deviation is printed, where the example is run-samplestimes. For examples with short runtime,-iterationscan be used to repeat the example several times before measuring runtime. Note that the runtime includes also setup time (the creation of the space for the model).statprints short execution statistics.gistruns Gist rather than search engines that print information. Gist is put into depth-first mode, when a non best solution search engine is used (that is,DFS), and into branch-and-bound mode otherwise (that is,BAB).If Gecode has not been compiled with support for Gist (see How Gecode has been configured for how to find out about Gecode’s configuration), the mode
gistwill be ignored and the modesolutionis used instead.
Trace options. Which events to trace (see also Groups and tracing) can be specified by the -trace commandline option. It accepts a comma-separated list of the event types to trace, that is init, prune, fix for fixpoint, fail for failure, and done as well as none to trace no events and all to trace events of all types.
Examples with tracing include SEND+MORE=MONEY puzzle, Generating Hamming codes, and Folium of Descartes.
CPProfiler options. For more details on the CPProfiler, please consult Using the CPProfiler as the commandline arguments are used exactly as described there.
Examples. For an example, in particular, how to use the user-defined options, see Using the script commandline driver. As all examples that come with Gecode use the script commandline driver, a plethora of examples is available (see Example scripts (models)). Also adding additional options is straightforward, for an example see Golf tournament.
Gist inspectors and comparators. The driver options can pass inspectors and comparators (see Inspecting and comparing nodes) to Gist. To register an inspector i, use the inspect.click(&i), inspect.solution(&i), or inspect.move(&i) methods of the option object, for a comparator c, use inspect.compare(&c).
11.2. Scripts¶
Scripts (see Script classes) are subclasses of Space that are designed to work together with option objects of class Options and SizeOptions.
In particular, the driver module defines scripts IntMinimizeScript, IntMaximizeScript, IntLexMinimizeScript, IntLexMaximizeScript, FloatMinimizeScript, and FloatMaximizeScript that can be used for finding best solutions based on a virtual cost() function, see also Using a cost function and Support for cost-based optimization.
Subclasses of FloatMinimizeScript and FloatMaximizeScript use the value passed on the command line option -step as value for the improvement step (see Optimizing float cost with improvement step.). For an example, see Golden spiral.
As scripts are absolutely straightforward, all can be understood by following some examples. For an example see Using the script commandline driver or all examples that come with Gecode, see Example scripts (models).