SystemContext class
#include <gtopt/system_context.hpp>
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
- 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).
-
auto block_max_at(const StageLP& stage,
const BlockLP& block,
const Max& lmax,
const double capacity_max = LinearProblem::
DblMax) const -> constexpr auto - 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
- auto demand_fail_cost(const StageLP& stage, const FailCost& fcost) const -> constexpr auto
- auto element(const Id<Element>& id) const -> constexpr auto&&
- auto element_index(const Id<Element>& id) const -> constexpr auto
- auto elements() const -> constexpr auto&&
-
template<typename Projection Projection, typename Value Value = Index, typename Factor Factor = block_auto flat(const GSTBIndexHolder<Value>& hstb, Projection proj, const Factor& factor = Factor()) const -> constexpr auto
factor_ matrix_ t> - Flattens GSTB-indexed data into vectors with optional scaling.
-
template<typename Projection Projection, typename Value Value = Index, typename Factor Factor = block_auto flat(const STBIndexHolder<Value>& hstb, Projection proj, const Factor& factor, const STIndexHolder<double>& st_scale) const -> constexpr auto
factor_ matrix_ t> -
template<typename Projection Projection, typename Value Value = Index, typename Factor Factor = block_auto flat(const STBIndexHolder<Value>& hstb, Projection proj, const Factor& factor = Factor()) const -> constexpr auto
factor_ matrix_ t> -
template<typename Projection Projection, typename Value Value = Index, typename Factor Factor = scenario_auto flat(const STIndexHolder<Value>& hst, Projection proj, const Factor& factor = Factor()) const -> constexpr auto
stage_ factor_ matrix_ t> -
template<typename Projection Projection = std::identity, typename Value Value = Index, typename Factor Factor = stage_auto flat(const TIndexHolder<Value>& ht, Projection proj = {}, const Factor& factor = {}) const -> constexpr auto
factor_ matrix_ t> - auto get_bus(const ObjectSingleId<BusLP>& id) const -> const BusLP & -> auto
- auto get_bus_index(const ObjectSingleId<BusLP>& id) const -> ElementIndex< BusLP > -> auto
- auto get_element(const ElementIndex<Element>& id) const -> const Element & -> auto
- auto get_element(const ObjectSingleId<Element>& id) const -> const Element & -> auto
-
template<typename Key>auto get_state_variable(Key&& key) const -> constexpr auto noexcept
- 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
- auto lp_col_label(ScenarioLP&& scenario, StageLP&& stage, Types && ... args) const -> std::string -> auto
- 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
- auto lp_label(ScenarioLP&& scenario, StageLP&& stage, Types && ... args) const -> std::string -> constexpr auto
- 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
- auto lp_row_label(ScenarioLP&& scenario, StageLP&& stage, Types && ... args) const -> std::string -> auto
- 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
- 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
- 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
- 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
- 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
- auto state_col_label(ScenarioLP&& scenario, StageLP&& stage, Types && ... args) const -> std::string -> auto
- 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
- 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
#include <gtopt/flat_helper.hpp>
constexpr const auto& gtopt:: SystemContext:: active_blocks() const noexcept
#include <gtopt/flat_helper.hpp>
constexpr size_ t gtopt:: SystemContext:: active_scenario_count() const noexcept
#include <gtopt/flat_helper.hpp>
constexpr const auto& gtopt:: SystemContext:: active_scenarios() const noexcept
#include <gtopt/flat_helper.hpp>
constexpr const auto& gtopt:: SystemContext:: active_stage_blocks() const noexcept
#include <gtopt/flat_helper.hpp>
constexpr size_ t gtopt:: SystemContext:: active_stage_count() const noexcept
#include <gtopt/flat_helper.hpp>
constexpr const auto& gtopt:: SystemContext:: active_stages() const noexcept
#include <gtopt/flat_helper.hpp>
const block_ factor_ matrix_ t& gtopt:: SystemContext:: block_discount_icost_factors() const
#include <gtopt/cost_helper.hpp>
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
#include <gtopt/cost_helper.hpp>
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
#include <gtopt/cost_helper.hpp>
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
#include <gtopt/cost_helper.hpp>
constexpr double gtopt:: SystemContext:: cost_factor(const ScenarioLP& scenario,
const StageLP& stage) const noexcept
#include <gtopt/cost_helper.hpp>
constexpr double gtopt:: SystemContext:: cost_factor(const ScenarioLP& scenario,
const StageLP& stage,
const BlockLP& block) const noexcept
#include <gtopt/cost_helper.hpp>
constexpr double gtopt:: SystemContext:: cost_factor(const StageLP& stage,
double probability = 1.0) const noexcept
#include <gtopt/cost_helper.hpp>
#include <gtopt/flat_helper.hpp>
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
#include <gtopt/flat_helper.hpp>
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.
#include <gtopt/flat_helper.hpp>
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
#include <gtopt/flat_helper.hpp>
template<typename Projection Projection, typename Value Value = Index, typename Factor Factor = scenario_ stage_ factor_ matrix_ t>
constexpr auto gtopt:: SystemContext:: flat(const STIndexHolder<Value>& hst,
Projection proj,
const Factor& factor = Factor()) const
#include <gtopt/flat_helper.hpp>
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
#include <gtopt/flat_helper.hpp>
constexpr bool gtopt:: SystemContext:: is_first_stage(const StageLP& stage) const noexcept
#include <gtopt/flat_helper.hpp>
constexpr bool gtopt:: SystemContext:: is_first_stage(const StageUid& stage_uid) const noexcept
#include <gtopt/flat_helper.hpp>
constexpr bool gtopt:: SystemContext:: is_last_stage(const StageUid& stage_uid) const noexcept
#include <gtopt/flat_helper.hpp>
#include <gtopt/label_maker.hpp>
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
#include <gtopt/label_maker.hpp>
auto gtopt:: SystemContext:: lp_col_label(ScenarioLP&& scenario,
StageLP&& stage,
Types && ... args) const -> std::string
#include <gtopt/label_maker.hpp>
auto gtopt:: SystemContext:: lp_col_label(StageLP&& stage,
Types && ... args) const -> std::string
#include <gtopt/label_maker.hpp>
template<typename... Types>
auto gtopt:: SystemContext:: lp_col_label(Types && ... args) const -> std::string
#include <gtopt/label_maker.hpp>
template<typename... Types>
auto gtopt:: SystemContext:: lp_label(ColLabelTag,
Types && ... args) const -> std::string
#include <gtopt/label_maker.hpp>
template<typename... Types>
auto gtopt:: SystemContext:: lp_label(RowLabelTag,
Types && ... args) const -> std::string
#include <gtopt/label_maker.hpp>
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
#include <gtopt/label_maker.hpp>
constexpr auto gtopt:: SystemContext:: lp_label(ScenarioLP&& scenario,
StageLP&& stage,
Types && ... args) const -> std::string
#include <gtopt/label_maker.hpp>
template<typename... Types>
auto gtopt:: SystemContext:: lp_label(Types && ... args) const -> std::string
#include <gtopt/label_maker.hpp>
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
#include <gtopt/label_maker.hpp>
auto gtopt:: SystemContext:: lp_row_label(ScenarioLP&& scenario,
StageLP&& stage,
Types && ... args) const -> std::string
#include <gtopt/label_maker.hpp>
auto gtopt:: SystemContext:: lp_row_label(StageLP&& stage,
Types && ... args) const -> std::string
#include <gtopt/label_maker.hpp>
template<typename... Types>
auto gtopt:: SystemContext:: lp_row_label(Types && ... args) const -> std::string
constexpr LpNamesLevel gtopt:: SystemContext:: names_level() const noexcept
#include <gtopt/label_maker.hpp>
constexpr auto gtopt:: SystemContext:: prev_stage(const StageLP& stage) const noexcept
#include <gtopt/flat_helper.hpp>
constexpr double gtopt:: SystemContext:: scenario_stage_ecost(const ScenarioLP& scenario,
const StageLP& stage,
const double cost) const noexcept
#include <gtopt/cost_helper.hpp>
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
#include <gtopt/cost_helper.hpp>
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
#include <gtopt/flat_helper.hpp>
STUids gtopt:: SystemContext:: st_uids() const
#include <gtopt/flat_helper.hpp>
constexpr double gtopt:: SystemContext:: stage_ecost(const StageLP& stage,
double cost,
double probability = 1.0) const noexcept
#include <gtopt/cost_helper.hpp>
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
#include <gtopt/cost_helper.hpp>
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)
#include <gtopt/label_maker.hpp>
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
#include <gtopt/label_maker.hpp>
auto gtopt:: SystemContext:: state_col_label(ScenarioLP&& scenario,
StageLP&& stage,
Types && ... args) const -> std::string
#include <gtopt/label_maker.hpp>
auto gtopt:: SystemContext:: state_col_label(StageLP&& stage,
Types && ... args) const -> std::string
#include <gtopt/label_maker.hpp>
template<typename... Types>
auto gtopt:: SystemContext:: state_col_label(Types && ... args) const -> std::string
STBUids gtopt:: SystemContext:: stb_uids() const
#include <gtopt/flat_helper.hpp>
TUids gtopt:: SystemContext:: t_uids() const
#include <gtopt/flat_helper.hpp>