mamut_routing_lib.checker¶
Check and price static routes under the family's binary64-exact-v1 profile.
SolutionCheckResult
¶
Bases: BaseModel
Checked route count, display cost and lossless exact evaluation for a valid solution.
A valid result carries a nonnegative num_routes. Its routing_cost
is present, except when exact_evaluation reports display_overflow:
the exact cost then has no finite binary64 display and routing_cost is
None. A solution that names another instance or declares another objective
is not checked at all. The checker raises ValueError for it instead of
returning a status.
is_valid
¶
make_invalid
classmethod
¶
A rejection with status and a human-readable error_message.
Source code in MAMUT-routing-lib/src/mamut_routing_lib/checker.py
make_valid
classmethod
¶
A valid result carrying the priced cost and route count.
Source code in MAMUT-routing-lib/src/mamut_routing_lib/checker.py
compute_route_cost
¶
compute_route_cost(
instance: LoadedStaticInstance,
route: list[int],
*,
backend: ExactBackend = "native",
) -> Fraction
Return the exact cost of the listed depot-to-depot arcs, including a partial tour.
Source code in MAMUT-routing-lib/src/mamut_routing_lib/checker.py
compute_solution_cost
¶
compute_solution_cost(
instance: LoadedStaticInstance,
solution_or_routes: BenchmarkSolution
| BenchmarkBKS
| list[list[int]],
*,
backend: ExactBackend = "native",
) -> Fraction
Sum the traversed arcs under binary64-exact-v1. Use check_solution to also check feasibility.
Source code in MAMUT-routing-lib/src/mamut_routing_lib/checker.py
canonical_route_order
¶
Routes sorted by their first customer: the canonical storage and summation order of every BKS.
Each route must be a nonempty list of positive integer customer ids, and no
customer may appear twice, so that the order is unique. An empty route list
is returned as is. Invalid input raises ValueError. This checks only the
shape of the routes, not their feasibility on an instance.
Source code in MAMUT-routing-lib/src/mamut_routing_lib/checker.py
shortest_decimal_cost_value
¶
Keep integers exact and interpret a float's shortest round-trip decimal spelling.
For example, the float 0.1 maps to 1/10. Multiple source decimal tokens can round to that same float, so the spelling alone cannot recover them.
Source code in MAMUT-routing-lib/src/mamut_routing_lib/checker.py
compute_shortest_decimal_solution_cost
¶
compute_shortest_decimal_solution_cost(
instance: LoadedStaticInstance,
solution_or_routes: BenchmarkSolution
| BenchmarkBKS
| list[list[int]],
) -> Fraction
Exact rational routing cost: the sum of shortest_decimal_cost_value over every arc, depot to depot.
Independent of route order and, on a symmetric matrix, of route direction. No feasibility check.
Source code in MAMUT-routing-lib/src/mamut_routing_lib/checker.py
check_solution
¶
check_solution(
instance: LoadedStaticInstance,
solution: BenchmarkSolution | BenchmarkBKS,
*,
backend: ExactBackend = "native",
objective_function: ObjectiveFunction | None = None,
instance_path: str | Path | None = None,
) -> SolutionCheckResult
Check an embedded static instance under binary64-exact-v1. Supply its path to verify a certified BKS.
Raises ValueError when the solution names another instance or declares
another objective, since no check status describes a mismatched submission.
Source code in MAMUT-routing-lib/src/mamut_routing_lib/checker.py
check_cvrp_solution
¶
check_cvrp_solution(
instance: BenchmarkInstanceCVRP,
solution: BenchmarkSolution | BenchmarkBKS,
*,
backend: ExactBackend = "native",
objective_function: ObjectiveFunction | None = None,
instance_path: str | Path | None = None,
) -> SolutionCheckResult
Check an embedded CVRP solution under the family profile.
Source code in MAMUT-routing-lib/src/mamut_routing_lib/checker.py
check_vrptw_solution
¶
check_vrptw_solution(
instance: BenchmarkInstanceVRPTW,
solution: BenchmarkSolution | BenchmarkBKS,
*,
backend: ExactBackend = "native",
objective_function: ObjectiveFunction | None = None,
instance_path: str | Path | None = None,
) -> SolutionCheckResult
Check an embedded VRPTW solution under the family profile.
Source code in MAMUT-routing-lib/src/mamut_routing_lib/checker.py
get_objective_tuple
¶
get_objective_tuple(
routes: list[list[int]],
cost: int | float | Fraction,
objective_function: ObjectiveFunction,
) -> tuple[int | float | Fraction, ...]
The comparison key of a solution under objective_function: (cost,) or (num_routes, cost) for the hierarchical objective.
Source code in MAMUT-routing-lib/src/mamut_routing_lib/checker.py
is_better_solution
¶
is_better_solution(
candidate_routes: list[list[int]],
candidate_cost: int | float | Fraction,
existing_routes: list[list[int]],
existing_cost: int | float | Fraction,
objective_function: ObjectiveFunction,
) -> bool
True when the candidate strictly precedes the existing solution under objective_function (see get_objective_tuple).
Pass the authoritative rational costs to compare under an exact family profile.
Source code in MAMUT-routing-lib/src/mamut_routing_lib/checker.py
is_better_exact
¶
is_better_exact(
candidate_routes: list[list[int]],
candidate_exact_cost: Fraction,
existing_routes: list[list[int]],
existing_exact_cost: Fraction,
objective_function: ObjectiveFunction,
) -> bool
Compare the given rational costs under the objective, retaining the incumbent on a tie.