This program is part of QOBLIB - Quantum Optimization Benchmarking Library and is designed to verify solutions to Capacitated Vehicle Routing Problems (CVRP). It checks whether a given solution satisfies all constraints and computes the total route cost.
The Capacitated Vehicle Routing Problem (CVRP) involves:
- A fleet of vehicles with capacity
$X$ - A central depot (node 1)
- A set of customers with demands
$d_i$ - Coordinates for all locations
The goal is to find routes for all vehicles that:
- Visit all customers exactly once
- Start and end at the depot
- Respect vehicle capacity constraints
- Minimize total distance
This checker verifies a solution against a CVRP instance file by:
- Parsing the instance file (TSPLIB/CVRPLIB format).
- Reading the solution file with routes.
- Validating each route:
- Computes total demand on the route.
- Checks capacity constraint.
- Calculates Euclidean distance.
- Verifying that all customers are visited exactly once.
- Computing the total cost (sum of all route distances).
- Reporting if the solution is feasible.
NAME : <instance-name>
DIMENSION : <number-of-nodes>
CAPACITY : <vehicle-capacity>
NODE_COORD_SECTION
<node-id> <x> <y>
...
DEMAND_SECTION
<node-id> <demand>
...
DEPOT_SECTION
1
-1
EOF
- Node 1 is the depot with demand 0
- Distances are computed using Euclidean distance rounded to nearest integer
Route #1: <customer1> <customer2> ...
Route #2: <customer3> <customer4> ...
...
Cost <total-cost>
- Routes list customer node IDs (excluding depot)
- Each route implicitly starts and ends at the depot
- Cost line is optional but recommended
Route #1: 15 2 18 1 8
Route #2: 10 11 7 9 6
Route #3: 17 4 5 19 3
Route #4: 20 12 13 14 16
Cost 646
- 0: Solution is valid (all constraints satisfied)
- 1: Solution is invalid (constraint violation detected)
- 2: Error reading files or parsing
cargo build --releaseThe binary will be in target/release/check_cvrp.
./target/release/check_cvrp <instance-file> <solution-file>./target/release/check_cvrp ../instances/XSH-n20-k4-01.vrp ../solutions/XSH-n20-k4-01.opt.solRun unit tests:
cargo testCheck all solutions against instances:
./check_all.shThe checker performs the following validations:
- Customer Coverage: Every customer must be visited exactly once
- Capacity Constraint: Total demand on each route ≤ vehicle capacity
- Valid Nodes: All customer IDs must be valid (1 to DIMENSION)
- Cost Calculation: Euclidean distances computed and rounded to nearest integer
- Cost Verification: If a cost is claimed, it is compared with calculated cost
The checker outputs:
- Instance information (name, nodes, capacity)
- For each route:
- Customer visits
- Total load vs capacity
- Route cost
- Validation status (OK/INVALID)
- Total cost across all routes
- Final verdict: VALID or INVALID
This file is part of QOBLIB - Quantum Optimization Benchmarking Library Licensed under the Apache License, Version 2.0