parse_vrp_solution

parse_vrp_solution(path)[source]

Parse a CVRPLIB solution file.

Expects format:

Route #1: 15 2 18 1 8
Route #2: 10 11 7 9 6
...
Cost 646

Customer IDs are 1-based (TSPLIB convention). The returned routes use 0-based indexing with the depot prepended and appended.

Parameters:

path (str | Path) – Path to the .opt.sol or .bst.sol file.

Return type:

tuple[list[list[int]], float]

Returns:

Tuple of (routes, cost) where routes is a list of routes and each route is [depot, c1, c2, ..., depot] with 0-based indices. The depot index is assumed to be 0.