gtopt::SDDPCutManager class

Storage for SDDP Benders cuts.

Single source of truth: per-scene vectors in m_scene_cuts_. The combined view is rebuilt on demand via build_combined_cuts. No global mutex: per-scene vectors are single-writer during the forward/backward pass (phase access within a scene is serial). Cross-scene cut sharing reads from these vectors after the phase-step barrier in run_backward_pass_synchronized, so no lock is needed there either.

Constructors, destructors, conversion operators

SDDPCutManager() defaulted

Public functions

auto at(SceneIndex scene_index) const -> const SceneCutStore& noexcept
auto at(SceneIndex scene_index) -> SceneCutStore& noexcept
auto build_combined_cuts(const PlanningLP& planning_lp) const -> std::vector<StoredCut>
Build combined stored cuts from per-scene vectors.
void cap_stored_cuts(const SDDPOptions& options, const PlanningLP& planning_lp)
Cap per-scene stored cuts to max_stored_cuts (oldest dropped).
void clear()
Clear all stored cut metadata (combined + per-scene).
auto clear_scene_cuts(SceneIndex scene_index, PlanningLP& planning_lp, bool keep_feasibility = false) -> std::ptrdiff_t
void forget_first_cuts(std::ptrdiff_t count, PlanningLP& planning_lp)
Remove the first count cuts from stored cuts and from the LP.
auto num_stored_cuts() const -> std::ptrdiff_t noexcept
Total number of stored cuts across all scenes.
void prune_inactive_cuts(const SDDPOptions& options, PlanningLP& planning_lp, const StrongIndexVector<SceneIndex, StrongIndexVector<PhaseIndex, PhaseStateInfo>>& scene_phase_states)
Prune inactive cuts from all (scene, phase) LPs.
void resize_scenes(Index num_scenes)
Resize per-scene storage to the given number of scenes.
void save_cuts_for_iteration(IterationIndex iteration_index, std::span<const uint8_t> scene_feasible, const SDDPOptions& options, PlanningLP& planning_lp, const LabelMaker& label_maker, const StrongIndexVector<SceneIndex, StrongIndexVector<PhaseIndex, PhaseStateInfo>>& scene_phase_states, SDDPWorkPool* pool = nullptr)
auto scene_cuts() const -> const auto& noexcept
Per-scene cut storage.
auto scene_cuts() -> auto& noexcept
Mutable per-scene cuts (for direct iteration access).
void store_cut(SceneIndex scene_index, PhaseIndex src_phase_index, const SparseRow& cut, CutType type, RowIndex row, SceneUid scene_uid_val, PhaseUid phase_uid_val)

Function documentation

SceneCutStore& gtopt::SDDPCutManager::at(SceneIndex scene_index) noexcept

Per-scene store accessor (step 3 of docs/analysis/investigations/sddp/sddp_cut_store_split_plan_2026-04-30.md). Replaces scene_cuts()[si] at call sites that touch one scene's cuts; keeps the migration mechanical (the wrapper's vector-like forwarders mean most reads compile unchanged after the substitution). Returns a SceneCutStore&; use .cuts() to get the underlying std::vector<StoredCut>& for span-taking APIs (e.g. save_scene_cuts_csv).

std::ptrdiff_t gtopt::SDDPCutManager::clear_scene_cuts(SceneIndex scene_index, PlanningLP& planning_lp, bool keep_feasibility = false)

Parameters
scene_index Scene whose accumulated cuts are discarded.
planning_lp PlanningLP whose cells hold the cut rows.
keep_feasibility Exempt CutType::Feasibility rows from the rollback (PLP elastic mode) — see SceneCutStore::clear_with_lp.

Discard every cut scene scene_index has accumulated. Deletes the corresponding rows from the scene's LP cells and clears m_scene_cuts_[scene_index]. Used by SDDPOptions::forward_infeas_rollback to roll back a scene declared infeasible in the forward pass — both forward-pass feasibility cuts (PLP-style backtrack chain) and earlier backward-pass optimality cuts go: the bad trajectory that produced any of them is no longer trusted. Returns the number of LP rows actually deleted.

Shared cuts received by scene_index from peers via share_cuts_for_phase are NOT in m_scene_cuts_[scene_index] (they live only as LP rows + m_active_cuts_ replay entries), so they survive this rollback — exactly the invariant that lets the next iteration's stall check distinguish "made no progress" from "received peer cuts and can retry".

void gtopt::SDDPCutManager::save_cuts_for_iteration(IterationIndex iteration_index, std::span<const uint8_t> scene_feasible, const SDDPOptions& options, PlanningLP& planning_lp, const LabelMaker& label_maker, const StrongIndexVector<SceneIndex, StrongIndexVector<PhaseIndex, PhaseStateInfo>>& scene_phase_states, SDDPWorkPool* pool = nullptr)

Save cuts (combined + per-scene) after an iteration.

When pool is non-null, the per-scene cut-file writes are dispatched as parallel tasks (16 sequential writes → 16 in parallel on a saturated pool, ~0.5–1 s saved per iteration on the large hydrothermal case scale). When pool is null, falls back to a sequential loop — used by code paths that do not have a pool available (e.g. unit tests that exercise this method directly without going through SDDPMethod::solve).

void gtopt::SDDPCutManager::store_cut(SceneIndex scene_index, PhaseIndex src_phase_index, const SparseRow& cut, CutType type, RowIndex row, SceneUid scene_uid_val, PhaseUid phase_uid_val)

Store a cut in the per-scene vector. Safe to call from scene workers concurrently since each scene has its own vector and phase access within a scene is serial.