mamut_routing_lib.td¶
Time-dependent routing (TDVRPTW / TDVRP) contract and canonical checker.
See the TD benchmark standard in the MAMUT-routing repository for the format
specification: instance .vrp.json files reference an ATF sidecar
(.atf.json / .atf.json.gz) holding one arrival-time NDCPWLF per arc.
IGP_MATERIALIZER_GENERATOR
module-attribute
¶
TD_OBJECTIVES
module-attribute
¶
AnyTDBenchmarkInstance
module-attribute
¶
ROAD_MATERIALIZER_GENERATOR
module-attribute
¶
ATFChecksumError
¶
Bases: ATFFormatError
Raised when an ATF sidecar's canonical bytes do not match the expected sha256.
ATFFormatError
¶
Bases: ValueError
Raised when an ATF sidecar file violates the canonical format.
InstanceATFs
dataclass
¶
InstanceATFs(
instance_name: str,
benchmark_name: str,
horizon: tuple[float, float],
num_customers: int,
arcs: dict[tuple[int, int], NDCPWLF],
generator: dict[str, Any] = dict(),
format_version: int = ATF_FORMAT_VERSION,
)
In-memory content of an ATF sidecar file.
generator
class-attribute
instance-attribute
¶
LoadedTDInstance
dataclass
¶
LoadedTDInstance(
instance: AnyTDBenchmarkInstance,
atfs: InstanceATFs,
instance_path: Path,
atf_path: Path | None,
categories_path: Path | None = None,
road_graph_path: Path | None = None,
traffic_path: Path | None = None,
collection_root: Path | None = None,
)
A TD instance paired with its arrival-time functions.
atf_path is the on-disk ATF sidecar for atf-ndcpwlf instances and
None for the materialized models; categories_path
(igp-profile) and road_graph_path + traffic_path
(road-graph v2) point to the respective compact sidecars in the
materialized cases. collection_root is set for instances living in a
marker-rooted collection (road-graph sidecar paths resolve against it).
IGPFormatError
¶
Bases: ValueError
Raised when an IGP categories sidecar violates the canonical format.
InstanceCategories
dataclass
¶
InstanceCategories(
base_name: str,
benchmark_name: str,
num_customers: int,
num_categories: int,
categories: list[str],
generator: dict[str, Any] = dict(),
format_version: int = IGP_CATEGORIES_FORMAT_VERSION,
)
In-memory content of an IGP categories sidecar.
categories holds num_customers + 1 digit strings of the same
length; categories[i][j] is the category of arc (i, j). The matrix
is symmetric with a fixed '0' diagonal (self-arcs do not exist; the
value is never read).
TDRouteEvaluation
¶
Bases: BaseModel
Exact duration and earliest minimizing departure of one feasible route.
TDSolutionCheckResult
¶
Bases: SolutionCheckResult
The checked solution and its route witnesses in canonical route order.
route_evaluations
class-attribute
instance-attribute
¶
BenchmarkInstanceTDVRP
¶
Bases: _TDInstanceValidationMixin
BenchmarkInstanceTDVRPTW
¶
Bases: _TDInstanceValidationMixin
validate_time_window_lengths
classmethod
¶
Source code in MAMUT-routing-tools/MAMUT-routing-lib/src/mamut_routing_lib/td/models.py
TDArrivalFunctionsRef
¶
Bases: BaseModel
Reference to the ATF sidecar file of a TD instance.
atf_path is relative to the collection root for an instance inside a
collection, and to the directory containing the instance file otherwise.
atf_sha256 is computed over the uncompressed canonical JSON bytes of
the sidecar, so it is stable across .json and .json.gz storage.
validate_atf_path
classmethod
¶
TDIGPProfileRef
¶
Bases: BaseModel
Compact IGP (Ichoua-Gendreau-Potvin 2003) time-dependent travel model.
Instead of shipping a consolidated ATF sidecar, the instance stores the
IGP data that fully determines it: contiguous time_periods (stored
absolute floats are canonical — never recomputed), a strictly positive
speeds matrix (num_categories x num_periods; FIFO by
construction), and a reference to the arc-category sidecar. The canonical
ATFs are materialized deterministically on load
(mamut_routing_lib.td.igp); atf_sha256 pins the materialized
canonical ATF bytes exactly as it would for a committed sidecar. See the
TD benchmark standard and the Lera2026 family design note.
validate_categories_path
classmethod
¶
validate_time_periods
classmethod
¶
Source code in MAMUT-routing-tools/MAMUT-routing-lib/src/mamut_routing_lib/td/models.py
validate_speeds
classmethod
¶
Source code in MAMUT-routing-tools/MAMUT-routing-lib/src/mamut_routing_lib/td/models.py
TDRoadGraphRef
¶
Bases: BaseModel
Compact road-network time-dependent travel model (format v2).
The instance references two sidecars, both collection-root-relative
and sha-pinned: the static road graph shared by every traffic subinstance
of the base (<base>.road.json.gz: trimmed subgraph with per-edge
free-flow speed_limit and vertex coordinates) and one traffic overlay
(<base>.traffic-<model>-<intensity>.json.gz: per-edge 24-bin speeds
aligned with the graph's edge order, clamped at free-flow). The canonical
ATFs are materialized deterministically on load
(mamut_routing_lib.td.roadgraph): pinned Dijkstra over the static
free-flow times, exact per-edge arrival functions from the overlay
speeds sampled exactly along the pinned paths on a fixed departure grid,
then deterministic decimation. sample_step and simplify_tolerance
are the authoritative materialization parameters and must equal the
values recorded in the road sidecar. atf_sha256 pins the materialized
canonical ATF bytes exactly as it would for a committed sidecar. See the
TD benchmark standard (road-graph v2).
NDCPWLF
¶
A non-decreasing continuous piecewise linear function.
Immutable by convention: xs and ys must not be mutated after
construction.
Source code in MAMUT-routing-tools/MAMUT-routing-lib/src/mamut_routing_lib/td/pwlf.py
identity
classmethod
¶
The identity function over [low, high].
Source code in MAMUT-routing-tools/MAMUT-routing-lib/src/mamut_routing_lib/td/pwlf.py
empty
classmethod
¶
is_empty
¶
num_breakpoints
¶
evaluate
¶
Evaluate the function at x (must lie within the domain).
At a vertical step the smallest value is returned. slope_one_exact
selects the slope-one rule of the checker fold (module docstring).
Source code in MAMUT-routing-tools/MAMUT-routing-lib/src/mamut_routing_lib/td/pwlf.py
evaluate_exact
¶
Interpolate the materialized binary64 knots at a rational time, taking the first ordinate at a jump.
Source code in MAMUT-routing-tools/MAMUT-routing-lib/src/mamut_routing_lib/td/pwlf.py
compose
¶
Return h = self ∘ g restricted to {x in dom(g) : g(x) in dom(self)}.
Two-pointer event merge over the common value axis
dom(self) ∩ img(g); O(len(self.xs) + len(g.xs)). slope_one_exact
selects the slope-one rule of the checker fold for both the forward
interpolation of self and the inverse interpolation of g.
Source code in MAMUT-routing-tools/MAMUT-routing-lib/src/mamut_routing_lib/td/pwlf.py
min_shifted_image
¶
Return (min_k (ys[k] - xs[k]), xs[k*]) with k* the earliest argmin.
For a route ready-time function this is the optimal route duration and
the associated optimal depot departure time. The minimum of y - x
over the whole domain is attained at a breakpoint because the shifted
function is linear between breakpoints.
Source code in MAMUT-routing-tools/MAMUT-routing-lib/src/mamut_routing_lib/td/pwlf.py
PWLFError
¶
Bases: ValueError
Raised when NDCPWLF invariants are violated.
InstanceRoadGraph
dataclass
¶
InstanceRoadGraph(
base_name: str,
benchmark_name: str,
num_customers: int,
horizon: tuple[float, float],
extension_end: float,
bin_edges: list[float],
sample_step: float,
simplify_tolerance: float,
num_vertices: int,
vertex_osm_ids: list[int],
vertex_lonlat: list[tuple[float, float]],
node_vertices: list[int],
edges: list[tuple[int, int, float, float]],
generator: dict[str, Any] = dict(),
format_version: int = ROAD_GRAPH_FORMAT_VERSION,
)
In-memory content of a road-graph sidecar (format v2).
Vertices are 0 .. num_vertices - 1; vertex_osm_ids[v] records the
originating OSM node id of vertex v (strictly increasing — vertices
are numbered in ascending OSM-id order, informative only);
vertex_lonlat[v] is its WGS84 (lon, lat) position (informative
only: rendering and heatmaps, never read by the materialization).
edges holds [u, v, length_m, speed_limit] entries sorted strictly
increasing by (u, v) (directed, no parallel edges); speed_limit is
the static free-flow limit (m-per-time-unit in the instance's units,
strictly positive) defining the pinned Dijkstra weight
length / speed_limit. node_vertices[i] is the graph vertex of
instance node i (depot first, all distinct). sample_step is the
departure-grid spacing and simplify_tolerance the decimation
tolerance of the pinned materialization; both are canonical (hashed)
materialization parameters, repeated in the instance td block and
cross-checked at load.
generator
class-attribute
instance-attribute
¶
RoadGraphFormatError
¶
Bases: ValueError
Raised when a road-graph or traffic-overlay sidecar violates the canonical format.
TrafficOverlay
dataclass
¶
TrafficOverlay(
base_name: str,
benchmark_name: str,
traffic_model: str,
intensity: str,
bin_edges: list[float],
edge_speeds: list[list[float]],
generator: dict[str, Any] = dict(),
format_version: int = TRAFFIC_OVERLAY_FORMAT_VERSION,
)
In-memory content of a traffic-overlay sidecar.
edge_speeds[k] is the per-bin speed row of edge k of the base's
road-graph sidecar (same order, same count); every speed is strictly
positive (FIFO by construction) and at most the edge's static
speed_limit (validated against the road graph: overlays are slowdowns
by contract). bin_edges must equal the road sidecar's bit-exactly.
atf_file_sha256
¶
sha256 of a sidecar's uncompressed bytes, streamed (no JSON parsing).
Equals the instance's atf_sha256 when the file holds the canonical
bytes (every file written by save_instance_atfs). A truncated or
corrupt gzip raises (EOFError, zlib.error or OSError).
Source code in MAMUT-routing-tools/MAMUT-routing-lib/src/mamut_routing_lib/td/artifacts.py
atfs_to_canonical_json_bytes
¶
Serialize to the canonical JSON bytes (the input of atf_sha256).
Fixed key order, one arc per line. Horizon bounds and knot coordinates use Python's shortest binary64 round-trip representation.
Source code in MAMUT-routing-tools/MAMUT-routing-lib/src/mamut_routing_lib/td/artifacts.py
compute_atf_sha256
¶
get_atf_path_for_instance
¶
get_atf_path_for_instance(
instance_path: str | Path,
atf_path: str | None = None,
*,
collection_root: str | Path | None = None,
) -> Path
Resolve the ATF sidecar of an instance file.
When atf_path (from the instance's td block) is given it is
resolved against the collection root for an instance inside a collection,
and against the instance directory for a loose file
(sidecars.sidecar_base_dir); otherwise the conventional sibling names
are probed (plain first, then gzip).
Source code in MAMUT-routing-tools/MAMUT-routing-lib/src/mamut_routing_lib/td/artifacts.py
load_instance_atfs
¶
load_instance_atfs(
path: str | Path,
*,
validate_complete: bool = True,
expected_sha256: str | None = None,
) -> InstanceATFs
Load a sidecar; with expected_sha256 its uncompressed bytes must hash to it (ATFChecksumError).
Source code in MAMUT-routing-tools/MAMUT-routing-lib/src/mamut_routing_lib/td/artifacts.py
load_td_benchmark_instance
¶
Load and validate the instance file only (no sidecar).
Source code in MAMUT-routing-tools/MAMUT-routing-lib/src/mamut_routing_lib/td/artifacts.py
load_td_instance
¶
load_td_instance(
instance_path: str | Path,
*,
verify_sha256: bool = True,
validate_complete: bool = True,
collection_root: str | Path | None = None,
) -> LoadedTDInstance
Load instance + sidecar, checking their mutual consistency.
For igp-profile and road-graph instances the ATFs are
materialized deterministically from the td block and the compact
sidecar(s); verify_sha256 then covers both the sidecar hashes (cheap)
and atf_sha256 (a full canonical serialization of the materialized
ATFs -- minutes at n=1000; pass verify_sha256=False in solver hot
paths, materialization is deterministic either way). Inside a collection,
every sidecar path is collection-root-relative: the root is found by
walking up to the mamut-collection.json marker, or passed explicitly
via collection_root. A loose atf-ndcpwlf or igp-profile
instance (no marker above it) reads its sidecar next to the instance
file; road-graph instances always need a collection.
Source code in MAMUT-routing-tools/MAMUT-routing-lib/src/mamut_routing_lib/td/artifacts.py
save_instance_atfs
¶
Write the sidecar atomically; gzip iff the path ends with .atf.json.gz.
Source code in MAMUT-routing-tools/MAMUT-routing-lib/src/mamut_routing_lib/td/artifacts.py
td_instance_from_payload
¶
Source code in MAMUT-routing-tools/MAMUT-routing-lib/src/mamut_routing_lib/td/artifacts.py
annotate_td_bks_optimality
¶
annotate_td_bks_optimality(
loaded: LoadedTDInstance | str | Path,
optimality: SolverReportedOptimality | dict[str, Any],
objective_function: ObjectiveFunction | None = None,
*,
backend: str = "native",
) -> Path
Attach a solver claim of optimality to the existing incumbent under the declared objective.
The claim must be a SolverReportedOptimality whose target_profile is the
TD profile, and the incumbent must carry an exact evaluation that still verifies.
The legacy proven: true stamp is refused. Reported bounds do not certify the incumbent.
Source code in MAMUT-routing-tools/MAMUT-routing-lib/src/mamut_routing_lib/td/bks.py
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 | None = None,
backend: str = "native",
) -> BenchmarkBKS
Price a candidate, check any declared cost and bind exact witnesses to canonical routes.
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 | None = None,
backend: str = "native",
) -> BKSUpdateResult
Re-evaluate both route sets and store only a strict exact improvement.
A legacy incumbent keeps its original bytes on ties and worse proposals. Replacing an incumbent with a claim first archives its original record. Writers serialize per instance.
Source code in MAMUT-routing-tools/MAMUT-routing-lib/src/mamut_routing_lib/td/bks.py
build_arc_atf
¶
Exact PWL arrival function: breakpoints at every zone-boundary crossing.
Zone bounds are coerced to floats: canonical ATF breakpoints must be
serialized as JSON floats (1080.0), and integer zone bounds would
otherwise leak python ints into xs and break the write/reload sha256
round-trip (1080 vs 1080.0).
Source code in MAMUT-routing-tools/MAMUT-routing-lib/src/mamut_routing_lib/td/igp.py
categories_to_canonical_json_bytes
¶
Serialize to the canonical JSON bytes (the input of categories_sha256).
Fixed key order, one category row per line, gzip-independent.
Source code in MAMUT-routing-tools/MAMUT-routing-lib/src/mamut_routing_lib/td/igp.py
compute_categories_sha256
¶
euclidean_distance
¶
Canonical distance of the igp-profile model: sqrt(dx*dx + dy*dy).
IEEE-754 binary64 with correctly rounded sqrt -- fully deterministic,
and bit-identical to the stored Sintef2008 arc_costs on integer G&H
coordinates.
Source code in MAMUT-routing-tools/MAMUT-routing-lib/src/mamut_routing_lib/td/igp.py
ichoua_travel_time
¶
Exact forward IGP loop; last-zone speed extended beyond the horizon.
Source code in MAMUT-routing-tools/MAMUT-routing-lib/src/mamut_routing_lib/td/igp.py
load_instance_categories
¶
Source code in MAMUT-routing-tools/MAMUT-routing-lib/src/mamut_routing_lib/td/igp.py
materialize_instance_atfs
¶
materialize_instance_atfs(
instance: AnyTDBenchmarkInstance,
categories: InstanceCategories,
) -> "InstanceATFs"
Build the canonical complete-graph InstanceATFs of an igp-profile instance.
Source code in MAMUT-routing-tools/MAMUT-routing-lib/src/mamut_routing_lib/td/igp.py
save_instance_categories
¶
Write the sidecar; gzip iff the path ends with .igp.json.gz (mtime=0).
Source code in MAMUT-routing-tools/MAMUT-routing-lib/src/mamut_routing_lib/td/igp.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-tools/MAMUT-routing-lib/src/mamut_routing_lib/checker.py
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
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
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
apply_ready_time
¶
apply_ready_time(
acc: NDCPWLF,
*,
earliest: float | None,
latest: float | None,
service_time: float,
slope_one_exact: bool = True,
) -> NDCPWLF
Apply the vertex map t -> max(t, earliest) + service_time to the image of acc.
This is the exact form of θ ∘ acc used by the checker fold
(td-fold/2). acc maps depot departure times to arrival times at the
vertex; the result maps them to ready times. Specification, over the
breakpoints (x_k, y_k) of acc in order:
- each kept breakpoint becomes
(x_k, max(y_k, earliest) + service_time)(plain float operations, no interpolation); - where a piece strictly crosses
earliest(y_{k-1} < earliest < y_k) the crossing(x*, earliest + service_time)is inserted,x*being the piece's inverse interpolation atearliest; - at the first
y_k > latestthe fold stops, after inserting the crossing(x*, latest + service_time)wheny_{k-1} < latest; a piece that crosses both bounds emits theearliestcrossing first. If alreadyy_0 > latestthe result is empty (time-window violation); - emission is clamped monotone and exact duplicates are dropped.
earliest=None means no waiting (TDVRP vertices); latest=None means
no due-date cut. The depot's return cut is
apply_ready_time(acc, earliest=None, latest=due, service_time=0.0).
Source code in MAMUT-routing-tools/MAMUT-routing-lib/src/mamut_routing_lib/td/pwlf.py
make_service_theta
¶
Vertex ready-time function θ without a time window, over [0, upper].
θ(t) = t + service_time, no waiting. upper is the largest arrival
time the vertex can see. It shares the dedup of make_theta, so
upper == 0 yields the single point ([0.0], [service_time]) instead
of two equal consecutive points.
Source code in MAMUT-routing-tools/MAMUT-routing-lib/src/mamut_routing_lib/td/pwlf.py
make_theta
¶
Vertex TW ready-time function θ over arrival times in [0, latest].
θ(t) = max(t, earliest) + service_time: arriving before earliest
waits (plateau), arriving after latest is infeasible (out of domain).
The checker no longer composes θ (contract td-fold/2): it applies the
same map exactly with :func:apply_ready_time. θ stays available as the
reference definition of the vertex transform.
Source code in MAMUT-routing-tools/MAMUT-routing-lib/src/mamut_routing_lib/td/pwlf.py
restrict_domain
¶
Restrict f to [low, high] ∩ dom(f) (checker fold, td-fold/2).
Replaces f.compose(NDCPWLF.identity(low, high)): every breakpoint of
f inside the window is kept verbatim (both points of a step at a window
end included), and a window end that falls strictly inside a piece is
evaluated there. Returns the empty function when the window misses the
domain.
Source code in MAMUT-routing-tools/MAMUT-routing-lib/src/mamut_routing_lib/td/pwlf.py
build_adjacency
¶
Outgoing edge indices per vertex, in edge-list (sorted (u, v)) order.
Source code in MAMUT-routing-tools/MAMUT-routing-lib/src/mamut_routing_lib/td/roadgraph.py
compute_fastest_path_tree
¶
compute_fastest_path_tree(
road: InstanceRoadGraph,
adjacency: list[list[int]],
source_vertex: int,
) -> tuple[list[float], list[int]]
Pinned Dijkstra over static free-flow times from source_vertex.
Free-flow edge weight is length / speed_limit: a property of the
base's road graph, independent of any traffic overlay. Determinism is
pinned end to end: the heap orders (distance, vertex) tuples (total
order, so equal-distance pops resolve by vertex id), outgoing edges relax
in edge-list order, and labels update on strict < only — the first
fastest path found is canonical. Returns (dist, pred_edge) where
pred_edge[v] is the index into road.edges of the tree edge
entering v (-1 at the source and at unreachable vertices).
Source code in MAMUT-routing-tools/MAMUT-routing-lib/src/mamut_routing_lib/td/roadgraph.py
compute_road_graph_sha256
¶
compute_traffic_overlay_sha256
¶
free_flow_node_times
¶
Free-flow fastest travel times between all instance nodes.
One pinned Dijkstra per node; entry [i][j] is the free-flow time from
node i to node j (0.0 on the diagonal). This is the reference the
published distances-fastest sidecar must match (after the family's
rounding convention); this is the generation gate of the Poryos2026 collection.
Source code in MAMUT-routing-tools/MAMUT-routing-lib/src/mamut_routing_lib/td/roadgraph.py
load_instance_road_graph
¶
Source code in MAMUT-routing-tools/MAMUT-routing-lib/src/mamut_routing_lib/td/roadgraph.py
load_traffic_overlay
¶
Source code in MAMUT-routing-tools/MAMUT-routing-lib/src/mamut_routing_lib/td/roadgraph.py
materialize_instance_atfs_roadgraph
¶
materialize_instance_atfs_roadgraph(
instance: AnyTDBenchmarkInstance,
road: InstanceRoadGraph,
overlay: TrafficOverlay,
) -> "InstanceATFs"
Build the canonical complete-graph InstanceATFs of a road-graph instance.
Pinned fastest paths come from the road graph's static free-flow limits (shared by every subinstance of the base); per-edge arrival functions come from the overlay's bin speeds. One pinned Dijkstra per instance node, then per-arc ATFs by exact grid sampling: the departure grid is propagated down the fastest-path tree (arrival vectors memoized per tree vertex), each target's samples are decimated (exact-collinear drop, then Douglas-Peucker with the pinned tolerance), and the kept subset of exact samples becomes the arc ATF.
Source code in MAMUT-routing-tools/MAMUT-routing-lib/src/mamut_routing_lib/td/roadgraph.py
678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 | |
materialize_selected_atfs_roadgraph
¶
materialize_selected_atfs_roadgraph(
instance: AnyTDBenchmarkInstance,
road: InstanceRoadGraph,
overlay: TrafficOverlay,
selected_arcs: set[tuple[int, int]],
) -> dict[tuple[int, int], NDCPWLF]
Materialize only selected complete-graph arcs with canonical semantics.
This is the sparse counterpart of :func:materialize_instance_atfs_roadgraph.
It uses the same pinned paths, departure grid, edge evaluation and
simplification, but avoids constructing the quadratic matrix when a
generation audit needs only the arcs of a route certificate.
Source code in MAMUT-routing-tools/MAMUT-routing-lib/src/mamut_routing_lib/td/roadgraph.py
793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 | |
road_graph_to_canonical_json_bytes
¶
Serialize to the canonical JSON bytes (the input of the graph sha256).
Fixed key order, one edge / one vertex coordinate pair per line, floats via Python's shortest round-trip repr, gzip-independent.
Source code in MAMUT-routing-tools/MAMUT-routing-lib/src/mamut_routing_lib/td/roadgraph.py
save_instance_road_graph
¶
Write the sidecar; gzip iff the path ends with .road.json.gz (mtime=0).
Source code in MAMUT-routing-tools/MAMUT-routing-lib/src/mamut_routing_lib/td/roadgraph.py
save_traffic_overlay
¶
Write the overlay; gzip iff the path ends with .json.gz (mtime=0).
The conventional name is <base>.traffic-<model>-<intensity>.json[.gz];
the .traffic- infix is required so overlays are never confused with
other sidecars.
Source code in MAMUT-routing-tools/MAMUT-routing-lib/src/mamut_routing_lib/td/roadgraph.py
simplify_ndcpwlf
¶
Deterministic Douglas-Peucker simplification of an NDCPWLF.
Keeps a subset of the original breakpoints (endpoints always kept), so
the result is non-decreasing and continuous by construction and every
kept breakpoint keeps ys >= xs. Interior breakpoints are dropped when
their vertical deviation from the chord of the enclosing kept pair is
<= tolerance; the split point is the deviation argmax, ties broken by
the smallest index. A vertical step strictly inside a kept pair may be
smoothed like any other breakpoint (its deviation is bounded the same
way); only when the kept pair itself is a pure vertical run (equal
x) is chord interpolation undefined and the run kept whole.
Source code in MAMUT-routing-tools/MAMUT-routing-lib/src/mamut_routing_lib/td/roadgraph.py
traffic_overlay_to_canonical_json_bytes
¶
Serialize to the canonical JSON bytes (the input of the traffic sha256).
Source code in MAMUT-routing-tools/MAMUT-routing-lib/src/mamut_routing_lib/td/roadgraph.py
validate_overlay_against_road
¶
The alignment contract between a traffic overlay and its base road graph.