gtopt::StateVariable class

Base classes

struct LPVariable

Public types

struct Key
using DependentVariable = LPVariable
using LPKey = gtopt::LPKey

Public static functions

template<typename ScenarioLP ScenarioLP, typename StageLP StageLP>
static auto key(const ScenarioLP& scenario, const StageLP& stage, LPClassName class_name, Uid element_uid, std::string_view col_name) -> Key
static auto key(LPClassName class_name, Uid uid, std::string_view col_name, PhaseIndex phase_index, StageUid stage_uid, SceneIndex scene_index, ScenarioUid scenario_uid) -> Key

Constructors, destructors, conversion operators

StateVariable(LPKey lp_key, ColIndex col, double scost, double var_scale, LpContext context) explicit constexpr

Public functions

template<typename ScenarioLP ScenarioLP, typename StageLP StageLP>
auto add_dependent_variable(const ScenarioLP& scenario, const StageLP& stage, ColIndex col) -> const DependentVariable&
auto add_dependent_variable(LPKey lp_key, ColIndex col) -> const DependentVariable&
auto col() const -> ColIndex noexcept
auto col_sol() const -> auto noexcept
auto col_sol_physical() const -> double noexcept
auto context() const -> const auto& noexcept
LP hierarchy context (scenario, stage, block, ...).
auto dependent_variables() const -> std::span<const DependentVariable> noexcept
auto has_col_sol() const -> bool noexcept
auto lp_key() const -> const LPKey& noexcept
auto phase_index() const -> PhaseIndex noexcept
auto reduced_cost() const -> auto noexcept
auto reduced_cost_col_scale() const -> auto noexcept
auto reduced_cost_physical(double scale_objective) const -> double noexcept
auto scene_index() const -> SceneIndex noexcept
auto scost() const -> auto noexcept
void set_col_sol(double v) const noexcept
void set_reduced_cost(double rc_lp, double dependent_col_scale) const noexcept
void set_source_reduced_cost(double v) const noexcept
void set_var_scale(double s) const noexcept
auto source_reduced_cost() const -> auto noexcept
auto var_scale() const -> auto noexcept

Function documentation

auto gtopt::StateVariable::col_sol() const noexcept

Forward-pass primal solution of this state variable's source column, in raw LP space. Multiply by var_scale() to obtain the physical value, or use col_sol_physical() below.

double gtopt::StateVariable::col_sol_physical() const noexcept

Physical-space primal solution: LP × var_scale.

For the alpha future-cost column this equals LP × scale_alpha, matching the alpha_svar->col_sol() * sa idiom at the forward- pass call sites. For state variables with var_scale = 1.0 (bare primal columns without a flatten-time semantic scale) this returns the same value as col_sol().

bool gtopt::StateVariable::has_col_sol() const noexcept

True once a solve has written col_sol (see set_col_sol). Lets readers tell a genuine 0 (e.g. a drained reservoir) from "never solved" instead of guessing from the value.

auto gtopt::StateVariable::reduced_cost() const noexcept

Reduced cost of the DEPENDENT column in the target phase's last solve, in raw LP space (i.e. in the dependent column's own LP units). Use reduced_cost_physical() below when building physical-space Benders cuts.

auto gtopt::StateVariable::reduced_cost_col_scale() const noexcept

Column scale of the DEPENDENT column whose raw reduced cost is stored in reduced_cost() (physical = LP × scale). Recorded together with the rc by set_reduced_cost, because it generally differs from this state variable's own var_scale() (the SOURCE column scale): ruiz equilibration assigns independent factors to the source column (e.g. last-block efin of phase t) and to the dependent column (sini of phase t+1).

double gtopt::StateVariable::reduced_cost_physical(double scale_objective) const noexcept

Dependent-column reduced cost lifted out of LP scaling: rc_LP × scale_objective / reduced_cost_col_scale().

The divisor is the DEPENDENT column's scale (the column the rc belongs to), NOT this state variable's var_scale() (the source column's scale). Equivalent to LinearInterface::get_col_cost()[dependent_col] on the target LP, so the two build_benders_cut_physical overloads agree.

Important: despite the name, this is NOT a truly physical reduced cost in $/[physical-unit]/hour. The per-(scenario, stage, block) cost_factor = probability × discount × duration baked into the LP cost coefficient via CostHelper::block_ecost is still folded in. The naming matches the LinearInterface::get_col_cost() convention (also LP-folded despite "physical" in its docstring), so the Benders cut builder (build_benders_cut_physical) can consume either source with identical semantics — both rely on cost_factor cancelling at the destination master LP.

To recover truly physical $/[unit]/hour, additionally divide by CostHelper::cost_factor(scenario, stage[, block]) for the state-variable's source-column context.

scale_objective is passed as an argument because it's a global option, not a per-state-variable property.

auto gtopt::StateVariable::scost() const noexcept

State cost for elastic penalty [$/physical_unit]. When > 0, overrides the global elastic_penalty for this variable.

void gtopt::StateVariable::set_reduced_cost(double rc_lp, double dependent_col_scale) const noexcept

Record the dependent column's raw LP reduced cost together with that column's own post-equilibration scale (LinearInterface::get_col_scale(dependent_col)). Both are required so reduced_cost_physical() never mixes the dependent column's rc with the source column's scale.

void gtopt::StateVariable::set_var_scale(double s) const noexcept

Update the cached var_scale to match the post-equilibration col_scale from the owning LinearInterface. Called from capture_state_variable_values so the value seen by col_sol_physical() is always the authoritative LP-side scale. Mutable through const because m_var_scale_ is a runtime cache, like m_col_sol_ and m_reduced_cost_ already are.

auto gtopt::StateVariable::source_reduced_cost() const noexcept

Reduced cost of THIS state variable's own source column in its owning phase's last solved basis, in raw LP space. Distinct from reduced_cost() above, which holds the DEPENDENT column's rc in the TARGET phase (the optimality-cut input). Captured by SDDPMethod::capture_state_variable_values at every optimal forward solve — the only point where the source phase's rc span is hot (before release_backend). Consumed by the PLP elastic cost policy (ElasticCostPolicy::Model::plp_unit_rc_tilt): PLP's AgrElastici prices each elastic slack pair with a 0.01 × rc(vf_i, t−1) tilt toward the cheapest reservoir. Lift to the LP-folded "physical" convention via × scale_objective / var_scale() — here var_scale() IS the right divisor, since the rc belongs to this (source) column.

auto gtopt::StateVariable::var_scale() const noexcept

Physical-to-LP scale: physical = LP × var_scale.

At construction, set from the user var_scale parameter (= the pre-equilibration col_scale). After LP flatten, ruiz equilibration may have multiplied an additional ruiz_factor into LinearInterface::m_scaling_.col_scales[col()]. Call set_var_scale() post-flatten to sync this cached value to the authoritative LinearInterface::get_col_scale(col()), so that col_sol_physical() and source_reduced_cost() lifting agree with the LP's internal scaling. (reduced_cost_physical() uses the dependent column's scale, see reduced_cost_col_scale().) See SDDPMethod::capture_state_variable_values for the sync site.