mamut_routing_lib.solvers.external.problem¶
Problem files for external solvers.
These are solver inputs, written into a scratch directory with fixed file
names, not the published CVRPLIB export of mamut_routing_lib.cvrplib (whose
bytes are pinned by the committed .vrp files and the website's writer).
Each reader is stricter than the format suggests, which is why there are three
writers:
cvrplib-x, the Uchoa X-set layout, for coordinate solvers. FILO2'sfscanfparser needs exactlyNAME,COMMENT,TYPE,DIMENSION,EDGE_WEIGHT_TYPE,CAPACITYin that order (noVEHICLESline) and a one-token name; HGS-CVRP skips the first three lines and throws on any header key other thanDIMENSION,EDGE_WEIGHT_TYPE,CAPACITY,DISTANCEandSERVICE_TIME.lkh: LKH-3 refusesNODE_COORD_SECTIONnext to explicit weights (it needs a coordinate type), readsVEHICLESand the VRPTW sections, and treatsACVRPandCVRPTWas asymmetric (CVRPas symmetric).cvrplib-matrix, for HGS-CVRP with the MAMUT-routing reader patch (patches/hgs-cvrp-explicit-matrix.patch): the X-format header plusEDGE_WEIGHT_FORMAT : FULL_MATRIXand anEDGE_WEIGHT_SECTIONof decimal (possibly asymmetric) costs beforeNODE_COORD_SECTION, whose coordinates only serve SWAP*'s polar sectors. NoVEHICLESline: the fleet is-veh.cvrplib-explicit: a generic CVRPLIB file with an integerFULL_MATRIX(for user-configured solvers), rendered bycvrplib.render_cvrplib.
Node i + 1 of a file is library node i; the depot is node 1.
LKH_RUN_PARAMETERS
module-attribute
¶
LKH_RUN_PARAMETERS = {
"PROBLEM_FILE": "the input file of the run",
"MTSP_SOLUTION_FILE": "the solution file of the run",
"SEED": "the seed of the run",
"TIME_LIMIT": "the time limit of the run",
"PRECISION": "the scale of the costs",
"SCALE": "the multiplier for input weights",
}
write_text
¶
Write lines with a final newline, streaming (an n = 4000 matrix is ~130 MB of text).
Source code in MAMUT-routing-lib/src/mamut_routing_lib/solvers/external/problem.py
render_x_format
¶
render_x_format(
*,
coordinates: Sequence[Sequence[float]],
demands: Sequence[int],
capacity: int,
coordinate_decimals: int,
comment: str = "MAMUT-routing",
name: str = "problem",
) -> Iterable[str]
Lines of an X-format CVRP (EUC_2D) with the depot as node 1.
Source code in MAMUT-routing-lib/src/mamut_routing_lib/solvers/external/problem.py
render_matrix_format
¶
render_matrix_format(
*,
matrix_rows: Iterable[str],
dimension: int,
coordinates: Sequence[Sequence[float]],
demands: Sequence[int],
capacity: int,
comment: str = "MAMUT-routing",
name: str = "problem",
) -> Iterable[str]
Lines of a full-matrix CVRP for the patched HGS-CVRP reader (depot = node 1).
The first three lines are skipped by the reader; the header keys it accepts are
DIMENSION, EDGE_WEIGHT_TYPE, EDGE_WEIGHT_FORMAT, CAPACITY and the
EDGE_WEIGHT_SECTION, which must come after DIMENSION.
Source code in MAMUT-routing-lib/src/mamut_routing_lib/solvers/external/problem.py
render_lkh_problem
¶
render_lkh_problem(
*,
problem_type: str,
matrix: Sequence[Sequence[int]],
demands: Sequence[int],
capacity: int,
vehicles: int,
time_windows: Sequence[Sequence[int]] | None = None,
service_times: Sequence[int] | None = None,
name: str = "problem",
) -> Iterable[str]
Lines of an LKH-3 problem file: explicit integer FULL_MATRIX, no coordinates.
Source code in MAMUT-routing-lib/src/mamut_routing_lib/solvers/external/problem.py
lkh_parameter_key
¶
The keyword of a parameter line as LKH-3 reads it: the first token, in upper case.
LKH-3 splits a line on = and white space. Empty for a blank line and for a comment (# ...).
Source code in MAMUT-routing-lib/src/mamut_routing_lib/solvers/external/problem.py
check_lkh_extra_lines
¶
Refuse (ValueError) an extra parameter line that sets a parameter of the run.
Source code in MAMUT-routing-lib/src/mamut_routing_lib/solvers/external/problem.py
render_lkh_params
¶
render_lkh_params(
*,
problem: Path,
solution: Path,
seed: int,
time_limit_s: float,
extra: Sequence[str] = (),
) -> Iterable[str]
Lines of an LKH-3 parameter file for one bounded VRP run.
SPECIAL selects LKH-3's VRP move settings; RUNS = 1 with a huge
MAX_TRIALS makes TIME_LIMIT the stopping rule (in LKH-3.0.6 the limit
counts from after reading the parameters, preprocessing included);
PRECISION = 1 keeps scaled costs inside LKH's 32-bit C * PRECISION;
MTSP_MIN_SIZE = 0 lets vehicles stay unused, so VEHICLES is an upper
bound rather than an exact fleet. extra lines come last and may tune the
search (RUNS = 10, POPULATION_SIZE = 10), not set a parameter of the
run (:data:LKH_RUN_PARAMETERS).
Source code in MAMUT-routing-lib/src/mamut_routing_lib/solvers/external/problem.py
render_explicit_cvrplib
¶
render_explicit_cvrplib(
*,
matrix: Sequence[Sequence[int]],
coordinates: Sequence[Sequence[float]],
demands: Sequence[int],
capacity: int,
num_vehicles: int | None,
time_windows: Sequence[Sequence[int]] | None = None,
service_times: Sequence[int] | None = None,
name: str = "problem",
) -> str
A generic CVRPLIB file with an integer FULL_MATRIX (cvrplib.render_cvrplib).