mamut_routing_lib.td.roadgraph¶
Road-network engine for the road-graph td model (format v2).
Format v2 splits the v1 monolithic sidecar in two, mirroring the base / subinstance structure of the Poryos2026 family:
-
The road-graph sidecar (
<base>.road.json[.gz], formatmamut-road-graphv2), one per base instance: the trimmed road subgraph every traffic subinstance lives on — directed edges with a physical length and a static free-flowspeed_limit(the pinned Dijkstra weight islength / speed_limit, so the trim and the pinned paths are properties of the base, independent of traffic),vertex_lonlatWGS84 coordinates (route polylines and traffic heatmaps are derivable from published data alone), and the instance-node -> graph-vertex mapping. -
The traffic overlay sidecar (
<base>.traffic-<model>-<intensity>.json[.gz], formatmamut-traffic-overlay), one per subinstance: per-edge piecewise- constant speeds over the horizon bins, rows aligned with the road sidecar's edge order, strictly positive (FIFO by construction) and clamped at the edge's free-flow limit (overlays are slowdowns by contract).
Both are hashed over their uncompressed canonical JSON bytes like every other TD sidecar. The pinned deterministic materialization is unchanged from the M12.1 sampling spec:
- a tie-break-pinned Dijkstra over static free-flow times
(
compute_fastest_path_tree) fixing one canonical fastest path per ordered vertex pair, shared by all subinstances of the base; - exact per-edge arrival functions from the overlay speeds (
build_arc_atfreused from the IGP engine with the bins as speed zones, extended toextension_end); - exact grid sampling along the fastest-path tree: a fixed departure grid
(
sample_stepspacing over the horizon) is propagated down the tree by evaluating each edge ATF at the parent's arrival values, so every sample is the exact arrival of the exact edge-by-edge composition — pointwise error cannot accumulate along the path; - deterministic decimation of the sampled arc function: one simultaneous drop
of interior points exactly collinear with their original neighbours, then
Douglas-Peucker simplification with
simplify_tolerance(simplify_ndcpwlfspec). Kept points are a subset of the exact samples, so the result is non-decreasing (FIFO) andys >= xsstructurally, and it spans exactly the horizon.
Every step is plain IEEE-754 double arithmetic on the stored floats with no epsilon comparisons, so the result is a pure function of the two sidecars' content. An optional numpy fast path evaluates the same formulas elementwise and is required to be bit-identical to the pure-Python reference (gate-tested); materialization therefore does not depend on whether numpy is installed.
ROAD_MATERIALIZER_GENERATOR
module-attribute
¶
RoadGraphFormatError
¶
Bases: ValueError
Raised when a road-graph or traffic-overlay sidecar violates the canonical format.
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
¶
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.
departure_grid
¶
The pinned departure grid: start + k * sample_step up to the horizon end.
sample_step must tile the horizon exactly (the computed endpoint must
equal the horizon end bit-for-bit), so the grid spans the horizon and the
materialized arc functions inherit exact horizon endpoints.
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.
Source code in MAMUT-routing-tools/MAMUT-routing-lib/src/mamut_routing_lib/td/roadgraph.py
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
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
compute_road_graph_sha256
¶
compute_traffic_overlay_sha256
¶
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
load_instance_road_graph
¶
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
load_traffic_overlay
¶
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
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
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
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
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
671 672 673 674 675 676 677 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 | |
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
786 787 788 789 790 791 792 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 | |