mamut_routing_lib.bks¶
Reprice and store static incumbents using the exact binary64 objective.
An existing record keeps its place on an exact tie. Historical displayed costs can come from earlier arithmetic rules, so compare their submitted routes again on the current instance. Callers serialize writers per instance.
DEFAULT_BKS_AUTHORS
module-attribute
¶
BKSUpdateAction
module-attribute
¶
What a store write did: wrote a first record, replaced a worse one, or kept the incumbent.
BKSPreviewAction
module-attribute
¶
BKSPreviewAction = Literal[
"would_create",
"would_replace",
"would_keep",
"invalid",
"stored_invalid",
]
What preview_bks_update reports a store write would do, without writing.
BKSUpdateResult
dataclass
¶
BKSUpdateResult(
action: BKSUpdateAction,
path: Path,
previous_path: Path | None,
candidate_cost: int | float | None,
candidate_num_routes: int,
tie: bool = False,
)
The candidate's display cost and route count, even when the incumbent wins.
A display overflow gives None. If an incumbent existed, previous_path is
its store path, including when that path now holds the replacement.
previous_path therefore does not identify a backup of the replaced
record. Only an incumbent that carries an optimality claim is archived,
under .bks-history/ next to it. Any other replaced record is gone.
create_bks_from_solution
¶
create_bks_from_solution(
instance: LoadedStaticInstance,
solution: BenchmarkSolution,
objective_function: ObjectiveFunction,
*,
authors: str,
metadata: dict[str, Any] | None = None,
backend: ExactBackend = "native",
) -> BenchmarkBKS
Create a canonical exact BKS from a solution and a materialized instance.
Source code in MAMUT-routing-lib/src/mamut_routing_lib/bks.py
save_bks_if_improved
¶
save_bks_if_improved(
instance: LoadedStaticInstance,
candidate_bks: BenchmarkBKS,
instance_path: str | Path,
*,
backend: ExactBackend = "native",
) -> BKSUpdateResult
Recheck the candidate and incumbent and replace only on a strict improvement.
Without a manifest, the supplied instance must equal the descriptor (and its
hydrated matrix) stored at instance_path. Otherwise this raises ValueError.
Source code in MAMUT-routing-lib/src/mamut_routing_lib/bks.py
save_solution_as_bks_if_improved
¶
save_solution_as_bks_if_improved(
instance_path: str | Path,
objective_function: ObjectiveFunction,
solution: BenchmarkSolution,
*,
authors: str,
metadata: dict[str, Any] | None = None,
backend: ExactBackend = "native",
supplied_checkable: LoadedStaticInstance | None = None,
) -> BKSUpdateResult
Load and prepare the instance once, check both submissions and store the winner.