11//! Calculation of cost coefficients for investment tools.
22use super :: costs:: { activity_cost, activity_surplus, annual_fixed_cost} ;
3+ use crate :: agent:: ObjectiveType ;
34use crate :: asset:: AssetRef ;
5+ use crate :: model:: Model ;
46use crate :: simulation:: prices:: ReducedCosts ;
57use crate :: time_slice:: { TimeSliceID , TimeSliceInfo } ;
68use crate :: units:: { MoneyPerActivity , MoneyPerCapacity , MoneyPerFlow } ;
79use indexmap:: IndexMap ;
10+ use std:: collections:: HashMap ;
811
12+ /// Map storing cost coefficients for an asset.
13+ ///
14+ /// These are calculated according to the objective type of the agent owning the asset.
915/// Map storing coefficients for each variable
10- pub struct CoefficientsMap {
16+ pub struct ObjectiveCoefficients {
1117 /// Cost per unit of capacity
1218 pub capacity_coefficient : MoneyPerCapacity ,
1319 /// Cost per unit of activity in each time slice
1420 pub activity_coefficients : IndexMap < TimeSliceID , MoneyPerActivity > ,
15- // Unmet demand coefficient
21+ /// Unmet demand coefficient
1622 pub unmet_demand_coefficient : MoneyPerFlow ,
1723}
1824
25+ /// Calculates cost coefficients for a set of assets for a given objective type.
26+ pub fn calculate_coefficients_for_assets (
27+ model : & Model ,
28+ objective_type : & ObjectiveType ,
29+ assets : & [ AssetRef ] ,
30+ reduced_costs : & ReducedCosts ,
31+ ) -> HashMap < AssetRef , ObjectiveCoefficients > {
32+ assets
33+ . iter ( )
34+ . map ( |asset| {
35+ let coefficient = match objective_type {
36+ ObjectiveType :: LevelisedCostOfX => calculate_coefficients_for_lcox (
37+ asset,
38+ & model. time_slice_info ,
39+ reduced_costs,
40+ model. parameters . value_of_lost_load ,
41+ ) ,
42+ ObjectiveType :: NetPresentValue => {
43+ calculate_coefficients_for_npv ( asset, & model. time_slice_info , reduced_costs)
44+ }
45+ } ;
46+ ( asset. clone ( ) , coefficient)
47+ } )
48+ . collect ( )
49+ }
50+
1951/// Calculates the cost coefficients for LCOX.
2052pub fn calculate_coefficients_for_lcox (
2153 asset : & AssetRef ,
2254 time_slice_info : & TimeSliceInfo ,
2355 reduced_costs : & ReducedCosts ,
2456 value_of_lost_load : MoneyPerFlow ,
25- ) -> CoefficientsMap {
57+ ) -> ObjectiveCoefficients {
2658 // Capacity coefficient
2759 let capacity_coefficient = annual_fixed_cost ( asset) ;
2860
@@ -36,7 +68,7 @@ pub fn calculate_coefficients_for_lcox(
3668 // Unmet demand coefficient
3769 let unmet_demand_coefficient = value_of_lost_load;
3870
39- CoefficientsMap {
71+ ObjectiveCoefficients {
4072 capacity_coefficient,
4173 activity_coefficients,
4274 unmet_demand_coefficient,
@@ -48,7 +80,7 @@ pub fn calculate_coefficients_for_npv(
4880 asset : & AssetRef ,
4981 time_slice_info : & TimeSliceInfo ,
5082 reduced_costs : & ReducedCosts ,
51- ) -> CoefficientsMap {
83+ ) -> ObjectiveCoefficients {
5284 // Capacity coefficient
5385 let capacity_coefficient = -annual_fixed_cost ( asset) ;
5486
@@ -62,7 +94,7 @@ pub fn calculate_coefficients_for_npv(
6294 // Unmet demand coefficient (we don't apply a cost to unmet demand, so we set this to zero)
6395 let unmet_demand_coefficient = MoneyPerFlow ( 0.0 ) ;
6496
65- CoefficientsMap {
97+ ObjectiveCoefficients {
6698 capacity_coefficient,
6799 activity_coefficients,
68100 unmet_demand_coefficient,
0 commit comments