API Referenceο
Module providing the Solver class to launch and monitor solver executions on XCSP3 instances.
It supports: - Managing solver options (time limit, seeds, solution limits, etc.) - Capturing solver outputs (objective values, assignments) - Enforcing timeouts - Building JSON or human-readable results - Displaying execution summaries with wall-clock and CPU times
- class xcsp.solver.solver.CheckStatus(value)ο
Bases:
EnumAn enumeration.
- INVALID = 'INVALID'ο
- NO_CHECK = 'NO CHECK'ο
- VALID = 'VALID'ο
- class xcsp.solver.solver.ResultStatusEnum(value)ο
Bases:
EnumEnum representing standard solver statuses such as SATISFIABLE, UNSATISFIABLE, UNKNOWN, and OPTIMUM FOUND.
- ERROR = 'ERROR'ο
- MEMOUT = 'MEMOUT'ο
- OPTIMUM = 'OPTIMUM FOUND'ο
- SATISFIABLE = 'SATISFIABLE'ο
- TIMEOUT = 'TIMEOUT'ο
- UNKNOWN = 'UNKNOWN'ο
- UNSATISFIABLE = 'UNSATISFIABLE'ο
- class xcsp.solver.solver.Solver(name, id_solver, version, command_line, options, alias=None)ο
Bases:
objectClass representing a solver execution context for an XCSP3 model. Allows setting solver options, running the solver, and capturing results.
- add_complementary_options(options)ο
Manually set additional command-line options for the solver.
This method replaces any previously set complementary options with the new list provided.
- Parameters:
options (list of str) β A list of additional command-line arguments to be passed to the solver.
- property aliasο
Return a list of aliases for the solver.
- all_solutions(activate: bool)ο
Enable or disable collecting all solutions found by the solver.
- Parameters:
activate (bool) β True to collect all solutions.
- static available_solvers() Dict[str, Solver]ο
Retrieve all available solvers installed in the system.
- Returns:
Mapping of name@version to Solver instances.
- Return type:
dict
- property cmdο
Return the base command line of the solver.
- static create_from_cli(args)ο
Create and configure a Solver instance based on parsed CLI arguments.
- Parameters:
args (dict) β CLI arguments parsed with argparse or similar.
- Returns:
Configured Solver instance.
- Return type:
- property idο
Return the solver ID.
- static lookup(name: str) Solverο
Retrieve a Solver instance by name and optional version.
- Parameters:
name (str) β Name or name@version of the solver.
- Returns:
The corresponding solver instance.
- Return type:
- Raises:
ValueError β If the solver is not found.
- property nameο
Return the name of the solver.
- objective_value()ο
- set_collect_intermediate_solutions(activate: bool)ο
Enable or disable collecting intermediate assignments during search.
- Parameters:
activate (bool) β True to collect intermediate solutions.
- set_delay(delay: int)ο
- set_error(error)ο
Set where to redirect standard error output (stderr).
- Parameters:
error (str or Path) β Either βstderrβ or a file path.
- set_is_timeout(is_timeout: bool)ο
Set whether the solver run was interrupted by a timeout.
- Parameters:
is_timeout (bool) β True if the run was interrupted by a timeout.
- set_json_output(activate)ο
Enable or disable JSON output mode instead of live printing.
- Parameters:
activate (bool) β True to generate JSON output.
- set_limit_number_of_solutions(limit: int | None)ο
Set the maximum number of solutions to retrieve.
- Parameters:
limit (int | None) β Maximum number of solutions, or None for unlimited.
- set_output(output)ο
Set where to redirect standard output (stdout).
- Parameters:
output (str or Path) β Either βstdoutβ or a file path.
- set_prefix(prefix)ο
Set a prefix to prepend to each line of solver output.
- Parameters:
prefix (str) β Prefix string.
- set_seed(seed: int | None)ο
Set the random seed for the solver.
- Parameters:
seed (int | None) β Random seed value.
- set_time_limit(time_limit: int | None)ο
Set the time limit (timeout) for the solver.
- Parameters:
time_limit (int | None) β Time limit in seconds, or None for unlimited.
- solve(instance_path, keep_solver_output=False, check=False, delay=5)ο
Launch and monitor the solver on the given instance.
Captures intermediate objectives and solutions, enforces a timeout, and returns parsed results.
- Parameters:
instance_path (str | Path) β Path to the XCSP3 instance file.
keep_solver_output (bool) β If True, solver stdout is printed live.
check (bool) β If True, checks the final solution using a solution checker.
- Returns:
A dictionary summarizing the solver run including solutions, bounds, times.
- Return type:
dict
- status() ResultStatusEnumο
- property versionο
Return the solver version.