Python API reference
This page documents the supported public Python API for JijZept Solver.
- solve(instance, *, options=None, time_limit=_UNSET, gap_limit=_UNSET, num_threads=_UNSET, presolve=_UNSET, verbosity=_UNSET, display_frequency=_UNSET, initial_state=None, structure=None)
Solve an OMMX optimization problem instance.
This function supports Ctrl+C interruption when running on the Python main thread. When interrupted, it returns the best solution found so far (feasible or infeasible, if any) with a warning, or raises KeyboardInterrupt if there is nothing to return. When called from a non-main thread (e.g. a server worker thread), the solver runs without SIGINT integration: it cannot be interrupted this way and runs until a limit is reached.
Option precedence, lowest to highest: solver defaults, the structure preset,
options, then the convenience arguments below. SeeSolveOptionsfor every available option.- Parameters:
instance (Any) – The OMMX Instance to solve.
options (jijzept_solver.core.SolveOptions | None) – SolveOptions with detailed solver settings (default None = solver defaults, or the structure preset when structure is set).
time_limit (float | None) – Time limit in seconds. Passing None explicitly selects “no time limit” (overriding options); omitted = no opinion (default: no time limit).
gap_limit (float) – Relative optimality gap tolerance, e.g. 0.01 for 1% (default 0.0001). None is not accepted.
num_threads (int | None) – Number of solver threads. Passing None explicitly selects automatic (overriding options); omitted = no opinion (default: automatic).
presolve (bool) – Enable presolve (default True; False when a TSP structure is set). None is not accepted.
verbosity (int) – Verbosity level: 0 = quiet, 1 = normal, 2 = verbose (default 1). None is not accepted.
display_frequency (int) – Display progress every N nodes, 0 = disabled (default 10). None is not accepted.
initial_state (Any) –
Optional initial solution as
ommx.v1.State(default None).Missing variables: filled with solver defaults (0 if in bounds, lower otherwise;
lower.ceil()for integers).Extra variables (not in the instance): silently ignored.
Out-of-bounds values: clamped.
* Recommendation: use a solution generated in the same environment * Presolve behavior (especially dual reductions) can vary across platforms (CPU architecture, OS, native library build). An initial_state created on one environment (e.g., a development machine) may not work effectively when used on another environment (e.g., a production machine), due to differences in presolve decisions between environments. To avoid this, when using initial_state, prefer using a solution generated by JijZept Solver in the same environment.
structure (jijzept_solver.core.Structure | None) – Structure describing problem structure (default None). Also applies the structure’s recommended option preset; values set in
optionsor passed explicitly override the preset.
- Returns:
The OMMX Solution. When no feasible solution was found within the limits, the best infeasible solution the solver encountered (smallest total constraint violation) is returned with
solution.feasible == False. Always checksolution.feasiblebefore using the values.- Raises:
KeyboardInterrupt – If interrupted by Ctrl+C before any solution (feasible or infeasible) was found. Ctrl+C interruption is available only when solve() runs on the Python main thread.
NoSolutionError – If the solver found no solution at all to return for the termination status. A subclass of RuntimeError; the termination status name is available as the
statusattribute (e.g."Infeasible","TimeLimit").RuntimeError – If an internal error occurs during solving.
ValueError – If the input instance or an option value is invalid.
- Return type:
Any
- class SolveOptions
Options for solve().
Every constructor argument defaults to None, meaning “not set”: the solver default is used, or the structure preset value when a structure is passed to solve(). Instances are immutable; derive modified copies with with_overrides.
Seven options default to “no limit” / “automatic”: time_limit, node_limit, solution_limit, num_threads, min_efficacy, max_cuts_per_round, and orthogonality_threshold. For these, passing None to with_overrides explicitly selects that behavior, overriding any value from a lower layer such as an options file.
- with_overrides(**kwargs)
Return a copy with the given options set on top of this object.
Keyword names and values match the constructor arguments. Passing None explicitly selects the unlimited/automatic behavior for time_limit, node_limit, solution_limit, num_threads, min_efficacy, max_cuts_per_round, orthogonality_threshold; None is rejected for every other option.
- Parameters:
kwargs (Any)
- Return type:
- to_dict(changed_only=False)
Return the options as a dict.
With changed_only=True only explicitly set options are included; otherwise every option appears with its effective value (the set value or the solver default). An explicit None (unlimited/automatic, set via with_overrides) is omitted from the changed_only dict, exactly as in a file written by to_file: it selects the same behavior as the default.
- Parameters:
changed_only (bool)
- Return type:
Any
- to_file(path)
Write the explicitly set options (only those) to a TOML file.
- Parameters:
path (str | os.PathLike | pathlib.Path)
- Return type:
None
- static from_file(path)
Load options from a TOML file.
- Parameters:
path (str | os.PathLike | pathlib.Path)
- Return type:
- static write_template(path)
Write a template TOML file listing every option with its default value.
- Parameters:
path (str | os.PathLike | pathlib.Path)
- Return type:
None
- class Structure
Structure of the optimization problem.
Used to automatically select solver strategies and register structural handlers.
- static tsp(var_name)
Create a TSP structure (Python factory method).
- static general(fixed_bases)
Create a General structure (Python factory method).
- class Tsp
The problem is a Travelling Salesman Problem.