bucket-graph-spprc¶
Header-only C++ template library implementing the bucket graph labeling algorithm for the Shortest Path Problem with Resource Constraints (SPPRC) and vehicle routing variants. Based on Sadykov, Uchoa & Pessoa (2021) with extensions from Sadykov et al. (2026).
The bucket graph of a small SPPRC with one resource, time: a column per vertex
from the source s to the sink t, its time window cut into buckets at most 10 wide,
and the bucket arcs between them. Highlighted is the optimal path, with the
time at which it reaches each bucket.¶
The bucket graph of a small SPPRC with one resource, time: a column per vertex
from the source s to the sink t, its time window cut into buckets at most 10 wide,
and the bucket arcs between them. Highlighted is the optimal path, with the
time at which it reaches each bucket.¶
Key Features¶
Generic Resource concept — 7-function compile-time interface
6 built-in resources — Standard (time/capacity), Side (a view’s non-main resources), NgPath, R1C (rank-1 cuts), CumulativeCost, PickupDelivery
Mono and bidirectional labeling with across-arc concatenation
Multi-stage pricing — Heuristic1 → Heuristic2 → Exact, one stage per
solve(); enumeration of all paths within a gap on requestBucket fixing and arc elimination with completion-bound pruning
SoA label storage with SIMD-accelerated dominance checks
2D bucketing for problems with two main resources
Quick Start¶
Requires a C++23 compiler (GCC 14+ or Clang 18+) and CMake 3.25+; the CLI, tests and examples
also need <print> (libstdc++ 14+ or libc++ 17+).
cmake -B build # picks g++-15/g++-14 if the default g++ is too old; CXX overrides
cmake --build build
# One-time: fetch benchmark instances
benchmarks/fetch_instances.sh
# Solve an SPPRC instance
./build/bgspprc-solve --stats --timing benchmarks/instances/spprclib/A-n54-k7-149.sppcc
On macOS, the Xcode Command Line Tools’ Apple clang builds it as is (tested with Apple clang 21; Apple’s version numbers are its own, and configure wants Apple clang 17 or more, i.e. Xcode 16.3+, the first based on an LLVM past 18), with no compiler flag:
xcode-select --install # once, for Apple clang and libc++
brew install cmake ninja uv
uv venv && uv pip install -r requirements-dev.txt # the lint and Python tools ctest runs
cmake -B build -G Ninja
cmake --build build
libc++ has no <experimental/simd>, so with Apple clang the engine’s SIMD loops take their scalar
paths; a Homebrew GCC (libstdc++) builds them.
The benchmark scripts run each solve under timeout. A recent macOS has one in /usr/bin; on an
older one, brew install coreutils adds GNU’s as gtimeout, which the scripts fall back on. With
neither, they stop before the first solve and say so.
Sample output:
bgspprc 0.2.0 (v0.2.0-0-g32a8c1c)
bgspprc: executor=StdThread bidir=parallel
A-n54-k7-149 sppcc n=55 arcs=2862 theta=-1e-06 cost=-56718.000 paths=1 26.5ms
0 34 41 25 47 25 47 25 41 34 54
n_buckets=550 n_labels_created=113210 n_dominance_checks=128977 n_non_dominated=12059
n_dominance_checks_fw=53407 n_dominance_checks_bw=75570 n_non_dominated_fw=4854 n_non_dominated_bw=7205
n_fixed_buckets=0 n_eliminated_arcs=0 label_state_bytes=1
timing: fw=5.570ms bw=17.709ms completion=1.009ms concat=2.562ms paths=1.167ms sum=28.018ms
Supported instance formats: .sppcc (capacity SPPCC), .vrp (Roberti CVRP pricing), .graph
(Solomon RCSPP) and .sppg (spp-graph’s general format, shared by the flowty pricers). Their
layouts, the meaning of the output above and every flag are in CLI Reference
below.
Benchmarks¶
# Fetch benchmark instances (once)
benchmarks/fetch_instances.sh
# Run benchmarks: rewrites rows of benchmarks/bgspprc.csv, the tracked results
# behind the tables below; BGSPPRC_CSV=other.csv writes elsewhere
benchmarks/run_benchmarks.sh
Results at a glance¶
Headline numbers from the committed CSVs, 120 s timeout per instance. Full
tables, methodology, and reproducer one-liners in
benchmarks/README.md.
sgm (s) = shifted geometric mean with shift = 1 s;
mean (s) = arithmetic mean; solved = #instances finished within the
120 s timeout (TL substitutes as 120 s in both).
Pathwyse comparison (sppcc + vrp) — bgspprc para_bidir_vec vs patched
Pathwyse, both in pure-ng mode.
set |
ng |
solver |
sgm (s) |
mean (s) |
solved |
|---|---|---|---|---|---|
spprclib |
8 |
bgspprc |
0.917 |
7.238 |
44/45 |
spprclib |
8 |
pathwyse |
1.522 |
12.133 |
42/45 |
spprclib |
16 |
bgspprc |
2.048 |
15.801 |
40/45 |
spprclib |
16 |
pathwyse |
4.284 |
24.290 |
38/45 |
spprclib |
24 |
bgspprc |
5.838 |
26.725 |
38/45 |
spprclib |
24 |
pathwyse |
10.590 |
42.512 |
31/45 |
roberti |
8 |
bgspprc |
0.551 |
0.911 |
31/31 |
roberti |
8 |
pathwyse |
2.330 |
9.999 |
30/31 |
roberti |
16 |
bgspprc |
3.176 |
15.003 |
28/31 |
roberti |
16 |
pathwyse |
8.796 |
28.152 |
28/31 |
roberti |
24 |
bgspprc |
14.813 |
44.346 |
23/31 |
roberti |
24 |
pathwyse |
26.824 |
62.019 |
19/31 |
bgspprc is 1.3×–2.4× faster than Pathwyse by sgm across the six
(set, ng) cells (ratio = (pathwyse_sgm + 1) / (bgspprc_sgm + 1),
shift = 1 s, TL → 120 s on both sides). Both solvers reach the same
optimal reduced cost on .sppcc/.vrp modulo cost-scale rounding
(verified per-row via compute_means.py pathwyse --rows). Pathwyse needs
patches against upstream d53c01b — see
benchmarks/patches/ (auto-applied by
run_pathwyse.sh).
Paper comparison (rcspp) — bgspprc para_bidir_vec vs Petersen & Spoorendonk
2025 (arXiv:2511.01397) all_s column.
ng |
solver |
sgm (s) |
mean (s) |
solved |
|---|---|---|---|---|
8 |
bgspprc |
1.884 |
5.640 |
56/56 |
8 |
paper |
0.203 |
0.406 |
56/56 |
16 |
bgspprc |
2.200 |
8.783 |
56/56 |
16 |
paper |
0.526 |
3.010 |
56/56 |
24 |
bgspprc |
2.588 |
15.433 |
52/56 |
24 |
paper |
0.873 |
9.123 |
53/56 |
bgspprc is 1.9×–2.4× slower than the paper on rcspp at sgm — same
formula (bg_sgm + 1) / (paper_sgm + 1), both sides share the 120 s
budget. Gap narrows with ng: 2.40× at ng=8 → 2.10× at ng=16 → 1.92× at
ng=24, suggesting bgspprc’s overhead is fixed-per-instance rather than
proportional to search-tree size.
Use as a Library¶
Requires a C++23 compiler and CMake ≥ 3.25. Add via CMake FetchContent:
include(FetchContent)
FetchContent_Declare(
bgspprc
GIT_REPOSITORY https://github.com/spoorendonk/bucket-graph-spprc.git
GIT_TAG v0.2.0)
FetchContent_MakeAvailable(bgspprc)
target_link_libraries(your_target PRIVATE bgspprc)
This page describes main, which is ahead of v0.2.0, so not everything here holds for that
release: read the README at its
tag when you pin it. Among what it
lacks: the rank-1 cut API below (denominators past 2, vertex memory, the per-vertex layout, fit,
R1CError) and the refusal of grids too large to index. And its update_arc_costs() does not drop
the last solve as proof, so there call solve() after it, before eliminating arcs or fixing
buckets. Its solves also price at the base costs once the bucket arcs are rebuilt
(#175): there call
update_arc_costs() again after build(), adapt_bucket_steps() and reset_elimination(). A
solve() that changed xi() rebuilt the grid by itself: call update_arc_costs() and solve again,
until a solve() leaves xi() unchanged, before using its paths or exact_complete(), eliminating
arcs, fixing buckets or enumerating. To use what is not released yet, set GIT_TAG to a commit hash, not to main, so a build
can be repeated.
CMake options, with their default when bgspprc is the top-level project and when it is embedded
through FetchContent or add_subdirectory:
Option |
Top level |
Embedded |
Effect |
|---|---|---|---|
|
ON |
OFF |
build |
|
ON |
OFF |
build the tests; configure downloads doctest |
|
ON |
OFF |
build |
|
OFF |
OFF |
scalar paths only, also in targets that link |
|
ON |
(ignored) |
set this clone’s |
The library passes your target no optimization or -march flags. This repository’s own CLI and
tests build with -O2, and with -march=native where the compiler has it; add the same to your
own target for comparable speed.
Minimal usage:
#include <bgspprc/solver.h>
using namespace bgspprc;
// Set up problem data. The caller owns the arrays, and the solver keeps a
// reference to pv itself: both must outlive it, so never pass a temporary.
ProblemView pv;
pv.n_vertices = N;
pv.source = 0;
pv.sink = N - 1;
pv.n_arcs = M;
pv.arc_from = from.data();
pv.arc_to = to.data();
pv.arc_base_cost = cost.data();
pv.n_resources = 1;
pv.arc_resource = &arc_resource_ptr;
pv.vertex_lb = &vertex_lb_ptr;
pv.vertex_ub = &vertex_ub_ptr;
// Create solver with no extra resources. Bucket steps default to the
// BG2021 §6.3 rule (horizon / ξ, ξ = 25 buckets per vertex, doubled when
// dominance gets expensive); pass .bucket_steps = {10.0, 1.0} to fix them.
Solver<EmptyPack> solver(pv, EmptyPack{});
solver.set_stage(Stage::Exact);
solver.build();
auto paths = solver.solve();
for (auto& p : paths)
printf("cost=%.2f vertices=%zu\n", p.reduced_cost, p.vertices.size());
What an empty result proves. A solve returns only paths of reduced cost
below theta (Options::theta, default -1e-6), so no path may mean that none
is cheap enough, not that the optimum is 0: to learn the cheapest path
whatever its cost, raise theta. And it is proof only of an exact solve:
One
solve()runs one stage, the current one, and may advance it for the next call. A new solver starts atHeuristic1; it moves toHeuristic2once a solve finds no path, or after 4 of them, and from there toExactonce one finds none, or after 11. It never entersEnumerate, which onlyset_stage(Stage::Enumerate)orenumerate(gap)asks for. The heuristic stages’ dominance ignores every resource but the main ones, andHeuristic1keeps one label per bucket, so an empty result of theirs proves nothing: callset_stage(Stage::Exact)first, as above.exact_complete()says whether the last solve was exact and hit no label cap (Options::max_scc_labels). If it is false, a path belowthetamay have been missed.label_cap_hit()reports the cap alone.The proof covers the arcs and buckets not eliminated or fixed. Those stay out after
update_arc_costs(), though they were ruled out at the costs of their own call;reset_elimination()brings them back, as a rebuild of the grid does. Unlike a rebuild,reset_elimination()does not clearexact_complete().An exact solve that finds nothing may rebuild the grid by itself (the ξ-doubling) and solve again at the same costs;
exact_complete()then describes the second solve.
Cost changes. The solver copies arc costs into its bucket arcs, so after
changing reduced costs, even in place in the array it already has, call
solver.update_arc_costs(reduced_costs) before the next solve(). It stores
the pointer, so that array must stay alive too. Also call it after changing a
resource’s data, such as an R1CData’s cuts or duals or a resource reached
through resource<R>(). Keep the reduced costs in an array of their own:
arc_base_cost gives a path’s original_cost and is read when the grid is
built, so rewriting it after build() leaves original_cost wrong.
The bucket grid takes its one or two main resources (n_main_resources, at
most 2) from the view and never reads the rest. Resources past them are the
pack’s to enforce: SideResources (resources/side.h) enforces view resources
[first, first + n) as standard resources, e.g.
SideResources(pv, n_grid, pv.n_resources - n_grid) with
n_grid = std::min(pv.n_main_resources, 2); it throws std::invalid_argument
for more than kMaxSideResources of them.
A view without a main resource makes the constructor throw
std::invalid_argument.
solver.cost_of(arcs) prices a given source-to-sink walk (arc ids in order)
as labelling would, under the current reduced costs and resource states: an
optional of its reduced and original cost, empty when the walk is
infeasible. Use it to reprice a column the solver did not generate.
Executors¶
Solver and BucketGraph take an executor as their second template argument
(default SequentialExecutor). The two threaded ones differ on a nested
dispatch, which the parallel bidirectional solve makes: it runs
parallel_invoke(bw, fw), and each side’s label compaction calls
parallel_for on the same executor.
ThreadPoolExecutor(executor.h, over a caller-ownedThreadPool) runs one dispatch at a time per pool; a nested one runs inline on its calling thread. So in a parallel bidir solve, compaction uses at most 2 threads however large the pool.StdThreadExecutor(executor_thread.h, a process-wide pool) lets a waiting thread run queued tasks, so a nestedparallel_forfans out across the whole pool.
Results are identical; only speed differs, so StdThreadExecutor timings
overstate what a ThreadPoolExecutor of the same size gives a bidir solve.
Custom Resources¶
Implement the Resource concept to define custom resource types:
struct MyResource {
using State = double;
bool symmetric() const;
State init_state(Direction dir) const;
std::pair<State, double> extend_along_arc(Direction dir, State s, int arc) const;
std::pair<State, double> extend_to_vertex(Direction dir, State s, int vertex) const;
double domination_cost(Direction dir, int vertex, State s1, State s2) const;
double concatenation_cost(Symmetry sym, int vertex, State s_fw, State s_bw) const;
double min_domination_cost() const;
};
// Bundle into a resource pack
using MyPack = ResourcePack<StandardResource, MyResource>;
Solver<MyPack> solver(pv, MyPack{std_res, my_res}, opts);
See examples/custom_resource.cpp for a complete working example, include/bgspprc/resource.h for the full concept definition, and include/bgspprc/resources/ for built-in implementations.
Examples¶
The examples/ directory contains standalone programs, built by default at top level:
basic_spprc.cpp— Solve a 5-vertex SPPRC with time windowscustom_resource.cpp— Implement a custom capacity resource using theResourceconcept
./build/examples/example_basic_spprc
./build/examples/example_custom_resource
CLI Reference¶
Usage: bgspprc-solve [OPTIONS] <path>...
Arguments:
<path> Instance file, or a directory whose own instance files are solved
(subdirectories are not entered; type by extension: .sppcc, .vrp,
.graph, .sppg)
Options:
--version Print version and build git hash, then exit
--mono Use mono solver (default: bidir)
--stage STAGE heuristic1|heuristic2|exact (default: exact)
--ng K ng-neighborhood size (default: 0/off for sppcc/vrp/sppg;
from file for graph, or 8 without one, see below; 0 disables)
--ng-metric M distance|cost: how --ng K ranks neighbors (default: cost;
distance needs coordinates or a distance matrix: sppcc, vrp)
--steps S1,S2 Bucket step sizes (default: per-type, see below)
--xi X Derive steps from ξ = X buckets per vertex (BG2021 §6.3);
not with --steps or --auto-steps
--auto-steps Use per-vertex auto-computed steps (overrides --steps)
--no-jump-arcs Disable jump arcs (for ablation studies)
--max-paths N Number of paths to return (0=all, 1=best; default: 1)
--theta T Pricing threshold θ (default: -1e-6 for CG)
--max-scc-labels N Label cap per SCC (default: 500000); a solve it cuts is
not exact, and a warning on stderr says so
--stats Print solve statistics after each instance
--csv Machine-readable CSV output
--timing Print phase timing breakdown (ignored with --csv)
--parallel Use the parallel executor (the default)
--no-parallel Use sequential executor (default: parallel)
--no-parallel-bidir Sequential fw/bw labeling
--write-sppg DIR Write each instance to DIR/<stem>.sppg instead of solving
--write-ng DIR With --ng K: write each .sppcc/.vrp's ng sets to
DIR/<stem>.ng<K>.csv (PathWyse's form) instead of solving
There is no --help; run it without a path to print the usage (exit 1).
Steps. Without --steps, --xi and --auto-steps: 10,1 for .sppcc and .vrp, per-vertex
steps computed from the arcs for .graph, and the ξ rule (25 buckets per vertex) for .sppg. A
step given as 0 or less takes the type’s default: on .graph a --steps with both at 0 or less
gives the per-vertex steps, and with one of them above 0 the other is 20 (first) or 50 (second).
--auto-steps overrides --steps.
ng sets. N(v) holds v itself, then its K-1 best neighbors, the depot and the sink excepted.
With K = 1 it still holds one neighbor, as K = 2. A set has at most 31 entries, v included: a larger
K is cut to 31 silently, which is a weaker relaxation than the one asked for, and --write-ng
writes the sets so cut, under the K asked for. For .graph the sets are the file’s n lines, or,
without a neighbor in any, those of the k cheapest outgoing arcs with the file’s k, or 8 if k is 0;
--ng K with K other than k builds them anew. --ng-metric applies only to sets built by --ng,
not to a file’s own.
Output. Results go to stdout; the banner, warnings and errors go to stderr. cost is the
reduced cost of the best path found and paths the number returned, at most --max-paths. Only
paths of reduced cost below θ are found, so with none the line reads cost=0.000 paths=0, which
does not mean the optimum is 0, and the exit status is still 0. The line under it lists the best
path’s vertices as the solver numbers them: for .sppcc and .vrp the depot is split, so the
path starts at the depot and ends at its copy, the last vertex (54 in the sample above). ms is
the wall clock of building and solving; --timing’s sum adds the phases, so with parallel
labeling it counts the concurrent forward and backward times twice.
A solve that stops an SCC at the label cap (--max-scc-labels, Options::max_scc_labels in the
library) is not exact, and the CLI then prints a warning naming the instance file on stderr; the
stdout format and the exit status stay the same. Its cost can be too high, or no path found where
one exists; see “What an empty result proves” above.
Exit status. 1 on any failure the CLI detects: an unknown or malformed option, no path given, a
file that cannot be opened or solved, an output directory that does not exist, or a malformed
instance: a field that is missing, extra, not a (finite) number or outside double’s range (1e999,
1e-400), arc costs that overflow it, an id out of range or given twice, a section that is missing or
incomplete, or records that are not as many as the file says. A file’s failure is reported on stderr
with its path, and the other files are still solved. Otherwise the status is 0, also when a
directory holds no instance files. An unknown --stage only warns and uses exact; a malformed
--steps only warns and uses the defaults.
Instance formats¶
Every format but .sppg has one resource-0 capacity window of [0, Q] per vertex. For .sppcc and
.vrp an arc consumes the demand of its head, and an arc into the sink none; file id i is solver
vertex i-1, and the depot’s copy, the sink, is the last vertex. Both need every keyword and section
named below, NAME excepted, with one value per node and per id, one capacity and one depot; other
keywords, and the data under them, are skipped, and so is all after EOF.
.sppcc: TSPLIB-like.NAME,DIMENSION,CAPACITY, thenEDGE_WEIGHT_SECTION(a full matrix),NODE_WEIGHT_SECTION(one weight per node) andDEMAND_SECTION(id demand, ids from 1). Node 0 is the depot: the source, with a copy as vertex n for the sink. Arc (i, j) costs d(i, j) + w(j), an arc into the sink d(i, 0), and an arc out of the depot w(0) besides..vrp: capacity-only CVRP pricing with Roberti’s data:NAME,DIMENSION,CAPACITY,NODE_COORD_SECTION(id x y, Euclidean distance, not rounded),DEMAND_SECTION(id d),DEPOT_SECTION(id) andPROFIT_SECTION(id p), ids from 1. Arc (i, j) costs d(i, j) - p(j), and into the sink, a copy of the depot, d(i, depot) - p(depot). Edge weights and time windows are not read..graph: DIMACS-like, withccomment lines.p name n m k(k the ng size);v id a b d Qa vertex’s time window, demand and capacity;e id from to cost timean arc, whose demand isdof its head;n v w ...v’s ng set. Thepline comes first, with onevline per vertex and melines (ids 0 to m-1) after it, and at most onenline per vertex. Ids from 0; vertex 0 is the source and n-1 the sink. Resources: capacity and time..sppg: the spp-graph format (itsdocs/instance-format.md); the grammar is incli/sppg_io.h. Main windows must be finite, resources past the first two main ones are enforced as ordinary resources (up to 8), and it carries no ng sets:--ng Kbuilds them from the K cheapest outgoing arcs. A file declaring more vertices than itswlines and arc ends can account for is refused when the rest have over 2^20 windows (vertices × resources, at least one per vertex), plus one perlline.
--write-sppg DIR converts any of these to .sppg instead of solving.
Running Tests¶
# Once, before configuring: the pinned lint and Python tools ctest also runs
# (without them configure warns and drops those tests)
uv venv && uv pip install -r requirements-dev.txt
# Run all tests
ctest --test-dir build
# Run a specific test by name
./build/test_runner --test-case="Bucket construction"
# Run tests matching a pattern
./build/test_runner -tc="*NgPath*"
Citing¶
Cite the paper for the result and the archived release for the code.
CITATION.cff carries both in machine-readable form — GitHub’s
“Cite this repository” button reads it.
The paper is arXiv:2606.30847, https://arxiv.org/abs/2606.30847.
@misc{spoorendonk2026bgspprc,
title = {bucket-graph-spprc: an extensible C++ library for the shortest
path problem with resource constraints},
author = {Spoorendonk, Simon},
year = {2026},
eprint = {2606.30847},
archivePrefix= {arXiv},
primaryClass = {math.OC},
url = {https://arxiv.org/abs/2606.30847}
}
The archived code is on Zenodo. The concept DOI 10.5281/zenodo.20819208 always resolves to the latest version; v0.1.0 is 10.5281/zenodo.20819209 and v0.2.0 is 10.5281/zenodo.24137027. Cite a version DOI when reproducibility matters — it pins one tree and one set of benchmark results:
@software{spoorendonk2026bgspprcsoftware,
title = {bucket-graph-spprc: a header-only C++ bucket graph labeling
library for the SPPRC},
author = {Spoorendonk, Simon},
year = {2026},
version = {0.2.0},
doi = {10.5281/zenodo.24137027},
url = {https://doi.org/10.5281/zenodo.24137027}
}
Cite a tag or a DOI, never main: the benchmark tables move with the code.
References¶
Sadykov, Uchoa, Pessoa (2021) — A bucket graph-based labeling algorithm with application to vehicle routing. Transportation Science, 55(1):4-28. DOI: 10.1287/trsc.2020.0985
Sadykov, Froger, Uchoa, Pessoa, Bulhoes, de Araujo (2026) — Bucket graph meta-solver for the resource constrained shortest path problem (Meta-Solver). HAL: hal-05486295. https://inria.hal.science/hal-05486295v2
Petersen, Spoorendonk (2025) — A parallel pull labelling algorithm for the resource constrained shortest path problem. arXiv:2511.01397. https://arxiv.org/abs/2511.01397
Pessoa, Sadykov, Uchoa, Vanderbeck (2020) — A generic exact solver for vehicle routing and related problems (VRPSolver). Mathematical Programming, 183:483-523. DOI: 10.1007/s10107-020-01523-z
Salani, Basso, Giuffrida (2024) — PathWyse: a flexible, open-source library for the resource constrained shortest path problem. Optimization Methods and Software, 1–23. DOI: 10.1080/10556788.2023.2296978
Seman, Munari, Bulhões, Camponogara (2024) — BALDES: A Branch-Cut-and-Price Bucket Graph Labeling Algorithm for Vehicle Routing. GitHub: https://github.com/lseman/baldes
Spoorendonk (2026) — bucket-graph-spprc: an extensible C++ library for the shortest path problem with resource constraints. arXiv:2606.30847. https://arxiv.org/abs/2606.30847