gtopt::SystemContext class

Base classes

class LabelMaker
class FlatHelper
Converts multi-dimensional optimization data into flat vectors for LP formulation.
class CostHelper
Handles cost calculations with time discounting for optimization problems.

Constructors, destructors, conversion operators

SystemContext(SimulationLP& simulation, SystemLP& system) explicit

Public functions

auto active_block_count() const -> constexpr size_t noexcept
auto active_blocks() const -> constexpr const auto& noexcept
auto active_scenario_count() const -> constexpr size_t noexcept
auto active_scenarios() const -> constexpr const auto& noexcept
auto active_stage_blocks() const -> constexpr const auto& noexcept
auto active_stage_count() const -> constexpr size_t noexcept
auto active_stages() const -> constexpr const auto& noexcept
template<typename Element Element>
auto add_element(Element&& element) -> constexpr auto
template<typename Key>
auto add_state_variable(Key&& key, ColIndex col) -> constexpr auto
auto block_discount_icost_factors() const -> const block_factor_matrix_t&
Returns cached discount-only inverse cost factors for blocks.
auto block_ecost(const ScenarioLP& scenario, const StageLP& stage, const BlockLP& block, const double cost) const -> constexpr double noexcept
Calculates the energy cost coefficient for a block.
auto block_icost_factors() const -> const block_factor_matrix_t&
Returns cached inverse cost factors for blocks (1/cost_factor).
template<typename Max Max>
auto block_max_at(const StageLP& stage, const BlockLP& block, const Max& lmax, const double capacity_max = LinearProblem::DblMax) const -> constexpr auto
template<typename Min Min, typename Max Max>
auto block_maxmin_at(const StageLP& stage, const BlockLP& block, const Max& lmax, const Min& lmin, const double capacity_max, const double capacity_min = 0.0) const -> std::pair< double, double > -> constexpr auto
auto cost_factor(const double probability, const double discount, const double duration = 1.0) const -> constexpr double noexcept
auto cost_factor(const ScenarioLP& scenario, const StageLP& stage) const -> constexpr double noexcept
auto cost_factor(const ScenarioLP& scenario, const StageLP& stage, const BlockLP& block) const -> constexpr double noexcept
auto cost_factor(const StageLP& stage, double probability = 1.0) const -> constexpr double noexcept
template<typename FailCost FailCost>
auto demand_fail_cost(const StageLP& stage, const FailCost& fcost) const -> constexpr auto
template<typename Element Element, template<typename> class Id>
auto element(const Id<Element>& id) const -> constexpr auto&&
template<typename Element Element, template<typename> class Id>
auto element_index(const Id<Element>& id) const -> constexpr auto
template<typename Element Element>
auto elements() const -> constexpr auto&&
auto flat(const GSTBIndexHolder<Value>& hstb, Projection proj, const Factor& factor = Factor()) const -> constexpr auto
Flattens GSTB-indexed data into vectors with optional scaling.
auto flat(const STBIndexHolder<Value>& hstb, Projection proj, const Factor& factor, const STIndexHolder<double>& st_scale) const -> constexpr auto
auto flat(const STBIndexHolder<Value>& hstb, Projection proj, const Factor& factor = Factor()) const -> constexpr auto
auto flat(const STIndexHolder<Value>& hst, Projection proj, const Factor& factor = Factor()) const -> constexpr auto
template<typename Projection Projection = std::identity, typename Value Value = Index, typename Factor Factor = stage_factor_matrix_t>
auto flat(const TIndexHolder<Value>& ht, Projection proj = {}, const Factor& factor = {}) const -> constexpr auto
auto get_bus(const ObjectSingleId<BusLP>& id) const -> const BusLP & -> auto
auto get_bus_index(const ObjectSingleId<BusLP>& id) const -> ElementIndex< BusLP > -> auto
template<typename Element Element>
auto get_element(const ElementIndex<Element>& id) const -> const Element & -> auto
template<typename Element Element>
auto get_element(const ObjectSingleId<Element>& id) const -> const Element & -> auto
template<typename Key>
auto get_state_variable(Key&& key) const -> constexpr auto noexcept
template<typename FailCost FailCost>
auto hydro_fail_cost(const StageLP& stage, const FailCost& fcost) const -> constexpr auto
auto is_first_scenario(const ScenarioUid& scenario_uid) const -> constexpr bool noexcept
auto is_first_stage(const StageLP& stage) const -> constexpr bool noexcept
auto is_first_stage(const StageUid& stage_uid) const -> constexpr bool noexcept
auto is_last_stage(const StageUid& stage_uid) const -> constexpr bool noexcept
template<typename ScenarioLP ScenarioLP, typename StageLP StageLP, typename BlockLP BlockLP, typename... Types>
auto lp_col_label(ScenarioLP&& scenario, StageLP&& stage, BlockLP&& block, Types && ... args) const -> std::string -> auto
template<typename ScenarioLP ScenarioLP, typename StageLP StageLP, typename... Types>
auto lp_col_label(ScenarioLP&& scenario, StageLP&& stage, Types && ... args) const -> std::string -> auto
template<typename StageLP StageLP, typename... Types>
auto lp_col_label(StageLP&& stage, Types && ... args) const -> std::string -> auto
template<typename... Types>
auto lp_col_label(Types && ... args) const -> std::string -> auto
template<typename... Types>
auto lp_label(ColLabelTag, Types && ... args) const -> std::string -> auto
template<typename... Types>
auto lp_label(RowLabelTag, Types && ... args) const -> std::string -> auto
template<typename ScenarioLP ScenarioLP, typename StageLP StageLP, typename BlockLP BlockLP, typename... Types>
auto lp_label(ScenarioLP&& scenario, StageLP&& stage, BlockLP&& block, Types && ... args) const -> std::string -> constexpr auto
template<typename ScenarioLP ScenarioLP, typename StageLP StageLP, typename... Types>
auto lp_label(ScenarioLP&& scenario, StageLP&& stage, Types && ... args) const -> std::string -> constexpr auto
template<typename StageLP StageLP, typename... Types>
auto lp_label(StageLP&& stage, Types && ... args) const -> std::string -> constexpr auto
template<typename... Types>
auto lp_label(Types && ... args) const -> std::string -> auto
template<typename ScenarioLP ScenarioLP, typename StageLP StageLP, typename BlockLP BlockLP, typename... Types>
auto lp_row_label(ScenarioLP&& scenario, StageLP&& stage, BlockLP&& block, Types && ... args) const -> std::string -> auto
template<typename ScenarioLP ScenarioLP, typename StageLP StageLP, typename... Types>
auto lp_row_label(ScenarioLP&& scenario, StageLP&& stage, Types && ... args) const -> std::string -> auto
template<typename StageLP StageLP, typename... Types>
auto lp_row_label(StageLP&& stage, Types && ... args) const -> std::string -> auto
template<typename... Types>
auto lp_row_label(Types && ... args) const -> std::string -> auto
auto names_level() const -> constexpr LpNamesLevel noexcept
auto options() const -> constexpr auto&& noexcept
auto prev_stage(const StageLP& stage) const -> constexpr auto noexcept
template<typename FailCost FailCost>
auto reserve_fail_cost(const StageLP& stage, const FailCost& fcost) const -> constexpr auto
auto scenario_stage_ecost(const ScenarioLP& scenario, const StageLP& stage, const double cost) const -> constexpr double noexcept
Calculates the energy cost coefficient for a scenario-stage pair.
auto scenario_stage_icost_factors() const -> const scenario_stage_factor_matrix_t&
Returns cached inverse cost factors for scenario-stage pairs.
auto simulation() const -> constexpr const SimulationLP& noexcept
template<typename Self Self>
auto simulation(this Self&& self) -> constexpr auto&& noexcept
auto st_uids() const -> STUids
auto stage_ecost(const StageLP& stage, double cost, double probability = 1.0) const -> constexpr double noexcept
Calculates the energy cost coefficient for a stage.
auto stage_icost_factors() const -> const stage_factor_matrix_t&
Returns cached inverse cost factors for stages (1/cost_factor).
template<typename LossFactor LossFactor>
auto stage_lossfactor(const StageLP& stage, const LossFactor& lfact) const -> constexpr auto
template<typename Min Min, typename Max Max>
auto stage_maxmin_at(const StageLP& stage, const Min& lmax, const Max& lmin, const double capacity_max, const double capacity_min = 0.0) const -> std::pair< double, double > -> constexpr auto
template<typename Reactance Reactance>
auto stage_reactance(const StageLP& stage, const Reactance& reactance) const -> constexpr auto
template<typename ScenarioLP ScenarioLP, typename StageLP StageLP, typename BlockLP BlockLP, typename... Types>
auto state_col_label(ScenarioLP&& scenario, StageLP&& stage, BlockLP&& block, Types && ... args) const -> std::string -> auto
template<typename ScenarioLP ScenarioLP, typename StageLP StageLP, typename... Types>
auto state_col_label(ScenarioLP&& scenario, StageLP&& stage, Types && ... args) const -> std::string -> auto
template<typename StageLP StageLP, typename... Types>
auto state_col_label(StageLP&& stage, Types && ... args) const -> std::string -> auto
template<typename... Types>
auto state_col_label(Types && ... args) const -> std::string -> auto
auto stb_uids() const -> STBUids
template<typename Self Self>
auto system(this Self&& self) -> constexpr auto&& noexcept
auto t_uids() const -> TUids

Function documentation

constexpr size_t gtopt::SystemContext::active_block_count() const noexcept

constexpr const auto& gtopt::SystemContext::active_blocks() const noexcept

constexpr size_t gtopt::SystemContext::active_scenario_count() const noexcept

constexpr const auto& gtopt::SystemContext::active_scenarios() const noexcept

constexpr const auto& gtopt::SystemContext::active_stage_blocks() const noexcept

constexpr size_t gtopt::SystemContext::active_stage_count() const noexcept

constexpr const auto& gtopt::SystemContext::active_stages() const noexcept

const block_factor_matrix_t& gtopt::SystemContext::block_discount_icost_factors() const

Returns cached discount-only inverse cost factors for blocks.

Returns Const reference to cached matrix of discount-only inverse cost factors

Lazily computed on first call, then cached. Formula: scale_objective / discount[t] (same for all s, b in stage t)

constexpr double gtopt::SystemContext::block_ecost(const ScenarioLP& scenario, const StageLP& stage, const BlockLP& block, const double cost) const noexcept

Calculates the energy cost coefficient for a block.

Returns Total energy cost coefficient for LP formulation

Computes the total energy cost for a power variable over a block duration, applying:

  • Scenario probability weighting
  • Stage discount factor
  • Block duration
  • Objective scaling

Formula: cost * probability * discount * duration / scale_objective

const block_factor_matrix_t& gtopt::SystemContext::block_icost_factors() const

Returns cached inverse cost factors for blocks (1/cost_factor).

Returns Const reference to cached matrix of inverse cost factors

Lazily computed on first call, then cached for subsequent accesses. Formula: 1 / (probability * discount * duration / scale_objective)

constexpr double gtopt::SystemContext::cost_factor(const double probability, const double discount, const double duration = 1.0) const noexcept

constexpr double gtopt::SystemContext::cost_factor(const ScenarioLP& scenario, const StageLP& stage) const noexcept

constexpr double gtopt::SystemContext::cost_factor(const ScenarioLP& scenario, const StageLP& stage, const BlockLP& block) const noexcept

constexpr double gtopt::SystemContext::cost_factor(const StageLP& stage, double probability = 1.0) const noexcept

template<typename Projection Projection, typename Value Value = Index, typename Factor Factor = block_factor_matrix_t>
constexpr auto gtopt::SystemContext::flat(const GSTBIndexHolder<Value>& hstb, Projection proj, const Factor& factor = Factor()) const

Flattens GSTB-indexed data into vectors with optional scaling.

Parameters
hstb The GSTB-indexed data holder
proj Projection function to apply to each value
factor Optional scaling factors (applied after projection)
Returns Pair of (values, valid) vectors

Processes a 3D (Scenario/Stage/Block) indexed container into:

  • Values vector with projected/scaled values
  • Valid vector marking which indices had data

template<typename Projection Projection, typename Value Value = Index, typename Factor Factor = block_factor_matrix_t>
constexpr auto gtopt::SystemContext::flat(const STBIndexHolder<Value>& hstb, Projection proj, const Factor& factor, const STIndexHolder<double>& st_scale) const

flat() overload that applies an additional per-(scenario,stage) scale factor on top of the block-level factor. Used by StorageLP::add_to_output to back-scale volume-balance duals when the daily-cycle option was active for a stage (scale = 24/stage_dur).

The st_scale lookup is performed once per (scenario,stage) pair, outside the block loop, so there is no per-block overhead. When a (suid,tuid) key is absent from st_scale the scale defaults to 1.0 (i.e. no scaling is applied for that stage), making this a safe drop-in for the plain flat() call when st_scale is empty.

template<typename Projection Projection, typename Value Value = Index, typename Factor Factor = block_factor_matrix_t>
constexpr auto gtopt::SystemContext::flat(const STBIndexHolder<Value>& hstb, Projection proj, const Factor& factor = Factor()) const

constexpr auto gtopt::SystemContext::flat(const STIndexHolder<Value>& hst, Projection proj, const Factor& factor = Factor()) const

template<typename Projection Projection = std::identity, typename Value Value = Index, typename Factor Factor = stage_factor_matrix_t>
constexpr auto gtopt::SystemContext::flat(const TIndexHolder<Value>& ht, Projection proj = {}, const Factor& factor = {}) const

constexpr bool gtopt::SystemContext::is_first_scenario(const ScenarioUid& scenario_uid) const noexcept

constexpr bool gtopt::SystemContext::is_first_stage(const StageLP& stage) const noexcept

constexpr bool gtopt::SystemContext::is_first_stage(const StageUid& stage_uid) const noexcept

constexpr bool gtopt::SystemContext::is_last_stage(const StageUid& stage_uid) const noexcept

template<typename ScenarioLP ScenarioLP, typename StageLP StageLP, typename BlockLP BlockLP, typename... Types>
auto gtopt::SystemContext::lp_col_label(ScenarioLP&& scenario, StageLP&& stage, BlockLP&& block, Types && ... args) const -> std::string

template<typename ScenarioLP ScenarioLP, typename StageLP StageLP, typename... Types>
auto gtopt::SystemContext::lp_col_label(ScenarioLP&& scenario, StageLP&& stage, Types && ... args) const -> std::string

template<typename StageLP StageLP, typename... Types>
auto gtopt::SystemContext::lp_col_label(StageLP&& stage, Types && ... args) const -> std::string

template<typename... Types>
auto gtopt::SystemContext::lp_col_label(Types && ... args) const -> std::string

template<typename... Types>
auto gtopt::SystemContext::lp_label(ColLabelTag, Types && ... args) const -> std::string

template<typename... Types>
auto gtopt::SystemContext::lp_label(RowLabelTag, Types && ... args) const -> std::string

template<typename ScenarioLP ScenarioLP, typename StageLP StageLP, typename BlockLP BlockLP, typename... Types>
constexpr auto gtopt::SystemContext::lp_label(ScenarioLP&& scenario, StageLP&& stage, BlockLP&& block, Types && ... args) const -> std::string

template<typename ScenarioLP ScenarioLP, typename StageLP StageLP, typename... Types>
constexpr auto gtopt::SystemContext::lp_label(ScenarioLP&& scenario, StageLP&& stage, Types && ... args) const -> std::string

template<typename StageLP StageLP, typename... Types>
constexpr auto gtopt::SystemContext::lp_label(StageLP&& stage, Types && ... args) const -> std::string

template<typename... Types>
auto gtopt::SystemContext::lp_label(Types && ... args) const -> std::string

template<typename ScenarioLP ScenarioLP, typename StageLP StageLP, typename BlockLP BlockLP, typename... Types>
auto gtopt::SystemContext::lp_row_label(ScenarioLP&& scenario, StageLP&& stage, BlockLP&& block, Types && ... args) const -> std::string

template<typename ScenarioLP ScenarioLP, typename StageLP StageLP, typename... Types>
auto gtopt::SystemContext::lp_row_label(ScenarioLP&& scenario, StageLP&& stage, Types && ... args) const -> std::string

template<typename StageLP StageLP, typename... Types>
auto gtopt::SystemContext::lp_row_label(StageLP&& stage, Types && ... args) const -> std::string

template<typename... Types>
auto gtopt::SystemContext::lp_row_label(Types && ... args) const -> std::string

constexpr LpNamesLevel gtopt::SystemContext::names_level() const noexcept

constexpr auto gtopt::SystemContext::prev_stage(const StageLP& stage) const noexcept

constexpr double gtopt::SystemContext::scenario_stage_ecost(const ScenarioLP& scenario, const StageLP& stage, const double cost) const noexcept

Calculates the energy cost coefficient for a scenario-stage pair.

Returns Total energy cost coefficient for LP formulation

Computes the total energy cost for a power variable over a stage duration, applying:

  • Scenario probability weighting
  • Stage discount factor
  • Stage duration
  • Objective scaling

Formula: cost * probability * discount * duration / scale_objective

const scenario_stage_factor_matrix_t& gtopt::SystemContext::scenario_stage_icost_factors() const

Returns cached inverse cost factors for scenario-stage pairs.

Returns Const reference to cached matrix of inverse cost factors

Lazily computed on first call, then cached. Formula: 1 / (probability * discount * duration / scale_objective)

constexpr const SimulationLP& gtopt::SystemContext::simulation() const noexcept

STUids gtopt::SystemContext::st_uids() const

constexpr double gtopt::SystemContext::stage_ecost(const StageLP& stage, double cost, double probability = 1.0) const noexcept

Calculates the energy cost coefficient for a stage.

Returns Total energy cost coefficient for LP formulation

Computes the total energy cost for a power variable over a stage duration, applying:

  • Probability weighting (default 1.0)
  • Stage discount factor
  • Stage duration
  • Objective scaling

Formula: cost * probability * discount * duration / scale_objective

const stage_factor_matrix_t& gtopt::SystemContext::stage_icost_factors() const

Returns cached inverse cost factors for stages (1/cost_factor).

Returns Const reference to cached vector of inverse cost factors

Lazily computed on first call (probability = 1.0), then cached. Formula: 1 / (discount * duration / scale_objective)

template<typename ScenarioLP ScenarioLP, typename StageLP StageLP, typename BlockLP BlockLP, typename... Types>
auto gtopt::SystemContext::state_col_label(ScenarioLP&& scenario, StageLP&& stage, BlockLP&& block, Types && ... args) const -> std::string

template<typename ScenarioLP ScenarioLP, typename StageLP StageLP, typename... Types>
auto gtopt::SystemContext::state_col_label(ScenarioLP&& scenario, StageLP&& stage, Types && ... args) const -> std::string

template<typename StageLP StageLP, typename... Types>
auto gtopt::SystemContext::state_col_label(StageLP&& stage, Types && ... args) const -> std::string

template<typename... Types>
auto gtopt::SystemContext::state_col_label(Types && ... args) const -> std::string

STBUids gtopt::SystemContext::stb_uids() const

TUids gtopt::SystemContext::t_uids() const