mamut_routing_lib.models¶
Pydantic models of the static benchmark contract (CVRP, VRPTW).
Every artifact is validated on load with extra="forbid": an instance file
(BenchmarkInstanceVRPTW for VRPTW, BenchmarkInstanceCVRP for CVRP, both
with an embedded (n+1) x (n+1) arc_costs matrix), a slim collection
instance (BenchmarkInstanceCVRPCollection / BenchmarkInstanceVRPTWCollection,
whose matrix comes from an arc_costs_source: a sha-pinned distances
sidecar or the euclidean rule), a solution (BenchmarkSolution), a
best-known solution (BenchmarkBKS, a solution plus its objective) and
a solver claim of optimality (SolverReportedOptimality, validated inside
metadata["optimality"]). Node index 0 is the depot, and validation rejects
any other depot value and a nonzero depot service time. Customers are
1..num_customers. Time-dependent instances live
in mamut_routing_lib.td.models.
NonnegativeInteger
module-attribute
¶
AnyArcCostsSource
module-attribute
¶
AnyArcCostsSource = Annotated[
ArcCostsDistancesRef | ArcCostsEuclidean,
Field(discriminator="model"),
]
LoadedStaticInstance
module-attribute
¶
AnyCollectionStaticInstance
module-attribute
¶
AnyCollectionStaticInstance: TypeAlias = (
BenchmarkInstanceCVRPCollection
| BenchmarkInstanceVRPTWCollection
)
AnyStaticBenchmarkInstance
module-attribute
¶
LEGACY_OPTIMALITY_CLAIM_MESSAGE
module-attribute
¶
LEGACY_OPTIMALITY_CLAIM_MESSAGE = "metadata.optimality holds a claim in the format of mamut-routing-lib versions before 0.13 (a 'proven: true' stamp). This library does not read that format. Read such historical files with mamut-routing-lib 0.12.0."
ArtifactPaths
¶
Bases: BaseModel
Repository-relative paths of the four artifacts of a generated instance (.vrp.json, .vrp, meta, manifest).
validate_relative_paths
classmethod
¶
InstanceMetadata
¶
Bases: BaseModel
Structured metadata of a generated (OSM-derived) instance.
Historic families carry a free-form dict instead; artifacts.has_structured_metadata
tells the two apart. num_vehicles_lb is the bin-packing lower bound on the
route count that the -k<K> name suffix advertises.
sibling_variant_paths
class-attribute
instance-attribute
¶
derived_problem_paths
class-attribute
instance-attribute
¶
source_problem_paths
class-attribute
instance-attribute
¶
validate_path_map
classmethod
¶
Source code in MAMUT-routing-lib/src/mamut_routing_lib/models.py
validate_num_vehicles_lb
classmethod
¶
Source code in MAMUT-routing-lib/src/mamut_routing_lib/models.py
ReferenceLLA
¶
BenchmarkInstanceVRPTW
¶
Bases: _InstanceValidationMixin
A VRPTW instance with an embedded arc-cost matrix.
Adds per-node service_times and time_windows ([ready, due],
depot included) to the CVRP core. Historic families (Sintef2008, Dimacs2021,
Ortec2022) and hydrated collection instances use this model; service
starts at or after ready and at or before due.
metadata
class-attribute
instance-attribute
¶
metadata: InstanceMetadata | dict[str, Any] = Field(
default_factory=dict, union_mode="left_to_right"
)
validate_depot_service
classmethod
¶
validate_vrptw_node_vector_lengths
classmethod
¶
Source code in MAMUT-routing-lib/src/mamut_routing_lib/models.py
from_legacy_dict
classmethod
¶
Load a legacy VRPTW descriptor, renaming its arc_travel_times matrix to arc_costs.
Source code in MAMUT-routing-lib/src/mamut_routing_lib/models.py
BenchmarkInstanceCVRP
¶
Bases: _InstanceValidationMixin
A CVRP instance with an embedded arc-cost matrix (no service times, no time windows).
metadata
class-attribute
instance-attribute
¶
metadata: InstanceMetadata | dict[str, Any] = Field(
default_factory=dict, union_mode="left_to_right"
)
ArcCostsDistancesRef
¶
ArcCostsEuclidean
¶
Bases: BaseModel
Arc costs materialized from the instance coordinates on load.
The canonical definition is round(hypot(dx, dy), decimals) on the
stored ENU coordinates (IEEE-754 doubles, Python round-half-to-even), so
no sidecar is needed for the euclidean metric variant.
validate_decimals
classmethod
¶
BenchmarkInstanceCVRPCollection
¶
Bases: _SlimInstanceValidationMixin
Slim CVRP instance of a family-first collection: arc costs by arc_costs_source, see artifacts.hydrate_collection_instance.
BenchmarkInstanceVRPTWCollection
¶
Bases: _SlimInstanceValidationMixin
Slim VRPTW instance of a family-first collection (service times and windows may be fractional).
validate_depot_service
classmethod
¶
validate_vrptw_node_vector_lengths
classmethod
¶
Source code in MAMUT-routing-lib/src/mamut_routing_lib/models.py
validate_time_windows
classmethod
¶
Source code in MAMUT-routing-lib/src/mamut_routing_lib/models.py
ClaimEvidence
¶
Bases: BaseModel
A file preserved as evidence of a solver claim, pinned by the sha256 of its bytes.
SolverReportedOptimality
¶
Bases: BaseModel
An attributable solver self-report of optimality, stored under metadata["optimality"].
target_profile names the evaluation profile under which the solver claims
optimality. The store requires it to equal the profile of the evaluated family.
reported_primal and reported_dual are the solver's own bounds, in its
own arithmetic, and evidence pins a preserved file of the run. The checker
verifies the routes but not the claim.
validate_bound
classmethod
¶
Source code in MAMUT-routing-lib/src/mamut_routing_lib/models.py
LegacyOptimalityClaimError
¶
Bases: ValueError
A BKS or solution file carries an optimality claim in the format of library versions before 0.13.
BenchmarkSolution
¶
Bases: _SolutionValidationMixin
A candidate solution: elementary routes of positive customer ids, optional cost.
cost may be None (the checker prices the routes) or the exact expected
value (the checker then reports objective_value_mismatch on any deviation).
BenchmarkBKS
¶
Bases: _SolutionValidationMixin
A best-known solution: a solution plus the objective_function it is best under.
Stored as <base>.bks.<ObjectiveFunction>.json next to the instance and
written only through mamut_routing_lib.bks (checker cost, mandatory
metadata.authors, replace-only-if-strictly-better).
from_legacy_dict
classmethod
¶
from_legacy_dict(
legacy_bks: dict[str, Any],
objective_function: ObjectiveFunction,
) -> "BenchmarkBKS"
Source code in MAMUT-routing-lib/src/mamut_routing_lib/models.py
require_depot_zero
¶
Validate the depot index on load. The exact profiles place the depot at vertex 0.
require_zero_depot_service
¶
Validate a service-time vector on load. The depot has no service duration.
Source code in MAMUT-routing-lib/src/mamut_routing_lib/models.py
is_pre_013_optimality_claim
¶
True for the proven: true stamp that library versions before 0.13 wrote.
reject_pre_013_optimality_claim
¶
Raise LegacyOptimalityClaimError when payload["metadata"]["optimality"] has the pre-0.13 shape.