#include <gtopt/storage_lp.hpp>
template<typename Object Object>
StorageLP class
Base classes
- struct Object
- Base object type providing common identification functionality.
Derived classes
-
template<typename Storage, typename NodeLP, auto NodeRef, const StorageStateDefaults& Defaults>class CarrierStorageLP
-
template<typename Storage, typename NodeLP, auto NodeRef, const StorageStateDefaults& Defaults>class CarrierStorageLP
-
template<typename Storage, typename NodeLP, auto NodeRef, const StorageStateDefaults& Defaults>class CarrierStorageLP
Public static variables
- static std::string_view CapacityName
- static std::string_view CycleChainName
- static std::string_view CycleCloseName
- static std::string_view CycleLimitName
- static std::string_view CycleScaleName
- static std::string_view CycleShiftCapName
- static std::string_view CycleShiftName
- static std::string_view DrainName
- static std::string_view EfinName
- static std::string_view EfinSlackName
- static std::string_view EiniName
- static std::string_view EnergyBalanceName
- static std::string_view EnergyName
- static std::string_view EnvelopeDnName
- static std::string_view EnvelopeUpName
- static std::string_view SeminGeName
- static std::string_view SiniName
- static std::string_view SoftEminName
Constructors, destructors, conversion operators
-
template<typename ObjectT>StorageLP(ObjectT&& pstorage, const InputContext& ic, const LPClassName& cname) explicit
Public functions
-
template<typename SystemContextT, typename FinpEffFn, typename FoutEffFn>auto add_to_lp(const LPClassName& cname, std::string_view ampl_class, SystemContextT& sc, const ScenarioLP& scenario, const StageLP& stage, LinearProblem& lp, const double flow_conversion_rate, const BIndexHolder<ColIndex>& finp_cols, FinpEffFn&& finp_efficiency_at, const BIndexHolder<ColIndex>& fout_cols, FoutEffFn&& fout_efficiency_at, const double stage_capacity, const std::optional<ColIndex> capacity_col = {}, const std::optional<Real> drain_cost = {}, const std::optional<Real> drain_capacity = {}, const StorageOptions opts = {}) -> bool
-
template<typename OutputContext OutputContext>auto add_to_output(OutputContext& out, std::string_view cname, std::string_view energy_dual_name = EnergyName) const -> bool
- auto balance_time_scale_at(const ScenarioLP& scenario, const StageLP& stage) const -> double
- auto drain_cols_at(const ScenarioLP& scenario, const StageLP& stage) const -> const auto&
- auto efin_col_at(const ScenarioLP& scenario, const StageLP& stage) const -> auto
- auto efin_slack_col_at(const ScenarioLP& scenario, const StageLP& stage) const -> std::optional<ColIndex>
- auto eini_col_at(const ScenarioLP& scenario, const StageLP& stage) const -> ColIndex
- auto energy_cols_at(const ScenarioLP& scenario, const StageLP& stage) const -> const auto&
- auto energy_rows_at(const ScenarioLP& scenario, const StageLP& stage) const -> const auto&
- auto energy_scale() const -> double noexcept
- auto find_drain_cols(const ScenarioLP& scenario, const StageLP& stage) const -> const BIndexHolder<ColIndex>* noexcept
- auto find_efin_col(const ScenarioLP& scenario, const StageLP& stage) const -> std::optional<ColIndex> noexcept
- auto find_efin_row(const ScenarioLP& scenario, const StageLP& stage) const -> std::optional<RowIndex> noexcept
- auto find_eini_col(const ScenarioLP& scenario, const StageLP& stage) const -> std::optional<ColIndex> noexcept
- auto find_energy_rows(const ScenarioLP& scenario, const StageLP& stage) const -> const BIndexHolder<RowIndex>* noexcept
- auto flow_scale() const -> double noexcept
-
template<typename Self>auto id(this const Self& self) -> auto noexcept
- Gets the object's identifier (explicit object syntax).
- auto output_dual_scale_at(const ScenarioLP& scenario, const StageLP& stage) const -> double
- auto physical_efin(const LinearInterface& li, const ScenarioLP& scenario, const StageLP& stage, double default_efin) const -> double
-
template<typename SystemLPT>auto physical_efin(const SystemLPT& sys, const ScenarioLP& scenario, const StageLP& stage, double default_efin) const -> double
- Overload accepting a SystemLP (extracts LinearInterface internally).
- auto physical_eini(const LinearInterface& li, const ScenarioLP& scenario, const StageLP& stage, double default_eini) const -> double
-
template<typename SystemLPT, typename SIdT>auto physical_eini(const SystemLPT& sys, const ScenarioLP& scenario, const StageLP& stage, double default_eini, const SIdT& sid) const -> double
- auto soft_emin_col_at(const ScenarioLP& scenario, const StageLP& stage) const -> std::optional<ColIndex>
- auto storage(this auto&& self) -> auto&& noexcept
- auto to_physical(double lp_value) const -> double noexcept
- Convert an LP-unit energy/volume value to physical units.
Parameter accessors for user constraint resolution
- auto param_emin(StageUid s, BlockUid b) const -> auto
- auto param_emax(StageUid s, BlockUid b) const -> auto
- auto param_ecost(StageUid s, BlockUid b) const -> auto
Function documentation
template<typename Object Object>
template<typename SystemContextT, typename FinpEffFn, typename FoutEffFn>
bool gtopt:: StorageLP<Object>:: add_to_lp(const LPClassName& cname,
std::string_view ampl_class,
SystemContextT& sc,
const ScenarioLP& scenario,
const StageLP& stage,
LinearProblem& lp,
const double flow_conversion_rate,
const BIndexHolder<ColIndex>& finp_cols,
FinpEffFn&& finp_efficiency_at,
const BIndexHolder<ColIndex>& fout_cols,
FoutEffFn&& fout_efficiency_at,
const double stage_capacity,
const std::optional<ColIndex> capacity_col = {},
const std::optional<Real> drain_cost = {},
const std::optional<Real> drain_capacity = {},
const StorageOptions opts = {})
| Parameters | |
|---|---|
| cname | Class name used for column/row labels. |
| ampl_class | AMPL class name under which the storage attributes are registered for user constraints (empty to skip the registration). |
| sc | System context (schedules, state variables). |
| scenario | Scenario being built. |
| stage | Stage being built. |
| lp | Linear problem that receives the columns/rows. |
| flow_conversion_rate | Flow-to-energy factor applied to the inflow / outflow / drain terms of the energy balance. |
| finp_cols | Per-block inflow (charge) columns. |
| finp_efficiency_at | Callable (BlockUid) -> double returning the per-block charge / inflow efficiency. Pass a lambda sampling an OptTBRealSched for per-block schedules (e.g. Battery's input_efficiency since PR-E), or [](BlockUid){ return 1.0; } for elements with no efficiency loss (Reservoir / LngTerminal / VolumeRight). |
| fout_cols | Per-block outflow (discharge) columns. |
| fout_efficiency_at | Same shape, for discharge / outflow. |
| stage_capacity | Installed capacity of the stage, used to resolve the per-block energy bounds. |
| capacity_col | Optional expansion capacity column; when set, each block's energy is bounded by it. |
| drain_cost | Optional cost of the drain (spill) column; no drain column is added when unset. |
| drain_capacity | Optional upper bound of the drain column (unbounded when unset; a value <= 0 disables the drain). |
| opts | Storage options (state variables, daily cycle, scaling, ...). |
| Returns | true on success. |
Add the storage energy-balance columns and rows of one (scenario, stage) to lp.
template<typename Object Object>
double gtopt:: StorageLP<Object>:: balance_time_scale_at(const ScenarioLP& scenario,
const StageLP& stage) const
Time scale of the energy-balance rows of (scenario, stage): the factor an external term fcr · rate · duration_b (block weight) must carry to enter the balance in the units of the storage's own flows. 1 except on periodic stages under model_options.periodic_storage, where the balance runs on ONE typical period (real Δt = duration_b · period_hours / duration).
template<typename Object Object>
const auto& gtopt:: StorageLP<Object>:: drain_cols_at(const ScenarioLP& scenario,
const StageLP& stage) const
Return the drain/spill column indices for (scenario, stage).
Drain columns represent the spillway (for reservoirs) or energy curtailment (for batteries). They are only present when the storage object has a non-zero drain cost; if absent for the requested pair, std::out_of_range is thrown (caught by the user-constraint resolver to produce a graceful std::nullopt).
template<typename Object Object>
std::optional<ColIndex> gtopt:: StorageLP<Object>:: efin_slack_col_at(const ScenarioLP& scenario,
const StageLP& stage) const
Return the soft-efin slack column for (scenario, stage), if it exists.
The slack is created only when Reservoir.efin is set AND Reservoir.efin_cost is > 0 AND the stage is the last stage of the last phase. Returns std::nullopt when the column was not created (i.e., the hard vol_end >= efin row is in effect, or no efin target exists for this storage element).
template<typename Object Object>
ColIndex gtopt:: StorageLP<Object>:: eini_col_at(const ScenarioLP& scenario,
const StageLP& stage) const
Return the initial-energy column for (scenario, stage).
Three cases:
- Global initial condition (first stage of first phase): stored in eini_cols with a fixed "eini" column.
- Same-phase reuse: eini_cols stores the previous stage's efin col.
- Cross-phase SDDP boundary: sini_cols stores the "sini" col; fall back from eini_cols (which does NOT have this entry) to sini_cols.
Invariant: every active (scenario, stage) pair is stored in exactly one of the two maps. The fallback throws std::out_of_range only if the caller passes an invalid (scenario, stage) combination.
template<typename Object Object>
const auto& gtopt:: StorageLP<Object>:: energy_rows_at(const ScenarioLP& scenario,
const StageLP& stage) const
Return the energy balance row indices for (scenario, stage).
These are the storage balance constraint rows (one per block). External entities can add coefficients to these rows to couple their flow variables into this storage's energy balance.
template<typename Object Object>
double gtopt:: StorageLP<Object>:: energy_scale() const noexcept
Energy/volume scale factor used in the LP: LP_var = physical / scale. For batteries this is Battery::energy_scale; for reservoirs it is Reservoir::energy_scale. Use to convert between LP and physical units.
template<typename Object Object>
const BIndexHolder<ColIndex>* gtopt:: StorageLP<Object>:: find_drain_cols(const ScenarioLP& scenario,
const StageLP& stage) const noexcept
Non-throwing lookup: returns a pointer to the drain/spill column map for (scenario, stage), or nullptr when not present.
template<typename Object Object>
std::optional<ColIndex> gtopt:: StorageLP<Object>:: find_efin_col(const ScenarioLP& scenario,
const StageLP& stage) const noexcept
Non-throwing efin_col_at: nullopt when (scenario, stage) was not built (storage inactive in the stage). See active_ref.hpp.
template<typename Object Object>
std::optional<RowIndex> gtopt:: StorageLP<Object>:: find_efin_row(const ScenarioLP& scenario,
const StageLP& stage) const noexcept
Non-throwing lookup of the explicit vol_end >= efin row for (scenario, stage). Returns the row index if present, or std::nullopt when Storage::efin is unset on this element.
template<typename Object Object>
std::optional<ColIndex> gtopt:: StorageLP<Object>:: find_eini_col(const ScenarioLP& scenario,
const StageLP& stage) const noexcept
Non-throwing eini_col_at (same eini → sini fallback): nullopt when (scenario, stage) was not built (storage inactive in the stage).
template<typename Object Object>
const BIndexHolder<RowIndex>* gtopt:: StorageLP<Object>:: find_energy_rows(const ScenarioLP& scenario,
const StageLP& stage) const noexcept
Non-throwing energy_rows_at: nullptr when (scenario, stage) was not built (storage inactive in the stage).
template<typename Object Object>
double gtopt:: StorageLP<Object>:: flow_scale() const noexcept
Flow variable scale factor used in the LP.
For drain (and extraction/finp/fout in the reservoir case): LP_var = physical / flow_scale. Default 1.0 (no scaling; battery default). Reservoirs use energy_scale.
template<typename Object Object>
double gtopt:: StorageLP<Object>:: output_dual_scale_at(const ScenarioLP& scenario,
const StageLP& stage) const
Per-(scenario, stage) factor applied to the energy-balance dual at Parquet-write time. Folds two effects: a constant -1 sign flip (industry-convention positive water value / marginal storage value) and the 24/duration daily-cycle correction when daily_cycle=true. Exposed for regression tests that pin the sign convention.
template<typename Object Object>
double gtopt:: StorageLP<Object>:: physical_efin(const LinearInterface& li,
const ScenarioLP& scenario,
const StageLP& stage,
double default_efin) const
Retrieve the physical efin (final energy/volume) for a given scenario and stage. Fallback chain:
- LP optimal solution
- default_efin
template<typename Object Object>
double gtopt:: StorageLP<Object>:: physical_eini(const LinearInterface& li,
const ScenarioLP& scenario,
const StageLP& stage,
double default_eini) const
Retrieve the physical eini without cross-phase lookup.
Used by callers that only have a LinearInterface (e.g. tests, non-SDDP code). Fallback chain: optimal solution → default_eini.
template<typename Object Object>
template<typename SystemLPT, typename SIdT>
double gtopt:: StorageLP<Object>:: physical_eini(const SystemLPT& sys,
const ScenarioLP& scenario,
const StageLP& stage,
double default_eini,
const SIdT& sid) const
| Parameters | |
|---|---|
| sys | Current SystemLP (provides linear_interface and prev_phase_sys for cross-phase lookups). |
| scenario | Current scenario LP object. |
| stage | Current stage LP object. |
| default_eini | Initial energy/volume when no LP solution exists. |
| sid | ObjectSingleId for this element, used to look up the same storage element in the previous phase. |
Retrieve the physical eini (initial energy/volume) for a given scenario and stage.
For the first stage of the first phase the eini column is the fixed initial condition, so default_eini is returned directly.
For cross-phase boundaries (phase > 0), eini corresponds to the previous phase's efin. When the current LP hasn't been solved, the method looks up the previous phase's efin from sys.prev_phase_sys(). Fallback chain:
- Current LP optimal solution (eini/sini column)
- Current LP warm column solution (from hot-start state file)
- Previous phase's efin (via sys.prev_phase_sys())
- default_eini (system initial volume / vini)
template<typename Object Object>
std::optional<ColIndex> gtopt:: StorageLP<Object>:: soft_emin_col_at(const ScenarioLP& scenario,
const StageLP& stage) const
Return the soft-emin slack column for (scenario, stage), if it exists.
The soft-emin slack is only created when soft_emin > 0 and soft_emin_cost > 0 for the given stage. Returns std::nullopt when the column was not created (i.e., soft_emin is inactive for this stage).
Variable documentation
template<typename Object Object>
static std::string_view gtopt:: StorageLP<Object>:: CycleChainName
Weighted cycle group (Stage::cycle_group) rows: the chain carrying the SoC from one grouped stage to the next (eini_{d+1} = eini_d + w_d·Δ_d), the group closure (Σ_d w_d·Δ_d = 0) and the per-block bound of the LAST repetition (emin ≤ energy_b + (w_d − 1)·Δ_d ≤ emax).
template<typename Object Object>
static std::string_view gtopt:: StorageLP<Object>:: CycleLimitName
LP row label for the daily energy-throughput limit (StorageOptions::max_cycles_day / PLEXOS Max Cycles Day). Duals surface as <class>/cycle_limit_….
template<typename Object Object>
static std::string_view gtopt:: StorageLP<Object>:: CycleScaleName
Stage-end state of a state storage on a periodic stage standing for n repetitions of its typical period: efin = s + n·(x_{N−1} − s) (model_options.periodic_storage).
template<typename Object Object>
static std::string_view gtopt:: StorageLP<Object>:: EfinSlackName
Slack variable name for the soft-efin slack column (created only when Reservoir.efin_cost is set). Mirrors SoftEminName — the slack relaxes the hard vol_end >= efin row into vol_end + slack >= efin priced at efin_cost.
template<typename Object Object>
static std::string_view gtopt:: StorageLP<Object>:: EnergyBalanceName
Constraint name for the per-block energy-balance row. Distinct from EnergyName (the variable) so the LP row and column do not share a base label — without this split, writers like CPXwriteprob emit #<col_index> disambiguators on every column when they detect the row/col name clash, making LP files much harder to diff. Keeping EnergyName for the variable preserves the <class>.energy.* column convention that downstream tooling (ScaledView lookup, cut I/O, Pampl readers) already depends on.
template<typename Object Object>
static std::string_view gtopt:: StorageLP<Object>:: EnvelopeUpName
Point-stage envelope rows (banded integration): charge-only / discharge-only level bounds over each node interval.