State

State#

class State#

State wrapper for Python

__contains__(key: int) bool#
__copy__() State#
__deepcopy__(_memo: Any) State#
__len__() int#
__new__(entries: ToState) State#
__repr__() str#
from_v1_bytes(bytes: bytes) State#
get(key: int) Optional[float]#
items() list[tuple[int, float]]#
keys() list[int]#
load_qplib_solution(path: str, *, num_variables: int) State#

Load a published QPLIB .sol file into a State.

Pass the variable count of the original QPLIB instance as num_variables. Omitted variables receive zero. The standard QPLIB solution names xN, bN, and iN map to OMMX ID N - 2; objvar is ignored because the objective is computed by evaluate(). Custom names and other solvers' .sol formats are not supported. Names are case insensitive.

Malformed input, duplicate IDs, nonfinite values, and out-of-range IDs raise ValueError with a line number. File read failures raise RuntimeError. Loading does not check bounds or feasibility.

>>> import tempfile
>>> from pathlib import Path
>>> from ommx import State
>>> with tempfile.TemporaryDirectory() as directory:
...     path = Path(directory) / "example.sol"
...     _ = path.write_text("objvar 12\nx2 0.5\nb4 1\n")
...     state = State.load_qplib_solution(str(path), num_variables=3)
>>> state.entries
{0: 0.5, 1: 0.0, 2: 1.0}
set(key: int, value: float) None#
to_v1_bytes() bytes#
values() list[float]#
property entries: dict[int, float]#