mamut_routing_lib.td.artifacts¶
IO for TD benchmark artifacts: ATF sidecar files and TD instance loading.
The ATF sidecar (<Instance>.atf.json or <Instance>.atf.json.gz) is the
canonical ground truth of a TD instance: one arrival-time NDCPWLF per arc of
the complete customer-based graph. Plain JSON is used for small instances
(debuggable at a glance), gzip for large ones; the loader accepts both. The
gzip form is written with mtime=0 so bytes are deterministic, and the
atf_sha256 recorded in instance files always hashes the uncompressed
canonical JSON bytes, making it storage-form independent.
ATFFormatError
¶
Bases: ValueError
Raised when an ATF sidecar file violates the canonical format.
ATFChecksumError
¶
Bases: ATFFormatError
Raised when an ATF sidecar's canonical bytes do not match the expected sha256.
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).
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
¶
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
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
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
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_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
td_instance_from_payload
¶
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.