Function: parseKnownParameters()
parseKnownParameters(
options?: {args:string[];defaults:Parameters;exitOnError:boolean;usage:string; }): [Parameters,string[]]
Parses OptalCP solver parameters from the command line, passing through unrecognized arguments.
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
[Parameters, string[]]
A tuple of the parsed parameters and an array of unrecognized arguments
Remarks
This function parses OptalCP solver parameters from the command line and returns both a Parameters object and an array of unrecognized arguments.
Instead of hardcoding solver settings like time limits or worker counts in your code,
you can let users configure them when running your application. This variant is
particularly useful when your application accepts its own arguments (like input file
names) alongside solver parameters. For example, running
node solve.js --timeLimit 120 input.txt would parse --timeLimit 120 as a solver
parameter and return input.txt as an unrecognized argument for your code to handle.
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 workers using --workerN. prefix.
For example, --worker0.searchType FDS sets the search type for the first worker only.
import * as cp from "@scheduleopt/optalcp";
// Parse solver parameters, collect input files as unrecognized args
const [params, inputFiles] = cp.parseKnownParameters({
defaults: { timeLimit: 60 },
usage: "Usage: node solve.js [OPTIONS] <input-file>..."
});
for (const file of inputFiles) {
const model = loadModel(file);
await model.solve(params);
}
See
- parseParameters for a stricter version that rejects unrecognized arguments.
- parseBenchmarkParameters, parseSomeBenchmarkParameters for parsing BenchmarkParameters.