Function: parseParameters()
parseParameters(
options?: {args:string[];defaults:Parameters;exitOnError:boolean;usage:string; }):Parameters
Implementation
Parameters
| Parameter | Type | Description |
|---|---|---|
options? | { args: string[]; defaults: Parameters; exitOnError: boolean; usage: string; } | - |
options.args? | string[] | Command-line arguments to parse. Defaults to process.argv.slice(2) |
options.defaults? | Parameters | Default parameter values. CLI arguments override these |
options.exitOnError? | boolean | If true (default), exits on error or --help. If false, throws an exception instead |
options.usage? | string | Custom usage text shown before the parameter list when --help is used |
Returns
The parsed parameters object
Remarks
This function parses OptalCP solver parameters from the command line and returns a Parameters object ready for use with Model.solve.
Instead of hardcoding solver settings like time limits or worker counts in your code,
you can let users configure them when running your application. For example, running
node solve.js --timeLimit 120 --nbWorkers 8 would override any defaults. This makes
your application flexible without requiring code changes for different scenarios.
The defaults option lets you specify sensible default values for your application.
When users don't provide a parameter on the command line, the default value is used.
By default (exitOnError: true), parse errors and --help/--optalcpVersion flags
cause the process to exit. Set exitOnError: false to throw exceptions instead.
If --help or -h is given, the function prints help starting with the usage
option (if provided), followed by the list of recognized parameters:
Help:
--help, -h Print this help
--optalcpVersion Print OptalCP version information
Solver path:
--solverPath string Path to the solver
Terminal output:
--color Never|Auto|Always Whether to colorize output to the terminal
Major options:
--nbWorkers uint32 Number of threads dedicated to search
--searchType LNS|FDS|FDSDual|SetTimes
Type of search to use
--randomSeed uint32 Random seed
--logLevel uint32 Level of the log
--warningLevel uint32 Level of warnings
--logPeriod double How often to print log messages (in seconds)
--verifySolutions bool When on, the correctness of solutions is verified
Limits:
--timeLimit double Wall clock limit for execution
--solutionLimit uint64 Stop the search after the given number of solutions
...
WorkerParameters can be specified for individual worker(s) using the following prefixes:
--workerN.or--workersN.for workerN--workerN-M.or--workersN-M.for workers in the rangeNtoM
For example:
--worker0.searchType FDSsets the search type for the first worker only.--workers4-8.noOverlapPropagationLevel 4sets the propagation level ofnoOverlapconstraint for workers 4, 5, 6, 7, and 8.
This function does not accept unrecognized arguments (they cause an error).
import * as cp from "@scheduleopt/optalcp";
// Parse with defaults that CLI can override
const params = cp.parseParameters({
defaults: { timeLimit: 60, nbWorkers: 4 },
usage: "Usage: node solve.js [OPTIONS] <input-file>\n\nSolve scheduling problem."
});
// Use parsed parameters
const result = await model.solve(params);
See
- parseKnownParameters to handle unrecognized arguments.
- parseBenchmarkParameters and parseSomeBenchmarkParameters for parsing benchmark parameters.