mamut_routing_lib.td.bks¶
TD-aware best-known-solution helpers.
The generic :mod:mamut_routing_lib.bks helpers go through the static
check_solution, which refuses TD instances. These mirrors validate and
price candidates with the canonical TD checker (:func:check_td_solution)
instead. The objective defaults to :attr:ObjectiveFunction.DURATION;
families whose contract is :attr:ObjectiveFunction.FLEET_COST_DURATION
(Blauth2024) pass it explicitly. Either way the stored cost is always the
checker's canonical value.
create_td_bks_from_solution
¶
create_td_bks_from_solution(loaded: LoadedTDInstance | str | Path, solution: BenchmarkSolution, *, authors: str, metadata: dict[str, Any] | None = None, objective_function: ObjectiveFunction = ObjectiveFunction.DURATION) -> BenchmarkBKS
Validate solution with the TD checker and wrap it as a BKS.
The BKS cost is the checker's canonical value under
objective_function. If solution.cost is set, check_td_solution
itself rejects any deviation from that value (exact doubles, no
tolerance), so a solver that disagrees with the reference checker can
never write to the BKS store.
Source code in MAMUT-routing-tools/MAMUT-routing-lib/src/mamut_routing_lib/td/bks.py
save_td_solution_as_bks_if_improved
¶
save_td_solution_as_bks_if_improved(loaded: LoadedTDInstance | str | Path, solution: BenchmarkSolution, *, authors: str, metadata: dict[str, Any] | None = None, objective_function: ObjectiveFunction = ObjectiveFunction.DURATION) -> BKSUpdateResult
TD counterpart of save_solution_as_bks_if_improved.
The candidate and any stored BKS are both validated by the TD checker
under objective_function; the stored file is replaced only on a strict
improvement. Each objective has its own store file
(<Name>.bks.<Objective>.json). Accepts a :class:LoadedTDInstance
directly so callers that already hold the loaded instance (solvers, sweep
runners) avoid re-reading the ATF sidecar.
Source code in MAMUT-routing-tools/MAMUT-routing-lib/src/mamut_routing_lib/td/bks.py
annotate_td_bks_optimality
¶
annotate_td_bks_optimality(loaded: LoadedTDInstance | str | Path, optimality: OptimalityMetadata | dict[str, Any], objective_function: ObjectiveFunction = ObjectiveFunction.DURATION) -> Path
Stamp the stored BKS of loaded with an optimality proof.
The stored BKS (of objective_function's store file) is re-validated by
the TD checker before being rewritten with metadata["optimality"] set.
When the stamp declares a proven_optimum, it must match the stored
cost: an absolute difference beyond :data:OPTIMALITY_COST_TOLERANCE
raises, and a dust-level difference is accepted only when the stamp's
note explains it. Everything else in the stored file (routes, cost,
authorship, other metadata) is left untouched — the proof stamp records
who proved the solution optimal, which is independent of who found it.