gtopt::AmplVariable struct

Registry value: one of three shapes for the registered attribute —

  • Per-block single col (the common case): block_cols.
  • Stage-level single col: stage_col, broadcast to every block.
  • Per-block sum of cols: block_cols_sum. The attribute resolves to Σ cols per block — used by the line PWL-direct mode where flowp / flown are the sum of per-segment LP cols rather than an aggregator column. See LineLP::add_to_lp for the piecewise_direct registration site, and element_column_resolver.cpp::resolve_col_to_row for the stamping path that expands a sum-leg into one row[col] += base · coef per element.

Exactly one of block_cols, stage_col, block_cols_sum is populated per registration (asserted by construction in the add_ampl_variable overloads).

The per-block map is stored by value because elements hold their STBIndexHolders (flat_map of BIndexHolder) and adding new entries invalidates any pointers into older values. In SDDP, add_to_lp is called once per (scenario, stage) pair, so later insertions grow the outer flat_map and reallocate its storage — any raw pointer cached here from an earlier call would dangle. Copying the BIndexHolder by value into AmplVariable sidesteps the lifetime problem entirely; the indices inside are small POD so copies are cheap.

Public types

struct Extras

Public functions

auto col_at(BlockUid block_uid) const -> std::optional<ColIndex> noexcept
auto cols_at(BlockUid block_uid) const -> std::span<const ColIndex> noexcept
auto constant_at(BlockUid block_uid) const -> std::optional<double> noexcept
auto offset_at(BlockUid block_uid) const -> double noexcept
auto weighted_cols_at(BlockUid block_uid) const -> std::span<const std::pair<ColIndex, double>> noexcept

Public variables

BIndexHolder<ColIndex> block_cols
std::unique_ptr<Extras> extras
AmplVariableKind kind
ColIndex stage_col

Function documentation

std::span<const ColIndex> gtopt::AmplVariable::cols_at(BlockUid block_uid) const noexcept

Look up the per-block sum-of-cols list for this block. Returns an empty span when this registration is not a sum-of-cols entry, or when the block has no list entry. Callers prefer the single-col col_at path; this is the fall-through for virtual aggregators.

std::optional<double> gtopt::AmplVariable::constant_at(BlockUid block_uid) const noexcept

Constant-only entry: the block carries an offset but NO column — the attribute was folded into a constant (e.g. a fixed-discharge Flow under --lp-reduction). The resolver then contributes the constant to the row RHS instead of reporting an unknown attribute.

double gtopt::AmplVariable::offset_at(BlockUid block_uid) const noexcept

Look up the per-block additive offset. Returns 0.0 when this registration has no offset table or no entry for this block — the expected case for every element except those using a shifted- variable encoding (Option C demand-fail).

std::span<const std::pair<ColIndex, double>> gtopt::AmplVariable::weighted_cols_at(BlockUid block_uid) const noexcept

Look up the per-block WEIGHTED sum-of-cols list for this block. Returns an empty span when this registration carries no weighted sum, or when the block has no list entry. Resolver stamping path: row[col] += base_coef · weight per (col, weight).

Variable documentation

BIndexHolder<ColIndex> gtopt::AmplVariable::block_cols

Per-block column map for this (scenario, stage). Empty when this entry represents a stage-level variable (see stage_col) or a per-block sum-of-cols (see block_cols_sum).

AmplVariableKind gtopt::AmplVariable::kind

Regular LP column or state-backed column. Always Regular today (see AmplVariableKind).

ColIndex gtopt::AmplVariable::stage_col

Stage-level column: same value for every block in the stage. Only meaningful when block_cols and block_cols_sum are empty.