Skip to content

mamut_routing_lib.td.checker

Time-dependent checking under the td-binary64-exact-v1 family profile.

TD_CHECKER_CONTRACT module-attribute

TD_CHECKER_CONTRACT = TD_PROFILE

TD_OBJECTIVES module-attribute

TD_OBJECTIVES = (
    ObjectiveFunction.DURATION,
    ObjectiveFunction.FLEET_COST_DURATION,
)

TDRouteEvaluation

Bases: BaseModel

Exact duration and earliest minimizing departure of one feasible route.

route instance-attribute

route: list[int]

feasible instance-attribute

feasible: bool

duration class-attribute instance-attribute

duration: Fraction | None = None

departure_time class-attribute instance-attribute

departure_time: Fraction | None = None

TDSolutionCheckResult

Bases: SolutionCheckResult

The checked solution and its route witnesses in canonical route order.

route_evaluations class-attribute instance-attribute

route_evaluations: list[TDRouteEvaluation] = []

compute_route_duration

compute_route_duration(
    instance: AnyTDBenchmarkInstance,
    atfs: InstanceATFs,
    route: list[int],
    *,
    backend: ExactBackend = "native",
) -> TDRouteEvaluation

Compute the minimum duration and earliest attaining departure of a single route.

Source code in MAMUT-routing-tools/MAMUT-routing-lib/src/mamut_routing_lib/td/checker.py
def compute_route_duration(
    instance: AnyTDBenchmarkInstance,
    atfs: InstanceATFs,
    route: list[int],
    *,
    backend: ExactBackend = "native",
) -> TDRouteEvaluation:
    """Compute the minimum duration and earliest attaining departure of a single route."""
    from mamut_routing_lib.exact_td import prepare_td

    checker = prepare_td(instance, atfs, backend=backend, objective_function=ObjectiveFunction.DURATION)
    try:
        witness = checker.route_timing(route)
    except ExactRouteError as error:
        if error.status not in (SolutionCheckStatus.TIME_WINDOW_VIOLATED, SolutionCheckStatus.ROUTE_TIMING_INFEASIBLE):
            raise
        return TDRouteEvaluation(route=route, feasible=False)
    return TDRouteEvaluation(route=route, feasible=True, duration=witness.duration, departure_time=witness.departure_time)

compute_solution_cost

compute_solution_cost(
    instance: AnyTDBenchmarkInstance,
    atfs: InstanceATFs,
    routes: list[list[int]],
    objective_function: ObjectiveFunction | None = None,
    *,
    backend: ExactBackend = "native",
) -> Fraction

Price a complete TD solution under its family's default objective or the specified objective.

Source code in MAMUT-routing-tools/MAMUT-routing-lib/src/mamut_routing_lib/td/checker.py
def compute_solution_cost(
    instance: AnyTDBenchmarkInstance,
    atfs: InstanceATFs,
    routes: list[list[int]],
    objective_function: ObjectiveFunction | None = None,
    *,
    backend: ExactBackend = "native",
) -> Fraction:
    """Price a complete TD solution under its family's default objective or the specified objective."""
    from mamut_routing_lib.exact_td import prepare_td

    return prepare_td(instance, atfs, backend=backend, objective_function=objective_function).evaluate(routes).cost

check_td_solution

check_td_solution(
    loaded: LoadedTDInstance,
    solution: BenchmarkSolution | BenchmarkBKS,
    objective_function: ObjectiveFunction | None = None,
    *,
    backend: ExactBackend = "native",
) -> TDSolutionCheckResult

Check the loaded TD solution with its family objective and the selected exact backend.

Source code in MAMUT-routing-tools/MAMUT-routing-lib/src/mamut_routing_lib/td/checker.py
def check_td_solution(
    loaded: LoadedTDInstance,
    solution: BenchmarkSolution | BenchmarkBKS,
    objective_function: ObjectiveFunction | None = None,
    *,
    backend: ExactBackend = "native",
) -> TDSolutionCheckResult:
    """Check the loaded TD solution with its family objective and the selected exact backend."""
    from mamut_routing_lib.solutions import _check_solution_model

    # A certified result asserts the identity of the on-disk edition. An ordinary
    # solution is evaluated directly on the supplied materialized operands.
    path = loaded.instance_path if isinstance(solution, BenchmarkBKS) and "standard" in solution.metadata else None
    return _check_solution_model(loaded.instance, path, loaded, solution, objective_function, backend)