FlatHelper class
#include <gtopt/flat_helper.hpp>
Converts multi-dimensional optimization data into flat vectors for LP formulation.
This helper class transforms scenario/stage/block indexed data into:
- Flat vectors for LP matrix construction
- Valid/invalid markers for sparse problems
- Scaled values using provided factors
Key features:
- Handles active element filtering (only processes active scenarios/stages/blocks)
- Applies scaling factors during flattening
- Supports multiple index holder types (GSTB, STB, ST, T)
- Provides constexpr accessors for active elements
- Thread-safe operations (all methods are const)
Derived classes
- class SystemContext
Constructors, destructors, conversion operators
- FlatHelper(const SimulationLP& simulation) 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 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 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
- auto prev_stage(const StageLP& stage) const -> constexpr auto noexcept
- auto simulation() const -> constexpr const SimulationLP& noexcept
- auto st_uids() const -> STUids
- auto stb_uids() const -> STBUids
- auto t_uids() const -> TUids
Function documentation
template<typename Projection Projection, typename Value Value = Index, typename Factor Factor = block_ factor_ matrix_ t>
constexpr auto gtopt:: FlatHelper:: 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:: FlatHelper:: 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.