C++ reference

The user-facing part of the library, in namespace bgspprc. Describe the problem in a ProblemView over arrays the caller owns, bundle the resources past the grid’s main ones in a ResourcePack, and solve with a Solver; see Use as a Library for a worked example. The headers are under include/bgspprc/, and bgspprc.h includes all but three, which are included on their own: executor_thread.h (StdThreadExecutor), resources/cumulative_cost.h and resources/pickup_delivery.h. The labeling engine behind Solver (BucketGraph, bucket_graph.h) is not listed here.

Solver

template<typename Pack, Executor Exec = SequentialExecutor>
class Solver

Top-level solver wrapping BucketGraph with multi-stage control.

Public Types

using Path = BucketGraph<Pack, Exec>::Path
using WalkCost = BucketGraph<Pack, Exec>::WalkCost

Public Functions

inline Solver(const ProblemView &problem, Pack resources, Options opts = {}, Exec executor = {})

Standalone: the bucket graph builds and owns the CSR adjacency. The solver keeps a reference to problem, which must outlive it like the arrays it views: never pass a temporary.

inline Solver(const ProblemView &problem, AdjacencyView adjacency, Pack resources, Options opts = {}, Exec executor = {})

Borrows adjacency, the CSR adjacency of problem’s arcs, and builds none (#133): it must outlive the solver, unchanged, and so must problem itself, to which the solver keeps a reference. Throws std::invalid_argument when its vertex or arc count differs from the view’s.

inline bool owns_adjacency() const noexcept

Whether the bucket graph built its own adjacency rather than borrowing one.

inline void build()

Build bucket graph (call once, or after step size changes). Throws std::invalid_argument for a grid it cannot index, as BucketGraph::build() does (#161).

inline void update_arc_costs(std::span<const double> reduced_costs)

Fast cost update — O(1), just stores the pointer. Like BucketGraph::update_arc_costs(), it drops the last solve as proof (#160): exact_complete() is false, and elimination and fixing do nothing, until the next solve().

inline std::vector<Path> solve()

Solve SPPRC — returns paths of reduced cost below Options::theta. Runs one stage, current_stage(), and may advance it for the next call: a new solver starts at Heuristic1, moves to Heuristic2 after a solve without paths or the 4th one, and then to Exact after a solve without paths or the 11th one. It never moves to Enumerate by itself. An empty result of a heuristic stage proves nothing: set_stage(Stage::Exact), and see exact_complete(). In Exact stage, accumulates dominance stats for BG2021 §6.3 A+ ξ-doubling: on CG convergence (empty exact pricing), checks if finer buckets would help and retries if so. A finer grid past INT_MAX buckets is refused (BucketGraph::build(), #161): then there is no refinement, and the old grid, ξ and steps stay.

inline void eliminate_arcs(double theta)

Arc elimination using optimality gap (bound-based).

inline void eliminate_arcs_label_based(double theta)

Label-based arc elimination (Section 4.2). Tighter but requires prior solve.

inline int fix_buckets(double theta)

Bucket fixing using optimality gap. Returns number of newly fixed buckets.

inline int n_fixed_buckets() const

Number of fixed buckets.

inline int n_buckets() const

Total bucket count.

inline int64_t labels_created() const

Labels allocated by the pool during the last solve.

inline int64_t dominance_checks() const

Dominance comparisons performed in the last solve.

inline int64_t dominance_checks(Direction d) const
inline int64_t non_dominated_labels() const

Labels surviving dominance in the last solve.

inline int64_t non_dominated_labels(Direction d) const
inline int64_t eliminated_bucket_arcs() const

Bucket arcs eliminated since last build.

inline void reset_elimination()

Reset all elimination/fixing.

inline void reset_midpoint()

Adaptive midpoint control for bidirectional labeling.

inline double midpoint() const
template<typename R>
inline R &resource()

Access a resource in the pack (for runtime reconfiguration). Call update_arc_costs() after reconfiguring it, so the last solve no longer counts as proof; see BucketGraph::resource().

inline std::optional<WalkCost> cost_of(std::span<const int> arcs) const

Reduced and original cost of a source-to-sink walk of arc ids, or nullopt when infeasible; see BucketGraph::cost_of().

inline bool enumeration_complete() const

False when the last solve() or enumerate() was an enumeration cut by one of its caps; true otherwise, which says something only after an enumeration (enumerate(gap), or solve() in Stage::Enumerate): then it returned every path costing below its bound (gap, or Options::theta), over the arcs and buckets not eliminated or fixed. See BucketGraph::enumeration_complete().

inline bool exact_complete() const

Whether the last solve() or enumerate() was exact and hit no label cap. Its bound is Options::theta, or gap for enumerate(gap). Exact pricing returns the paths below it that survive dominance (at most max_paths), not all of them, so an empty result proves no path costs below it up to the dominance tolerance, over the arcs and buckets not eliminated or fixed; only an enumeration lists them all. False after build() or update_arc_costs() until the next solve. See BucketGraph::exact_complete().

inline bool label_cap_hit() const

Whether the last solve() stopped labelling an SCC at Options::max_scc_labels, or the last enumerate() at BucketGraph::kEnumSccLabelCap, with labels left to extend; false after build(). See BucketGraph::label_cap_hit().

inline const SolveTimings &solve_timings() const

Phase timing breakdown accumulated across all solve iterations (including A+ refinement retries).

inline void set_stage(Stage stage)

Stage management.

inline Stage current_stage() const
inline std::vector<Path> enumerate(double gap)

Path enumeration within gap.

inline void save_warm_labels(double fraction = 0.7)

Save warm labels for next solve (top fraction by cost).

inline bool adapt_bucket_steps(double threshold = 20.0)

Adaptive bucket step sizes. Returns true if steps changed and the grid was rebuilt; the rebuild throws as BucketGraph::build() does (#161), keeping the old grid and putting the steps back.

inline const std::array<double, 2> &bucket_steps() const

Get current bucket steps.

inline double xi() const

Current ξ (BG2021 §6.3), the nominal bucket count per vertex; see BucketGraph::xi().

inline void set_vertex_bucket_steps(std::vector<std::array<double, 2>> steps)

Set per-vertex bucket step sizes: one pair per vertex, or none for the uniform steps (std::invalid_argument otherwise).

inline std::vector<std::array<double, 2>> compute_min_inbound_arc_resource(int max_buckets = 200) const

Compute per-vertex steps from minimum inbound arc resource consumption.

Public Static Functions

static inline constexpr std::size_t label_state_size()

Size of the compile-time resource state tuple in bytes.

struct Options

Public Members

std::array<double, 2> bucket_steps = {0.0, 0.0}

Bucket widths of the one or two main resources; a step <= 0 is derived from xi (BG2021 §6.3).

double xi = 25.0

BG2021 §6.3: initial maximum number of buckets per vertex.

bool bidirectional = true

Label forward and backward and join, rather than forward only.

bool symmetric = false

Use the forward labels as the backward ones; needs source == sink.

bool no_jump_arcs = false

Disable jump arcs (for ablation studies).

bool parallel_bidir = true

Concurrent forward and backward labeling (requires a parallel executor).

int max_paths = 0

Most paths a solve returns; 0 = unlimited.

double theta = -1e-6

Only paths of reduced cost below theta are returned.

int max_enum_labels = 5000000

Cap on an enumeration’s total labels, per direction (enumeration_complete()).

int max_scc_labels = 500000

Labels one SCC may hold outside enumeration. A solve that reaches it stops extending there and is no longer exact (exact_complete()).

Solver::Path and Solver::WalkCost are the engine’s types, defined in bucket_graph.h:

  • Path, a path a solve returns: std::vector<int> vertices and std::vector<int> arcs in order from source to sink, and double reduced_cost and double original_cost.

  • WalkCost, what cost_of returns for a feasible walk: double reduced_cost and double original_cost.

enum class bgspprc::Stage : uint8_t

Values:

enumerator Heuristic1

one label per bucket, the cheapest

enumerator Heuristic2

dominance on cost and main resources only, pack ignored

enumerator Exact

full exact labeling

enumerator Enumerate

find all paths within gap

enum class bgspprc::Direction : uint8_t

Values:

enumerator Forward
enumerator Backward
enum class bgspprc::Symmetry : uint8_t

Values:

enumerator Asymmetric
enumerator Symmetric
constexpr double bgspprc::INF = std::numeric_limits<double>::infinity()
constexpr double bgspprc::NEG_INF = -std::numeric_limits<double>::infinity()
constexpr double bgspprc::EPS = 1e-9

Problem data

struct ProblemView

Non-owning view of the problem data. All arrays are caller-owned.

Public Members

int n_vertices = 0

number of vertices, source and sink included

int source = 0

where every path starts

int sink = 0

where every path ends

int n_arcs = 0

number of arcs

const int *arc_from = nullptr

Arc tails, n_arcs of them. Arc ids are the caller’s insertion order, so caller-side arc data stays index-aligned without a permutation table.

const int *arc_to = nullptr

arc heads, n_arcs of them

const double *arc_base_cost = nullptr

original arc costs, n_arcs of them

int n_resources = 0

number of resources

const double *const *arc_resource = nullptr

Per-arc resource consumptions, [resource][arc]: n_resources pointers, each to n_arcs.

const double *const *vertex_lb = nullptr

Per-vertex lower resource bounds, [resource][vertex]: n_resources pointers, each to n_vertices.

const double *const *vertex_ub = nullptr

Per-vertex upper resource bounds, laid out as vertex_lb.

int n_main_resources = 1

Resources [0, n_main_resources) define the bucket grid, which takes at most two: a larger count is read as 2. BucketGraph never reads the resources past its grid ones; to enforce them, put them in the pack (SideResources, resources/side.h, enforces them from this view). BucketGraph throws std::invalid_argument for a view without a main resource, with n_resources below the grid’s count, or with a null arc_resource/vertex_lb/vertex_ub.

const bool *resource_nondisposable = nullptr

Per-resource non-disposability: array of n_resources bools. true = non-disposable (equality required in dominance). nullptr means all resources are disposable (default).

struct AdjacencyView

Non-owning CSR topology, ~40 bytes, passed by value. Arrays are owned by whoever built them (the owning adjacency, or the core). out_begin/in_begin have n_vertices+1 entries; out_arcs/in_arcs have n_arcs.

Public Functions

inline std::span<const int> outgoing(int v) const noexcept
inline std::span<const int> incoming(int v) const noexcept

Public Members

const int *out_begin = nullptr
const int *out_arcs = nullptr
const int *in_begin = nullptr
const int *in_arcs = nullptr
int n_vertices = 0
int n_arcs = 0
class CsrAdjacency

CSR adjacency built from a ProblemView’s arc arrays: the owning form of AdjacencyView. Same accessors as the shared contract’s owning adjacency (flowty/flowty#58), renamed so bgspprc’s Adjacency above stays as it is.

Invariant: every arc appears exactly once in outgoing(arc_from[a]) and exactly once in incoming(arc_to[a]).

Public Functions

CsrAdjacency() = default
inline void build(const ProblemView &pv)
inline std::span<const int> outgoing(int v) const noexcept
inline std::span<const int> incoming(int v) const noexcept
inline int n_vertices() const noexcept
inline int n_arcs() const noexcept
inline AdjacencyView view() const & noexcept

The non-owning view. Deleted on an rvalue, so binding a view to a temporary CsrAdjacency is a compile error rather than a dangle.

AdjacencyView view() const && = delete
inline operator AdjacencyView() const & noexcept
operator AdjacencyView() const && = delete
struct Adjacency

Helper to build adjacency lists from arc arrays.

Public Functions

inline void build(const ProblemView &pv)

Public Members

std::vector<std::vector<int>> outgoing
std::vector<std::vector<int>> incoming

Resources

template<typename R>
concept Resource
#include <bgspprc/resource.h>

Concept for a Meta-Solver resource type (§4.1 functions 1-6).

Each resource carries per-label state and defines:

  • symmetric: whether this resource supports symmetric labeling (§4.1)

  • extend_along_arc: how state changes along an arc

  • extend_to_vertex: how state changes at a vertex (destination marking)

  • domination_cost: extra cost penalty when L1’s state is “worse” than L2’s

  • concatenation_cost: cost adjustment when joining fw/bw labels at a vertex

template<Resource... Rs>
struct ResourcePack

Compile-time pack of resources. Labels carry a tuple of all states.

Public Types

using StatesTuple = std::tuple<typename Rs::State...>

Public Functions

inline explicit ResourcePack(Rs... rs)
inline bool symmetric() const

True if all resources in the pack support symmetric labeling.

inline StatesTuple init_states(Direction dir) const
inline std::pair<StatesTuple, double> extend_along_arc(Direction dir, const StatesTuple &states, int arc_id) const

Extend all resources along an arc (extendAlongArc). Returns (new_states, total_extra_cost). If any resource returns INF cost, the extension is infeasible.

inline std::pair<StatesTuple, double> extend_to_vertex(Direction dir, const StatesTuple &states, int vertex) const

Extend all resources to a vertex (extendToVertex). Returns (new_states, total_extra_cost).

inline double domination_cost(Direction dir, int vertex, const StatesTuple &s1, const StatesTuple &s2) const

Compute domination cost: how much extra cost L1 pays vs L2 due to resource states.

inline double min_domination_cost() const

Lower bound on domination_cost across all possible state pairs. Used for c_best pruning: if c_best + min_dom_cost > L->cost, skip bucket.

inline double concatenation_cost(Symmetry sym, int vertex, const StatesTuple &s_fw, const StatesTuple &s_bw) const

Compute concatenation cost adjustment for joining forward/backward labels. If any resource returns INF, the concatenation is infeasible.

Public Members

std::tuple<Rs...> resources

Public Static Functions

static inline constexpr std::size_t label_state_size()

Size of the compile-time resource state tuple in bytes.

Public Static Attributes

static constexpr std::size_t size = sizeof...(Rs)
using bgspprc::EmptyPack = ResourcePack<>

Empty resource pack (no extra resources beyond main).

struct StandardResource

Standard disposable resource (time windows, capacity, etc.).

State = double (accumulated consumption q). Extension: q’ = max(q + d_a, lb[v’]), infeasible if q’ > ub[v’]. Domination cost: INF when L1’s state exceeds L2’s (forward: s1 > s2, backward: s1 < s2), otherwise 0 (Meta-Solver §4.2.1). Concatenation cost: INF when fw/bw states are incompatible at join vertex.

This resource is typically used as one of the 1-2 “main resources” that define the bucket grid. Main resource extension is handled directly in the bucket graph labeling loop (not via the resource pack) for performance.

When used as a non-main resource in the pack, it provides additional resource constraints (e.g., a third resource beyond the 2 main ones).

Public Types

using State = double

Public Functions

inline bool symmetric() const

Standard resource symmetry depends on arc consumptions and bounds (Meta-Solver 2026 §4.2.1). Caller should verify conditions externally; conservatively returns false.

inline StandardResource(const double *consumption_, const double *lb_, const double *ub_, int source_, int sink_, int n_arcs_)
inline State init_state(Direction dir) const
inline std::pair<State, double> extend_along_arc(Direction dir, State q, int arc_id) const

Extend along arc. Returns (new_state, cost_delta). cost_delta = INF means infeasible.

inline std::pair<State, double> extend_to_vertex(Direction dir, State q, int vertex) const

Extend to vertex: clamp to vertex bounds and check feasibility. Forward: q = max(q, lb[v]), infeasible if q > ub[v]. Backward: q = min(q, ub[v]), infeasible if q < lb[v].

inline double domination_cost(Direction dir, int, State s1, State s2) const

Exact, not within EPS: extend_to_vertex checks windows strictly, so a dominator an EPS past s2 could be cut where s2 is not (#114).

inline double min_domination_cost() const

Lower bound on domination_cost: always 0.

inline double concatenation_cost(Symmetry sym, int vertex, State s_fw, State s_bw) const

Public Members

const double *consumption
const double *lb
const double *ub
int source
int sink
int n_arcs
struct SideResources

The resources of a ProblemView past its main ones, as one pack resource.

The bucket grid takes at most two main resources from the view and never reads the rest: resources [min(n_main_resources, 2), n_resources) are the pack’s to enforce. This resource enforces resources [first, first + n) of the view, each a standard resource (StandardResource’s extension, domination and concatenation), with equality in dominance for a non-disposable one. The count is a runtime value up to kMaxSideResources, so one instantiation serves every view.

Public Types

using State = std::array<double, kMaxSideResources>

Public Functions

inline SideResources(const ProblemView &pv, int first_, int n_)

Throws std::invalid_argument unless [first, first + n) lies in the view’s resources and n <= kMaxSideResources.

inline bool symmetric() const
inline State init_state(Direction dir) const
inline std::pair<State, double> extend_along_arc(Direction dir, State q, int arc_id) const
inline std::pair<State, double> extend_to_vertex(Direction dir, State q, int vertex) const
inline double domination_cost(Direction dir, int, const State &s1, const State &s2) const

Exact, as StandardResource’s (#114).

inline double min_domination_cost() const
inline double concatenation_cost(Symmetry sym, int vertex, const State &s_fw, const State &s_bw) const

Public Members

const double *const *arc_resource
const double *const *vertex_lb
const double *const *vertex_ub
const bool *resource_nondisposable
int source
int sink
int first
int n
constexpr int bgspprc::kMaxSideResources = 8
struct CumulativeCostResource

Cumulative cost resource R^cc for CCVRP (Meta-Solver 2026 §5).

Minimizes weighted average arrival time. Forward state tracks (cumulative_cost S, arrival_time T); backward tracks (cumulative_cost S, cumulative_weight W).

Key property: extend_along_arc returns non-zero cost deltas, exercising ResourcePack cost accumulation.

Public Functions

inline bool symmetric() const
inline CumulativeCostResource(const double *travel_time_, const double *weight_, double W_max_, double T_max_, int n_arcs_)
inline State init_state(Direction) const
inline std::pair<State, double> extend_along_arc(Direction dir, State s, int arc_id) const

Forward: S’ = S + w_a * (T + l_a), T’ = T + l_a, cost_delta = w_a * (T + l_a) Backward: S’ = S + (W + w_a) * l_a, W’ = W + w_a, cost_delta = (W + w_a) * l_a

inline std::pair<State, double> extend_to_vertex(Direction, State s, int) const

No vertex-level changes.

inline double domination_cost(Direction dir, int, State s1, State s2) const

Forward: (S1 - S2) + max(0, T1 - T2) * W_max Backward: (S1 - S2) + max(0, W1 - W2) * T_max

inline double min_domination_cost() const

Conservative lower bound on domination_cost across all state pairs. The actual minimum can be negative (e.g. s1.S < s2.S), but 0 is a safe bound for c_best pruning.

inline double concatenation_cost(Symmetry, int, State s_fw, State s_bw) const

Cross-product: T_fw * W_bw.

Public Members

const double *travel_time
const double *weight
double W_max
double T_max
int n_arcs
struct State

Public Members

double S
double T_or_W
struct PickupDeliveryResource

Simultaneous pickup-and-delivery resource R^spd (Meta-Solver 2026 §6).

Forward state: (P = pickup collected, D = remaining delivery capacity). Backward state: (P_bar = remaining pickup capacity, D_bar = delivery served).

All changes happen at vertices (extend_to_vertex), not arcs. Domination is component-wise (INF or 0), concatenation checks compatibility.

Public Functions

inline bool symmetric() const
inline PickupDeliveryResource(const double *pickup_, const double *delivery_, double Q_, int n_vertices_)
inline State init_state(Direction dir) const
inline std::pair<State, double> extend_along_arc(Direction, State s, int) const

No-op: all changes happen at vertices.

inline std::pair<State, double> extend_to_vertex(Direction dir, State s, int vertex) const

Forward: P’ = P + p_v, D’ = min(D - d_v, Q - P’), infeasible if P + p_v > Q or d_v > D. Backward: P_bar’ = min(P_bar - p_v, Q - (D_bar + d_v)), D_bar’ = D_bar + d_v, infeasible if D_bar + d_v > Q or p_v > P_bar.

inline double domination_cost(Direction dir, int, State s1, State s2) const

Forward: INF if P1 > P2 or D1 < D2, else 0. Backward: INF if D_bar1 > D_bar2 or P_bar1 < P_bar2, else 0. Exact, not within EPS: the EPS in extend_to_vertex and here would add up, so a dominator could be cut where the label it pruned is not (#114).

inline double min_domination_cost() const

Lower bound on domination_cost: 0 (returns 0 or INF).

inline double concatenation_cost(Symmetry, int, State s_fw, State s_bw) const

Concatenation: INF if P_fw > P_bar_bw or D_bar_bw > D_fw, else 0.

Public Members

const double *pickup
const double *delivery
double Q
int n_vertices
struct State

Public Members

double P
double D

ng-paths

struct NgPathData

Derived ng-path data: local bit maps and per-arc transforms. Owns its arrays; borrowed by NgPathView.

Subclassed by bgspprc::NgPathResource

Public Functions

inline NgPathData()
inline NgPathData(int n_vertices, int n_arcs, const int *arc_from, const int *arc_to, const std::vector<std::vector<int>> &neighbors)

Public Members

int n_vertices_
int n_arcs_
std::vector<int8_t> bit_map
std::vector<int8_t> self_bit_
std::vector<ArcInfo> arc_info
std::vector<std::vector<int>> neighbors_
struct ArcInfo

Per-arc precomputed transform data for both directions.

Public Members

int8_t fw_check_bit
std::array<std::pair<int8_t, int8_t>, 32> fw_shift_pairs
int fw_n_pairs
int8_t bw_check_bit
std::array<std::pair<int8_t, int8_t>, 32> bw_shift_pairs
int bw_n_pairs
class NgPathView

Borrowing ng-path resource over caller-owned NgPathData. The data must outlive the view. compress_state is what lets BucketGraph find it as the ng resource of a pack (it duck-types that member).

Public Types

using State = uint32_t

Public Functions

NgPathView() = delete
inline explicit NgPathView(const NgPathData &data) noexcept
NgPathView(const NgPathData&&) = delete
inline bool symmetric() const

Ng-path resource is always symmetric (Meta-Solver 2026 §4.2.2).

inline State init_state(Direction) const

Initialize state: empty (BucketGraph calls extend_to_vertex to mark source/sink).

inline std::pair<State, double> extend_along_arc(Direction dir, State s, int arc_id) const

extendAlongArc: transform bit vector from source ordering to target ordering. Does NOT mark the destination vertex — that’s done by extend_to_vertex.

inline std::pair<State, double> extend_to_vertex(Direction, State s, int vertex) const

extendToVertex: set the destination vertex’s self bit, and also mark vertex in its own ng-neighborhood (if v ∈ N(v)) so that self-loop arcs are correctly detected by extend_along_arc’s check.

inline double domination_cost(Direction, int, State s1, State s2) const

Domination: L1 dominates L2 only if L1’s visited set is subset of L2’s. Same vertex → same local mapping (including self bit, which is always set in both), so direct bitwise comparison works.

inline double min_domination_cost() const

Lower bound on domination_cost: 0 (subset check returns 0 or INF).

inline double concatenation_cost(Symmetry, int, State s_fw, State s_bw) const

Concatenation: across-arc (i,j) produces fw state at j via extend_along_arc only (no self bit for j), while bw state at j has j’s self bit set. Any common bit means a vertex visited in both directions → cycle.

inline uint32_t compress_state(State s, int vertex) const

Strip self bit from state for SoA storage (all labels in a bucket share the same vertex, so the self bit is always 1 — redundant for dominance).

struct NgPathResource : public bgspprc::NgPathData

Owning ng-path resource: NgPathData plus the resource methods, forwarded to a view over itself.

Public Types

using State = NgPathView::State

Public Functions

inline NgPathView view() const & noexcept

The borrowing view. Deleted on an rvalue, so a view of a temporary is a compile error rather than a dangle.

NgPathView view() const && = delete
inline bool symmetric() const
inline State init_state(Direction dir) const
inline std::pair<State, double> extend_along_arc(Direction dir, State s, int arc_id) const
inline std::pair<State, double> extend_to_vertex(Direction dir, State s, int vertex) const
inline double domination_cost(Direction dir, int vertex, State s1, State s2) const
inline double min_domination_cost() const
inline double concatenation_cost(Symmetry sym, int vertex, State s_fw, State s_bw) const
inline uint32_t compress_state(State s, int vertex) const
inline NgPathData()
inline NgPathData(int n_vertices, int n_arcs, const int *arc_from, const int *arc_to, const std::vector<std::vector<int>> &neighbors)

Rank-1 cuts

struct R1Cut

Rank-1 Cut definition (caller provides).

A cut with limited arc memory (lm-R1C, Pecin et al. 2017): a path’s coefficient is ⌊Σ_v p_v·a_v⌋, summed over the visits a_v to the base set while the path stays on memory arcs; leaving the memory resets the sum. Every multiplier is a fraction p_v = k_v/d in (0, 1) over a common denominator d ∈ [2, 8] — the subset-row family SR12, SR32, SR52 (d = 2), SR43, SR53 (3), SR54 (4), SR55, SR65 (5), SR76 (6), SR87 (7), SR98 (8). set_cuts takes d as the smallest denominator the multipliers share: ⌊Σ k_v a_v / d⌋ is the same for any common one, and the smallest takes the fewest bits. A vertex listed twice adds both multipliers, as in pull-rcspp’s cut form.

Public Members

std::vector<int> base_set
std::vector<double> multipliers
std::vector<std::pair<int, int>> memory_arcs
double dual_value = 0.0
struct R1VertexCut

Rank-1 cut with vertex memory, pull-rcspp’s cut form field for field: a path’s coefficient is ⌊Σ_v k_v·a_v / d⌋ over its visits a_v to the coefficient vertices while it stays inside the memory. With M’ = memory ∪ coefficient vertices, arc (i, j) keeps the running sum iff both i and j are in M’; any other arc resets it. Each numerator lies in [1, d - 1], and a vertex listed twice sums its numerators. The denominator is taken as given, not reduced to the smallest one the numerators share.

Public Members

std::vector<std::pair<int, int>> coefficients
int denominator = 2
std::vector<int> memory
double dual = 0.0
template<std::size_t Words>
class BasicR1CData

Derived R1C data: the active cuts, their packed layout and the lookup masks. Owns its arrays; borrowed by BasicR1CView. Rebuilt by set_cuts whenever the cuts or their duals change.

Layout: each cut c holds its running sum mod d_c in a field of w_c = ⌈log2 d_c⌉ bits (1 for d = 2, 2 for d ∈ {3, 4}, 3 for d ∈ [5, 8]), placed in cut order in the Words 64-bit words of the state; a field never straddles two words. On the global layout (

set_cuts(cuts, n_vertices,

n_arcs)

) every cut has its field at every vertex. On the per-vertex layout (the ProblemView overloads) a cut has a field only at the vertices of M’, where its sum can be nonzero. In cut order, each cut takes the lowest place free at every vertex of M’, so that most arcs keep a field in place; where no place is free at all of them, each vertex gives it its own lowest free place. Which cuts fit is decided by packing each vertex in cut order with no gaps (as before #150), and that packing is also the layout where the shared places would leave a cut out (they can split a vertex’s free bits into holes too narrow for a later field). A state is read in the layout of the vertex it is at, and an arc moves a kept field whose places at its two ends differ. A cut that does not fit makes set_cuts throw, as does a malformed one; on a throw the previous cuts stay.

Subclassed by bgspprc::BasicR1CResource< 1 >, bgspprc::BasicR1CResource< Words >

Public Functions

template<Executor Exec = SequentialExecutor>
inline void set_cuts(std::span<const R1Cut> cuts, int n_vertices, int n_arcs, Exec &&exec = {})

Set the active cuts (arc memory) on the global layout: every cut has its field at every vertex, so they share 64·Words bits. Rebuilds the layout and all lookup tables. Throws R1CError (InvalidCut) if a cut is malformed (sizes differ, a multiplier outside (0, 1) or not k/d for some d ≤ 8, a vertex or arc out of range, a NaN dual), or (TooManyCounters) if the cuts need more than 64·Words bits. The executor is used to parallelize the arc-memory masks over cuts.

template<Executor Exec = SequentialExecutor>
inline void set_cuts(std::span<const R1Cut> cuts, const ProblemView &pv, Exec &&exec = {})

Set the active cuts (arc memory) on the per-vertex layout: a cut has a field only at its base-set vertices and the ends of its memory arcs, placed as the class comment says, so 64·Words bits bound the cuts sharing a vertex, not all of them. The view gives the arc endpoints and must be the one the resource prices. Throws as the global overload, TooManyCounters naming the cut and the vertex where it found no room.

template<Executor Exec = SequentialExecutor>
inline void set_cuts(std::span<const R1VertexCut> cuts, const ProblemView &pv, Exec &&exec = {})

Set the active cuts (vertex memory, pull-rcspp’s form) on the per-vertex layout: a cut has a field at the vertices of M’ (its memory and coefficient vertices). The view gives the arc endpoints the memory is read on, and must be the one the resource prices. Throws as the R1Cut overloads, InvalidCut also for a denominator outside [2, 8], a numerator outside [1, d - 1] or a memory vertex out of range.

inline int n_active() const
inline bool per_vertex() const

True for the per-vertex layout (the ProblemView overloads).

inline Field field(int cut) const

Cut c’s field on the global layout. On the per-vertex layout it has word == -1 and only the width and denominator: use field(cut, v).

inline Field field(int cut, int vertex) const

Cut c’s field at vertex v (word == -1 where it has no slot).

inline double beta(int cut) const

Cut c’s β = max(0, -σ).

Public Static Functions

static inline R1CFit fit(std::span<const R1Cut> cuts, const ProblemView &pv)

Which of cuts the per-vertex layout of set_cuts(cuts, pv) has room for, without throwing for a cut that has none. Packs as set_cuts does (the same code), greedily in cut order: a cut is placed iff each vertex of its M’ has a free place for its field, and takes room only then. So set_cuts accepts cuts iff unplaced is empty, and accepts the placed cuts alone, though not always in the same slots: the subset may take the shared places where cuts took the gap-free ones (class comment). The packing is not monotone in field width: an R1Cut whose multipliers reduce to a smaller d than its R1VertexCut twin may pack differently. A malformed cut still throws R1CError (InvalidCut), as set_cuts would.

static inline R1CFit fit(std::span<const R1VertexCut> cuts, const ProblemView &pv)

fit for vertex-memory cuts: the room set_cuts(cuts, pv) has for them on its per-vertex layout.

Public Static Attributes

static constexpr std::size_t kWords = Words
struct Field

Where a cut’s field lives in the state at a vertex. word is -1 where the cut has no slot.

Public Members

int word = 0
int shift = 0
int width = 0
int denominator = 2
template<std::size_t Words>
class BasicR1CView

lm-R1C resource conforming to the Resource concept, borrowing caller-owned BasicR1CData (flowty/flowty#58), 8 bytes. The data must outlive the view. It carries the is_r1c_resource tag, by which detail::R1CResourceIndex finds it in a pack.

State: per cut, its running sum mod d in its field (see BasicR1CData). extend_along_arc: memory reset (keep the fields of cuts that remember the arc: arc ∈ AM, or both its ends in M’ for vertex memory). extend_to_vertex: add the vertex’s numerators; a sum reaching d pays +β per multiple of d and keeps the remainder. On 1-bit cuts with numerator 1 (the 3-SRC) that is a toggle, and runs word-parallel.

Public Types

using State = R1CState<Words>
using Data = BasicR1CData<Words>

Public Functions

BasicR1CView() = delete
inline explicit BasicR1CView(const Data &data) noexcept
BasicR1CView(const Data&&) = delete
inline int n_active() const
inline bool symmetric() const
inline State init_state(Direction) const
inline std::pair<State, double> extend_along_arc(Direction dir, State state, int arc_id) const

Memory reset along arc: keep the fields of cuts that remember the arc (arc ∈ AM, or both ends in M’).

inline std::pair<State, double> extend_to_vertex(Direction, State state, int vertex) const

Add the vertex’s numerators. A 1-bit field with numerator 1 toggles, and pays +β when it was set; any other adds k_v and pays +β per multiple of d reached.

inline double domination_cost(Direction, int vertex, State s1, State s2) const

Extra cost L1 must overcome to dominate L2 — a non-negative PENALTY. For each cut where the dominator L1’s sum exceeds the dominated L2’s, some completion lifts L1 to d one visit before L2 (both sums lie in [0, d), so never more than once more), so L1 pays at most one extra +β: c(L1) + Σ_{s1 > s2} β ≤ c(L2) dominates for every completion.

inline double min_domination_cost() const

Lower bound on domination_cost: 0. The dominance penalty is a sum of +β (β ≥ 0), so it is never negative.

inline double concatenation_cost(Symmetry, int vertex, State s_fw, State s_bw) const

Cost when joining fw/bw labels: a cut whose two sums reach d together gains one more coefficient on the joined path (both lie in [0, d), so at most one) and is charged +β. On 1-bit fields: both bits set.

Public Static Functions

static inline uint64_t word(const State &s, std::size_t i)

Word i of a state.

static inline constexpr uint64_t exceeds2(uint64_t left, uint64_t right, uint64_t low)

For each field of left’s layout of width 2 (with low its lowest bits), the lowest bit set where left’s field exceeds right’s. Bit-parallel over the word: with (a b) the left field and (c d) the right one, (a b) > (c d) ⟺ a¬c ∨ (a = c) b¬d.

static inline constexpr uint64_t exceeds3(uint64_t left, uint64_t right, uint64_t low)

As exceeds2 for 3-bit fields: (a b c) > (d e f).

Public Static Attributes

static constexpr bool is_r1c_resource = true
template<std::size_t Words>
struct BasicR1CResource : public bgspprc::BasicR1CData<Words>

Owning R1C resource: BasicR1CData plus the resource methods, forwarded to a view over itself.

Public Types

using View = BasicR1CView<Words>
using State = View::State

Public Functions

inline View view() const & noexcept

The borrowing view. Deleted on an rvalue, so a view of a temporary is a compile error rather than a dangle.

View view() const && = delete
inline bool symmetric() const
inline State init_state(Direction dir) const
inline std::pair<State, double> extend_along_arc(Direction dir, State state, int arc_id) const
inline std::pair<State, double> extend_to_vertex(Direction dir, State state, int vertex) const
inline double domination_cost(Direction dir, int vertex, State s1, State s2) const
inline double min_domination_cost() const
inline double concatenation_cost(Symmetry sym, int vertex, State s_fw, State s_bw) const

Public Static Attributes

static constexpr bool is_r1c_resource = true
using bgspprc::R1CData = BasicR1CData<1>

One state word: 64 one-bit cuts (3-SRCs), 32 two-bit or 21 three-bit ones.

using bgspprc::R1CView = BasicR1CView<1>
using bgspprc::R1CResource = BasicR1CResource<1>
template<std::size_t Words>
using bgspprc::R1CState = std::conditional_t<Words == 1, uint64_t, std::array<uint64_t, Words>>

The packed state of Words 64-bit words: a plain uint64_t for one word, so that with only 1-bit cuts, cut c is bit c.

struct R1CFit

Which cuts of a set fit the per-vertex layout, from BasicR1CData::fit. unplaced lists, ascending, the indices of the cuts that found no room at some vertex of their M’; bit_fails[v] counts the unplaced cuts that found no room at vertex v (one entry per vertex of the view).

Public Members

std::vector<int> unplaced
std::vector<int> bit_fails
struct R1CError : public std::invalid_argument

What set_cuts throws. Derives from std::invalid_argument, so callers catching that keep working. cut is the index of the offending cut and vertex the offending vertex, -1 where none applies.

Public Functions

inline R1CError(R1CErrc errc, const char *what, int cut_index, int vertex_id = -1)

Public Members

R1CErrc code
int cut = -1
int vertex = -1
enum class bgspprc::R1CErrc : uint8_t

Why set_cuts refused its cuts.

Values:

enumerator InvalidCut

a malformed cut: bad sizes, multiplier, numerator, denominator, vertex or arc, or a NaN value

enumerator TooManyCounters

the fields need more bits than the state words hold

constexpr int bgspprc::kR1CMaxDenominator = 8

The largest denominator of a cut’s multipliers.

Executors

template<typename E>
concept Executor
#include <bgspprc/executor.h>

Pluggable execution strategy. Structural: no base class.

  • parallel_for(begin, end, f): applies f(i) to [begin, end)

  • parallel_for_chunked(begin, end, f): f(chunk_begin, chunk_end, chunk_idx) receives bulk ranges and a chunk index in [0, n_threads()). chunk_idx is what lets callers index per-chunk storage lock-free – it is a chunk index, not a thread id, so it stays unique even if one worker takes two chunks.

  • parallel_invoke(f, g): runs both callables, possibly concurrently. Neither may wait on the other: SequentialExecutor, the default, runs f then g, and so does a ThreadPool already dispatching.

  • n_threads(): upper bound on chunk_idx

struct SequentialExecutor

Sequential executor. The default everywhere.

Public Functions

inline void parallel_for(int begin, int end, auto &&f) const
inline void parallel_for_chunked(int begin, int end, auto &&f) const
inline void parallel_invoke(auto &&f, auto &&g) const
inline int n_threads() const
class ThreadPool

Fork-join pool, owned by the caller – typically the BCP core, one per solve. Workers are created once and joined on destruction; the calling thread participates as chunk 0 so a core is not left idle.

Public Functions

inline explicit ThreadPool(int n_threads)

n_threads counts the calling thread, so n_threads-1 workers are spawned.

inline ~ThreadPool()
ThreadPool(const ThreadPool&) = delete
ThreadPool &operator=(const ThreadPool&) = delete
inline int n_threads() const noexcept
template<typename F>
inline void dispatch(int n_tasks, F &&task)

Runs task(i) for i in [0, n_tasks), distributed across the pool and the calling thread. Blocks until all complete. Task indices are handed out from a shared counter, so a slow chunk does not stall the others.

One dispatch at a time per pool. A call made while the pool is already dispatching – nested, from inside a task, or concurrent, from another thread – runs inline on its calling thread, in index order. bgspprc’s bidirectional solve does exactly this: parallel_invoke(bw, fw), and each side’s compact_labels calls parallel_for on the same executor. So a nested parallel_invoke(f, g) runs f, then g: f must not wait on g.

If a task throws, no further indices are handed out, the tasks already running finish, and the first exception is rethrown here.

template<typename F>
inline void parallel_for_chunked(int begin, int end, F &&f)

Every chunk is non-empty: n_chunks is recomputed from the chunk size, so a short range never yields a chunk that starts past end.

template<typename F>
inline void parallel_for(int begin, int end, F &&f)
template<typename F, typename G>
inline void parallel_invoke(F &&f, G &&g)
class ThreadPoolExecutor

Non-owning handle to a caller-owned ThreadPool. This is what gets passed to a pricer: the pool lives in the core, the executor is 8 bytes.

Public Functions

inline explicit ThreadPoolExecutor(ThreadPool &pool) noexcept
inline void parallel_for(int begin, int end, auto &&f) const
inline void parallel_for_chunked(int begin, int end, auto &&f) const
inline void parallel_invoke(auto &&f, auto &&g) const
inline int n_threads() const noexcept
struct StdThreadExecutor

Thread-backed executor using a static thread pool. parallel_for distributes work across pool threads + the calling thread. parallel_invoke runs two tasks concurrently (one on pool, one on caller).

Nested dispatch fans out: a waiter runs queued tasks, so a parallel_for inside a parallel_invoke task uses the whole pool. ThreadPoolExecutor (executor.h) differs: one dispatch at a time per pool, a nested one inline. So its parallel bidir solve compacts labels on at most 2 threads, where this executor uses all of them. Results are the same; only speed differs.

Exception safety: if a pool task throws, the exception is captured and rethrown on the calling thread after all tasks complete.

Public Functions

inline void parallel_for(int begin, int end, auto &&f) const
inline void parallel_for_chunked(int begin, int end, auto &&f) const

Divides [begin, end) into chunks (one per thread) and calls f(chunk_begin, chunk_end, chunk_idx) on each. chunk_idx is unique per chunk in [0, n_threads()), enabling lock-free per-thread accumulation. Unlike parallel_for, there is no element-count threshold: callers pass chunk-level work, so per-chunk cost is assumed high.

inline void parallel_invoke(auto &&f, auto &&g) const
inline int n_threads() const