From 838ea8dc01a3b7aa42faa84b16fb4d18ff141cca Mon Sep 17 00:00:00 2001 From: Tom Bland Date: Tue, 10 Nov 2026 15:47:35 +0000 Subject: [PATCH 1/2] Use market prices for competitive algorithm appraisal --- src/simulation/investment/competitive.rs | 12 ++- .../investment/competitive/coefficients.rs | 89 ++++++------------- .../investment/competitive/metrics.rs | 8 +- .../investment/competitive/optimisation.rs | 10 +-- .../investment/competitive/output.rs | 4 +- 5 files changed, 46 insertions(+), 77 deletions(-) diff --git a/src/simulation/investment/competitive.rs b/src/simulation/investment/competitive.rs index 6844f9c13..97de9cb6e 100644 --- a/src/simulation/investment/competitive.rs +++ b/src/simulation/investment/competitive.rs @@ -236,7 +236,7 @@ fn log_on_equal_appraisal_outputs( } /// Get the best assets for meeting demand for the given commodity -#[allow(clippy::too_many_arguments)] +#[allow(clippy::too_many_arguments, clippy::too_many_lines)] pub fn select_best_assets( model: &Model, mut opt_assets: Vec, @@ -265,8 +265,14 @@ pub fn select_best_assets( prepare_commissioned_assets_for_retention(&mut opt_assets); // Calculate coefficients for all asset options according to the agent's objective - let coefficients = - calculate_coefficients_for_assets(model, objective_type, &opt_assets, prices, year); + let coefficients = calculate_coefficients_for_assets( + model, + objective_type, + &opt_assets, + &prices.market, + &prices.fallback, + year, + ); // Iteratively select the best asset until demand is met let mut round = 0; diff --git a/src/simulation/investment/competitive/coefficients.rs b/src/simulation/investment/competitive/coefficients.rs index e7fde07d6..b9a0ad8bd 100644 --- a/src/simulation/investment/competitive/coefficients.rs +++ b/src/simulation/investment/competitive/coefficients.rs @@ -3,7 +3,6 @@ use crate::agent::ObjectiveType; use crate::asset::AssetRef; use crate::model::Model; use crate::simulation::PriceMap; -use crate::simulation::prices::Prices; use crate::time_slice::{TimeSliceID, TimeSliceInfo}; use crate::units::{MoneyPerActivity, MoneyPerFlow}; use indexmap::IndexMap; @@ -13,35 +12,35 @@ use std::sync::Arc; /// Per-time-slice cost coefficients for an asset. /// /// These coefficients are calculated according to the agent's `ObjectiveType` and are used by the -/// investment appraisal routines. They comprise the activity coefficients (revenue minus operating -/// cost, derived from shadow prices) used in the appraisal optimisation, together with the market -/// costs (derived from market prices). +/// investment appraisal routines. Both the activity coefficients used in the appraisal optimisation +/// and the costs used to calculate the appraisal metric are derived from market prices. #[derive(Clone)] pub struct ObjectiveCoefficients { - /// Cost per unit of activity in each time slice + /// Net revenue per unit of activity, including fallback revenue and epsilon, in each time slice pub activity_coefficients: IndexMap, - /// Market costs associated with asset for each time slice - pub market_costs: IndexMap, + /// Costs per unit of activity for the appraisal metric, excluding fallback revenue and epsilon + pub metric_costs: IndexMap, } /// Calculates cost coefficients for a set of assets for a given objective type. /// /// Returns a map from each asset to its [`ObjectiveCoefficients`], which holds a per-time-slice -/// activity coefficient and market cost. +/// activity coefficient and metric cost. /// /// Activity coefficients are revenue from flows (including the primary output) minus operating -/// cost, calculated using shadow prices. A small positive epsilon is added to each activity -/// coefficient so that assets with near-zero net value still appear in dispatch. +/// cost, calculated using market prices, plus the primary output's fallback revenue. A small positive +/// epsilon is added to each activity coefficient so that assets with near-zero net value still appear +/// in dispatch. /// -/// Market costs are calculated using market prices rather than shadow prices. For NPV they use the -/// same revenue-minus-operating-cost calculation as the activity coefficients. For LCOX the sign is -/// inverted (as the value represents a cost) and the primary output (commodity of interest) is -/// excluded. +/// Metric costs are operating cost minus flow revenue at market prices. NPV includes all flows, +/// whereas LCOX excludes revenue from the primary output (commodity of interest). Neither includes +/// fallback revenue or epsilon. pub fn calculate_coefficients_for_assets( model: &Model, objective_type: ObjectiveType, assets: &[AssetRef], - prices: &Prices, + market_prices: &PriceMap, + fallback_prices: &PriceMap, year: u32, ) -> HashMap> { assets @@ -51,7 +50,8 @@ pub fn calculate_coefficients_for_assets( asset, objective_type, &model.time_slice_info, - prices, + market_prices, + fallback_prices, year, ); (asset.clone(), Arc::new(coefficient)) @@ -64,79 +64,46 @@ fn calculate_coefficients_for_asset( asset: &AssetRef, objective_type: ObjectiveType, time_slice_info: &TimeSliceInfo, - prices: &Prices, + market_prices: &PriceMap, + fallback_prices: &PriceMap, year: u32, ) -> ObjectiveCoefficients { // Small constant added to each activity coefficient to ensure break-even/slightly negative // assets are still dispatched const EPSILON_ACTIVITY_COEFFICIENT: MoneyPerActivity = MoneyPerActivity(f64::EPSILON * 100.0); - // Activity coefficients let mut activity_coefficients = IndexMap::new(); - let mut market_costs = IndexMap::new(); + let mut metric_costs = IndexMap::new(); let primary_output_flow = asset.primary_output().unwrap(); let asset_region = asset.region_id(); for time_slice in time_slice_info.iter_ids() { // Get the operating cost of the asset. This includes the variable operating cost, levies and // flow costs, but excludes costs/revenues from commodity consumption/production. let operating_cost = asset.get_operating_cost(year, time_slice); - let net_operating_cost = - -calculate_asset_revenues(asset, operating_cost, time_slice, &prices.shadow); + let net_revenue = asset.get_revenue_from_flows(market_prices, time_slice) - operating_cost; - let fallback_cost = prices - .fallback + let fallback_revenue = fallback_prices .get(&primary_output_flow.commodity.id, asset_region, time_slice) .unwrap_or(MoneyPerFlow(0.0)) * primary_output_flow.coeff; activity_coefficients.insert( time_slice.clone(), - fallback_cost - net_operating_cost + EPSILON_ACTIVITY_COEFFICIENT, + fallback_revenue + net_revenue + EPSILON_ACTIVITY_COEFFICIENT, ); - let market_cost = match objective_type { + let metric_cost = match objective_type { ObjectiveType::LevelisedCostOfX => { - calculate_asset_costs_for_lcox(asset, operating_cost, time_slice, &prices.market) - } - ObjectiveType::NetPresentValue => { - -calculate_asset_revenues(asset, operating_cost, time_slice, &prices.market) + operating_cost + - asset.get_revenue_from_flows_excluding_primary(market_prices, time_slice) } + ObjectiveType::NetPresentValue => -net_revenue, }; - market_costs.insert(time_slice.clone(), market_cost); + metric_costs.insert(time_slice.clone(), metric_cost); } ObjectiveCoefficients { activity_coefficients, - market_costs, + metric_costs, } } - -/// Calculate the revenue from all flows minus operating cost -fn calculate_asset_revenues( - asset: &AssetRef, - operating_cost: MoneyPerActivity, - time_slice: &TimeSliceID, - prices: &PriceMap, -) -> MoneyPerActivity { - // Revenue from flows including the primary output - let revenue_from_flows = asset.get_revenue_from_flows(prices, time_slice); - - // The activity coefficient is the revenue from flows minus the operating cost (net revenue) - revenue_from_flows - operating_cost -} - -/// Calculate asset costs for LCOX objective. -/// -/// Excludes revenues from the primary output (commodity of interest). -fn calculate_asset_costs_for_lcox( - asset: &AssetRef, - operating_cost: MoneyPerActivity, - time_slice: &TimeSliceID, - prices: &PriceMap, -) -> MoneyPerActivity { - // Revenue from flows excluding the primary output - let revenue_from_flows = asset.get_revenue_from_flows_excluding_primary(prices, time_slice); - - // The activity coefficient is the operating cost minus the revenue from non-primary flows - operating_cost - revenue_from_flows -} diff --git a/src/simulation/investment/competitive/metrics.rs b/src/simulation/investment/competitive/metrics.rs index d4bc96532..a7b5438b6 100644 --- a/src/simulation/investment/competitive/metrics.rs +++ b/src/simulation/investment/competitive/metrics.rs @@ -53,7 +53,7 @@ pub struct AppraisalOutput { pub unmet_demand: DemandMap, /// The comparison metric to compare investment decisions pub metric: Option>, - /// Activity coefficients and market costs used in the appraisal + /// Activity coefficients and metric costs used in the appraisal pub coefficients: Arc, /// Full solution to the optimisation pub solution: IndexMap<(AssetRef, TimeSliceID), Activity>, @@ -233,7 +233,7 @@ fn calculate_lcox( asset.total_capacity(), annual_fixed_cost(asset), &results.asset_activity, - &coefficients[asset].market_costs, + &coefficients[asset].metric_costs, ); Ok(AppraisalOutput::new( @@ -278,7 +278,7 @@ fn calculate_npv( asset.total_capacity(), annual_fixed_cost, &results.asset_activity, - &coefficients[asset].market_costs, + &coefficients[asset].metric_costs, ); Ok(AppraisalOutput::new( @@ -465,7 +465,7 @@ mod tests { fn objective_coeffs() -> Arc { Arc::new(ObjectiveCoefficients { activity_coefficients: IndexMap::new(), - market_costs: IndexMap::new(), + metric_costs: IndexMap::new(), }) } diff --git a/src/simulation/investment/competitive/optimisation.rs b/src/simulation/investment/competitive/optimisation.rs index 1349968b3..c29c1b915 100644 --- a/src/simulation/investment/competitive/optimisation.rs +++ b/src/simulation/investment/competitive/optimisation.rs @@ -219,20 +219,16 @@ pub fn perform_optimisation( // something we should consider. // // A second scenario is where there are two different (non-equivalent) assets with identical - // marginal cost (despite having different VOC and/or flows), and where moving activity between + // marginal cost, and where moving activity between // the assets isn't prevented by constraints (e.g. activity constraints or utilisation peak // constraints). In this case there will be two identical corner solutions, and adding a tranche // to asset A may inadvertently cause it to switch to the equally good solution where asset B // wins, hence resulting in a decrease in activity (the opposite can also happen where adding a // tranche to asset B switches it to a solution where asset B wins, resulting in artificially - // inflated marginal activity). For example, in the simple example for 2021 investments RELCHP - // and RGASPB have identical marginal cost in autumn.night and autumn.evening. This is a bigger - // problem, going back to the issues of degeneracy and non-deterministic results, and something - // we should try to understand better and address at the dispatch stage (which ultimately sets - // the shadow prices that determine marginal costs). In the case of investment appraisal, this + // inflated marginal activity). In the case of investment appraisal, this // can artificially decrease/increase marginal activities resulting in nonsensical LCOX. This is // a problem. It may help to seed each model with the previous solution, to reduce the risk of - // flip-flopping, but the underlying issue also needs to be addressed. + // flip-flopping. Ok(ResultsMap { asset_activity: marginal_activity, diff --git a/src/simulation/investment/competitive/output.rs b/src/simulation/investment/competitive/output.rs index 121837f5c..73de74a20 100644 --- a/src/simulation/investment/competitive/output.rs +++ b/src/simulation/investment/competitive/output.rs @@ -121,7 +121,7 @@ mod tests { #[fixture] fn appraisal_output(asset: Asset, time_slice: TimeSliceID) -> AppraisalOutput { let activity_coefficients = indexmap! { time_slice.clone() => MoneyPerActivity(0.5) }; - let market_costs = indexmap! { time_slice.clone() => MoneyPerActivity(0.4) }; + let metric_costs = indexmap! { time_slice.clone() => MoneyPerActivity(0.4) }; let activity = indexmap! { time_slice.clone() => Activity(10.0) }; let unmet_demand = indexmap! { TimeSliceSelection::Single(time_slice.clone()) => Flow(5.0) }; @@ -129,7 +129,7 @@ mod tests { asset: AssetRef::from(asset), coefficients: Arc::new(ObjectiveCoefficients { activity_coefficients, - market_costs, + metric_costs, }), activity, unmet_demand, From 3d7921357b40022d2dccc2577e1a883ab6354873 Mon Sep 17 00:00:00 2001 From: Tom Bland Date: Fri, 13 Nov 2026 14:20:43 +0000 Subject: [PATCH 2/2] Update docs --- docs/model/agents.md | 27 +++++++++++++-------------- docs/model/dispatch_optimisation.md | 9 ++------- schemas/input/model.yaml | 5 ++--- 3 files changed, 17 insertions(+), 24 deletions(-) diff --git a/docs/model/agents.md b/docs/model/agents.md index 3176504aa..a6f2ad766 100644 --- a/docs/model/agents.md +++ b/docs/model/agents.md @@ -45,19 +45,17 @@ feasible options remain. ### Commodity prices used in appraisal -Investment appraisal uses three distinct price sets, all sourced from the previous MSY's dispatch -(or from the previous [ironing-out loop][framework-overview] iteration if enabled): +Investment appraisal uses two price sets calculated from the previous MSY's dispatch (or from the +previous [ironing-out loop][framework-overview] iteration if enabled): -- **Shadow prices** \\( \lambda\_{c,r,t} \\): used for activity coefficients in the mini dispatch - optimisation step of each appraisal (see [Mini Dispatch Optimisation](#mini-dispatch-optimisation)). -- **Market prices** \\( \pi\_{c,r,t} \\): used to calculate the investment metric (Cost Index or - SNAS) after dispatch. +- **Market prices** \\( \pi\_{c,r,t} \\): used for activity coefficients in the mini dispatch and + for the investment metric (Cost Index or SNAS). - **Fallback prices** \\( \phi\_{c,r,t} \\): used to incentivise dispatch in the mini dispatch - optimisation when shadow prices alone are insufficient (see + optimisation when market prices alone are insufficient (see [Mini Dispatch Optimisation](#mini-dispatch-optimisation)). Calculated using the strategy defined by `fallback_pricing_strategy` in [`model.toml`][model-toml]. -See [Commodity Prices][prices] for how these price sets are calculated. +See [Commodity Prices][prices] for how prices are calculated. ### Capacities of options @@ -126,7 +124,7 @@ elsewhere. This is captured by the activity coefficient \\( \alpha_t \\), which combines two components: \\[ - \mathrm{NetOperatingCost}_t = \mathrm{OperatingCost}(t) - \mathrm{RevenueFromFlows}(\lambda, t) + \mathrm{NetOperatingCost}_t = \mathrm{OperatingCost}(t) - \mathrm{RevenueFromFlows}(\pi, t) \\] \\[ @@ -138,12 +136,12 @@ This is captured by the activity coefficient \\( \alpha_t \\), which combines tw \\] where \\( \mathrm{RevenueFromFlows} \\) is the sum of all commodity flow revenues and costs (positive -for outputs, negative for inputs) valued at shadow prices, \\( \mathrm{OperatingCost} \\) is the +for outputs, negative for inputs) valued at market prices, \\( \mathrm{OperatingCost} \\) is the variable operating cost plus levies and flow costs, \\( f_{c,\mathrm{primary}} \\) is the primary output flow coefficient, and \\( \varepsilon \\) is a small positive constant added to ensure that break-even assets are still dispatched. -**NetOperatingCost** is the net cost of running the asset for one unit of activity at shadow prices +**NetOperatingCost** is the net cost of running the asset for one unit of activity at market prices — negative when the asset is profitable (revenues exceed costs). **FallbackCost** is the cost of procuring one unit of activity's worth of primary output from an @@ -188,7 +186,8 @@ dispatch optimisation, and are applied to each asset separately. After the dispatch LP is solved, an investment metric is calculated for the option using **market prices**. The metric is based on the option's marginal activity, while the fixed costs and market -costs are those of the option itself. +costs are those of the option itself. Fallback revenue and epsilon are not included in the metric +costs, though they can affect the activity profile used to calculate the metric. #### Marginal activity @@ -309,7 +308,7 @@ All per-flow costs (\\( \mathrm{cost}\_{\mathrm{input}} \\), | AFC | £1,000/MW | | Capacity | 100 MW | -##### Prices (both shadow and market prices are equal in this example) +##### Market prices | Commodity | \\( t_0 \\) (Peak) | \\( t_1 \\) (Off-peak) | | ----------- | -------------------- | ------------------------ | @@ -319,7 +318,7 @@ All per-flow costs (\\( \mathrm{cost}\_{\mathrm{input}} \\), #### Mini Dispatch Optimisation (identical for LCOX and NPV) -Activity coefficients use shadow prices: +Activity coefficients use market prices: **\\( t_0 \\):** \\[ diff --git a/docs/model/dispatch_optimisation.md b/docs/model/dispatch_optimisation.md index 2a70e6f7c..e50ea7ce5 100644 --- a/docs/model/dispatch_optimisation.md +++ b/docs/model/dispatch_optimisation.md @@ -151,8 +151,7 @@ These constraints are defined in the optional `commodity_constraints.csv` file. The dual values (shadow prices) of the commodity balance constraints represent the marginal cost of satisfying an additional unit of demand for that commodity in region \\( r \\) during selection - \\( s \\). These shadow prices are critical outputs of the dispatch model and are used to seed and - guide the investment appraisal of [competitive agents][competitive-agents] in subsequent steps. + \\( s \\). These shadow prices are used in in partial system dispatch. --- @@ -245,9 +244,7 @@ candidate assets are present: \end{cases} \\] -where \\( \epsilon \\) is the `commodity_balance_epsilon` parameter. The shadow prices from this -candidate dispatch run are then used to seed and guide the investment appraisal of -[competitive agents][competitive-agents] in subsequent steps. +where \\( \epsilon \\) is the `commodity_balance_epsilon` parameter. --- @@ -293,5 +290,3 @@ caused by one or more constraints defined in `commodity_constraints.csv`. If the rerun remains infeasible, commodity constraints are not identified as the cause. Since commodity constraints are an experimental feature, this diagnosis should be treated as indicative rather than definitive. - -[competitive-agents]: ./agents.md#competitive-agents diff --git a/schemas/input/model.yaml b/schemas/input/model.yaml index fc8fb347c..e170a8497 100644 --- a/schemas/input/model.yaml +++ b/schemas/input/model.yaml @@ -57,10 +57,9 @@ properties: notes: | The fallback price represents the cost of procuring the commodity of interest from an alternative source rather than producing it with the asset being appraised. It provides an - additional incentive for an asset to dispatch even when shadow prices alone are insufficient. + additional incentive for an asset to dispatch even when market prices alone are insufficient. - Setting this to `unpriced` uses a fallback price of zero, reverting to the pure - shadow-price formulation. + Setting this to `unpriced` uses a fallback price of zero. value_of_lost_load: type: number description: The cost applied to unmet demand