gtopt::CostHelper class

Handles cost calculations with time discounting for optimization problems.

Provides methods for:

  • Calculating discounted costs for blocks, stages and scenarios
  • Generating cost scaling factors
  • Applying probability and discount factors

Derived classes

class SystemContext

Public static functions

static auto block_ecost(const ScenarioLP& scenario, const StageLP& stage, const BlockLP& block, const double cost) -> double noexcept
Calculates the energy cost coefficient for a block.
static auto cost_factor(const double probability, const double discount, const double duration = 1.0) -> double noexcept
static auto cost_factor(const ScenarioLP& scenario, const StageLP& stage) -> double noexcept
static auto cost_factor(const ScenarioLP& scenario, const StageLP& stage, const BlockLP& block) -> double noexcept
static auto cost_factor(const StageLP& stage, double probability = 1.0) -> double noexcept
static auto scenario_stage_ecost(const ScenarioLP& scenario, const StageLP& stage, const double cost) -> double noexcept
Calculates the energy cost coefficient for a scenario-stage pair.
static auto stage_ecost(const StageLP& stage, double cost, double probability = 1.0) -> double noexcept
Calculates the energy cost coefficient for a stage.

Constructors, destructors, conversion operators

CostHelper(const PlanningOptionsLP& options, const std::vector<ScenarioLP>& scenarios, const std::vector<StageLP>& stages) explicit

Public functions

auto block_discount_icost_factors() const -> const block_factor_matrix_t&
Returns cached discount-only inverse cost factors for blocks.
auto block_icost_factors() const -> const block_factor_matrix_t&
Returns cached inverse cost factors for blocks (1/cost_factor).
auto block_icost_factors_no_duration() const -> const block_factor_matrix_t&
Inverse cost factors for blocks WITHOUT the duration term.
auto scenario_stage_icost_factors() const -> const scenario_stage_factor_matrix_t&
Returns cached inverse cost factors for scenario-stage pairs.
auto scenario_stage_icost_factors_no_duration() const -> const scenario_stage_factor_matrix_t&
auto stage_icost_factors() const -> const stage_factor_matrix_t&
Returns cached inverse cost factors for stages (1/cost_factor).
auto stage_icost_factors_no_duration() const -> const stage_factor_matrix_t&

Function documentation

static double gtopt::CostHelper::block_ecost(const ScenarioLP& scenario, const StageLP& stage, const BlockLP& block, const double cost) 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

Formula: cost * probability * discount * duration

Note: scale_objective is NOT applied here. It is applied globally in LinearProblem::flatten() so that every objective coefficient is divided by the same scalar. Callers that place the result somewhere other than the objective column (e.g. as a constraint coefficient or RHS) must not rely on scale_objective being present.

static double gtopt::CostHelper::scenario_stage_ecost(const ScenarioLP& scenario, const StageLP& stage, const double cost) 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

Formula: cost * probability * discount * duration

Note: scale_objective is NOT applied here; it is applied globally in LinearProblem::flatten().

static double gtopt::CostHelper::stage_ecost(const StageLP& stage, double cost, double probability = 1.0) 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

Formula: cost * probability * discount * duration

Note: scale_objective is NOT applied here; it is applied globally in LinearProblem::flatten().

const block_factor_matrix_t& gtopt::CostHelper::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)

const block_factor_matrix_t& gtopt::CostHelper::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)

const block_factor_matrix_t& gtopt::CostHelper::block_icost_factors_no_duration() const

Inverse cost factors for blocks WITHOUT the duration term.

Returns Const reference to cached matrix of duration-free inverse factors

Lazily computed, then cached. Formula: 1 / (probability * discount) (same for all blocks in a stage)

Use for duals of stock constraints (storage energy balance → water value / energy shadow price, $ per stored-unit), which must not be divided by block duration the way per-block power-balance duals (LMP) are.

const scenario_stage_factor_matrix_t& gtopt::CostHelper::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)

const scenario_stage_factor_matrix_t& gtopt::CostHelper::scenario_stage_icost_factors_no_duration() const

Per-(scenario, stage) inverse factors WITHOUT duration: 1 / (probability * discount). Use for per-stage STOCK / commodity duals & reduced costs (storage efin / soft_emin / eini state, per-stage fuel offtake $/fuel-unit).

const stage_factor_matrix_t& gtopt::CostHelper::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)

const stage_factor_matrix_t& gtopt::CostHelper::stage_icost_factors_no_duration() const

Per-stage inverse factors WITHOUT duration: 1 / discount. Use for per-stage STOCK / commodity duals (e.g. emission cap $/tonne).