Skip to main content

Function: parseParameters()

parseParameters(options?: { args: string[]; defaults: Parameters; exitOnError: boolean; usage: string; }): Parameters

Implementation

Parameters

ParameterTypeDescription
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?ParametersDefault parameter values. CLI arguments override these
options.exitOnError?booleanIf true (default), exits on error or --help. If false, throws an exception instead
options.usage?stringCustom usage text shown before the parameter list when --help is used

Returns

Parameters

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:

WorkerParameters can be specified for individual worker(s) using the following prefixes:

  • --workerN. or --workersN. for worker N
  • --workerN-M. or --workersN-M. for workers in the range N to M

For example:

  • --worker0.searchType FDS sets the search type for the first worker only.
  • --workers4-8.noOverlapPropagationLevel 4 sets the propagation level of noOverlap constraint 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