gtopt::SceneIterationTracker class

Tracks per-scene iteration progress for async SDDP execution.

All methods are called from the main thread only (the one running the state-machine orchestration loop). Pool tasks write results into their futures; the main thread collects them and updates the tracker. No thread safety is required.

Constructors, destructors, conversion operators

SceneIterationTracker() defaulted
SceneIterationTracker(Index num_scenes, int max_spread) explicit

Public functions

auto all_complete(IterationIndex iteration_index) const -> bool
auto all_converged() const -> bool
True when ALL scenes have individually converged.
auto bounds_for_iteration(IterationIndex iteration_index) const -> std::vector<SceneBounds>
auto converged_iteration(SceneIndex scene_index) const -> IterationIndex
Iteration at which a scene converged (-1 if not yet converged).
auto is_converged(SceneIndex scene_index) const -> bool
True if a specific scene has individually converged.
void mark_converged(SceneIndex scene_index, IterationIndex iteration_index)
Mark a scene as individually converged at the given iteration.
auto max_completed_iteration() const -> IterationIndex
Maximum completed iteration across all scenes.
auto max_spread() const -> int
auto min_completed_iteration() const -> IterationIndex
auto min_completed_iteration_among_active() const -> IterationIndex
auto num_converged() const -> Index
Number of scenes that have individually converged.
auto num_scenes() const -> Index
void report_complete(SceneIndex scene_index, IterationIndex iteration_index, double ub, double lb, bool feasible)
auto scene_iterations() const -> std::vector<int>

Function documentation

bool gtopt::SceneIterationTracker::all_complete(IterationIndex iteration_index) const

True when ALL scenes have completed at least iteration iteration_index.

std::vector<SceneBounds> gtopt::SceneIterationTracker::bounds_for_iteration(IterationIndex iteration_index) const

Get per-scene bounds for iteration iteration_index. Requires all_complete(iteration_index) to return true.

IterationIndex gtopt::SceneIterationTracker::min_completed_iteration() const

Minimum completed iteration across all scenes. Returns IterationIndex{-1} if no scene has completed any iteration.

IterationIndex gtopt::SceneIterationTracker::min_completed_iteration_among_active() const

Minimum completed iteration across non-converged (active) scenes only. Once a scene converges its m_scene_completed_iter_ entry is frozen at the convergence iteration and never advances again; without excluding those scenes here, the global minimum stays pinned and the solve_async max_spread gate at sddp_iteration.cpp:1322-1328 permanently blocks every still- active scene from advancing past min + max_spread.

Result: the outer while(!all_done) loop in solve_async (sddp_iteration.cpp:1758) keeps spinning because some scenes are stuck in idle with no work scheduled — observed on the large hydrothermal case hs8 where 6 wettest scenes converged at iter 51 and the 9 dry scenes wedged at iter 54 against min=51 + 2 = 53.

Returns the same value as min_completed_iteration() when no scene has converged yet. Returns IterationIndex::max() when all scenes have converged (caller should treat as "no spread constraint").

void gtopt::SceneIterationTracker::report_complete(SceneIndex scene_index, IterationIndex iteration_index, double ub, double lb, bool feasible)

Record that scene completed iteration iteration_index with the given bounds. Maintains a ring buffer of depth max_spread + 1 per scene.

std::vector<int> gtopt::SceneIterationTracker::scene_iterations() const

Snapshot of per-scene completed iteration indices, as raw int for the JSON serialisation boundary (SolverStatusSnapshot, SDDPIterationResult). The unwrap here is legitimate — downstream consumers only print/JSON-serialise these values and never use them as IterationIndex identities.