Skip to content

mamut_routing_lib.solvers.external.descriptor

Declarative description of an external solver executable.

A descriptor says how to call a solver (argv template), what it reads and writes, its numeric limits and its capabilities; ExternalSolver does the rest. Built-ins live in catalog; users add or override descriptors in the solvers config (config).

argv placeholders: {executable} (absolute path: the native executable, or the script of a runtime = "python" solver), {java}, {jar}, {python} (this interpreter), {problem}, {params}, {solution}, {workdir} (absolute paths), {seed}, {time_limit_s} (30 or 12.5), {time_limit_int} (whole seconds, at least 1), {vehicles}. fleet_args are appended (formatted) when the instance has a fixed fleet, then extra_args -- except with input_format = "lkh", where extra_args are literal lines appended to the parameter file, whatever the argv. Such a line cannot set a parameter that the runner writes for the run (the files, the seed, the time limit, the precision): the descriptor is refused.

id_convention says how a cvrplib-sol solution file numbers its stops. It is declared, not guessed: a file Route #1: 0 1 2 for 3 customers is complete if customers are numbered from 0, and misses customer 3 if they are numbered from 1 with the depot written as 0.

InputFormat module-attribute

InputFormat = Literal[
    "cvrplib-x", "cvrplib-matrix", "cvrplib-explicit", "lkh"
]

OutputFormat module-attribute

OutputFormat = Literal['cvrplib-sol', 'lkh-mtsp']

ExternalSolverDescriptor dataclass

ExternalSolverDescriptor(
    name: str,
    label: str,
    method: str,
    argv: tuple[str, ...],
    input_format: InputFormat,
    output_format: OutputFormat,
    capabilities: SolverCapabilities,
    executable: str | None = None,
    executable_names: tuple[str, ...] = (),
    runtime: Literal["native", "java", "python"] = "native",
    jar: str | None = None,
    java: str = "java",
    java_options: tuple[str, ...] = (),
    solution_file: str = "solution.sol",
    distance_model: Literal[
        "float", "nint", "integer"
    ] = "float",
    coordinate_scales: tuple[float, ...] = (1.0,),
    matrix_scales: tuple[float, ...] = (
        1.0,
        0.1,
        0.01,
        0.001,
    ),
    limits: Limits = Limits(),
    require_exact_scale: bool = False,
    fleet_args: tuple[str, ...] = (),
    extra_args: tuple[str, ...] = (),
    vehicles_factor: float = 1.2,
    vrptw_vehicles_factor: float = 2.0,
    timeout_grace_s: float = 30.0,
    timeout_grace_fraction: float = 0.1,
    term_grace_s: float = 2.0,
    progress_pattern: str | None = None,
    version: str | None = None,
    env: Mapping[str, str] = dict(),
    requires_note: str | None = None,
    homepage: str | None = None,
    source: str = "builtin",
    *,
    id_convention: IdConvention = "one-based",
)

name instance-attribute

name: str

label instance-attribute

label: str

method instance-attribute

method: str

argv instance-attribute

argv: tuple[str, ...]

input_format instance-attribute

input_format: InputFormat

output_format instance-attribute

output_format: OutputFormat

capabilities instance-attribute

capabilities: SolverCapabilities

executable class-attribute instance-attribute

executable: str | None = None

executable_names class-attribute instance-attribute

executable_names: tuple[str, ...] = ()

runtime class-attribute instance-attribute

runtime: Literal['native', 'java', 'python'] = 'native'

jar class-attribute instance-attribute

jar: str | None = None

java class-attribute instance-attribute

java: str = 'java'

java_options class-attribute instance-attribute

java_options: tuple[str, ...] = ()

solution_file class-attribute instance-attribute

solution_file: str = 'solution.sol'

id_convention class-attribute instance-attribute

id_convention: IdConvention = field(
    default="one-based", kw_only=True
)

distance_model class-attribute instance-attribute

distance_model: Literal["float", "nint", "integer"] = (
    "float"
)

coordinate_scales class-attribute instance-attribute

coordinate_scales: tuple[float, ...] = (1.0,)

matrix_scales class-attribute instance-attribute

matrix_scales: tuple[float, ...] = (1.0, 0.1, 0.01, 0.001)

limits class-attribute instance-attribute

limits: Limits = field(default_factory=Limits)

require_exact_scale class-attribute instance-attribute

require_exact_scale: bool = False

fleet_args class-attribute instance-attribute

fleet_args: tuple[str, ...] = ()

extra_args class-attribute instance-attribute

extra_args: tuple[str, ...] = ()

vehicles_factor class-attribute instance-attribute

vehicles_factor: float = 1.2

vrptw_vehicles_factor class-attribute instance-attribute

vrptw_vehicles_factor: float = 2.0

timeout_grace_s class-attribute instance-attribute

timeout_grace_s: float = 30.0

timeout_grace_fraction class-attribute instance-attribute

timeout_grace_fraction: float = 0.1

term_grace_s class-attribute instance-attribute

term_grace_s: float = 2.0

progress_pattern class-attribute instance-attribute

progress_pattern: str | None = None

version class-attribute instance-attribute

version: str | None = None

env class-attribute instance-attribute

env: Mapping[str, str] = field(default_factory=dict)

requires_note class-attribute instance-attribute

requires_note: str | None = None

homepage class-attribute instance-attribute

homepage: str | None = None

source class-attribute instance-attribute

source: str = 'builtin'

with_overrides

with_overrides(**values: Any) -> 'ExternalSolverDescriptor'
Source code in MAMUT-routing-lib/src/mamut_routing_lib/solvers/external/descriptor.py
def with_overrides(self, **values: Any) -> "ExternalSolverDescriptor":
    return replace(self, **values)

to_json

to_json() -> dict[str, Any]
Source code in MAMUT-routing-lib/src/mamut_routing_lib/solvers/external/descriptor.py
def to_json(self) -> dict[str, Any]:
    data = asdict(self)
    data["capabilities"] = self.capabilities.to_json()
    data["limits"] = {key: value for key, value in asdict(self.limits).items() if value is not None}
    data["env"] = dict(self.env)
    return data

sha256

sha256() -> str

Hash of everything that shapes a run (not the source label).

Source code in MAMUT-routing-lib/src/mamut_routing_lib/solvers/external/descriptor.py
def sha256(self) -> str:
    """Hash of everything that shapes a run (not the source label)."""
    payload = {key: value for key, value in self.to_json().items() if key != "source"}
    return hashlib.sha256(json.dumps(payload, sort_keys=True, default=str).encode()).hexdigest()