@@ -508,7 +508,7 @@ fn add_marginal_cost_prices<'a, I, J>(
508508 year,
509509 commodities,
510510 & PricingStrategy :: MarginalCost ,
511- None :: < & HashMap < AssetRef , Activity > > ,
511+ /*annual_activities=*/ None ,
512512 )
513513 . collect ( ) ;
514514 let priced_groups: HashSet < _ > = group_prices. keys ( ) . cloned ( ) . collect ( ) ;
@@ -567,10 +567,17 @@ where
567567 I : Iterator < Item = ( & ' a AssetRef , & ' a TimeSliceID , Activity ) > ,
568568{
569569 // Validate supported strategies, and require annual activities for FullCost pricing.
570- assert ! ( matches!(
571- ( pricing_strategy, annual_activities) ,
572- ( PricingStrategy :: MarginalCost , _) | ( PricingStrategy :: FullCost , Some ( _) )
573- ) ) ;
570+ match pricing_strategy {
571+ PricingStrategy :: MarginalCost => assert ! (
572+ annual_activities. is_none( ) ,
573+ "Cannot provide annual_activities with marginal pricing strategy"
574+ ) ,
575+ PricingStrategy :: FullCost => assert ! (
576+ annual_activities. is_some( ) ,
577+ "annual_activities must be provided for full pricing strategy"
578+ ) ,
579+ _ => panic ! ( "Invalid pricing strategy" ) ,
580+ }
574581
575582 // Accumulator map to collect costs from existing assets. For each (commodity, region,
576583 // ts selection), this maps each asset to a weighted average of the costs for that
@@ -583,16 +590,15 @@ where
583590 > = IndexMap :: new ( ) ;
584591
585592 // Cache of annual fixed costs per flow for each asset (only used for Full cost pricing)
586- let mut annual_fixed_costs: HashMap < _ , _ > = HashMap :: new ( ) ;
593+ let mut annual_fixed_costs = HashMap :: new ( ) ;
587594
588595 // Iterate over existing assets and their activities
589596 for ( asset, time_slice, activity) in activity_for_existing {
590597 let region_id = asset. region_id ( ) ;
591598
592599 // When using full cost pricing, skip assets with zero activity across the year, since
593600 // we cannot calculate a fixed cost per flow.
594- let annual_activity = matches ! ( pricing_strategy, PricingStrategy :: FullCost )
595- . then ( || annual_activities. unwrap ( ) [ asset] ) ;
601+ let annual_activity = annual_activities. map ( |activities| activities[ asset] ) ;
596602 if annual_activity. is_some_and ( |annual_activity| annual_activity < Activity :: EPSILON ) {
597603 continue ;
598604 }
@@ -654,7 +660,7 @@ where
654660/// involves taking a weighted average across time slices for each asset according to potential
655661/// activity (i.e. the upper activity limit), omitting prices in the extreme case of zero potential
656662/// activity (Note: this should NOT happen as validation should ensure there is at least one
657- /// candidate that can provide a price in each timeslice for which a price could be required).
663+ /// candidate that can provide a price in each time slice for which a price could be required).
658664/// Costs for candidates are calculated assuming full utilisation.
659665///
660666/// # Arguments
@@ -692,10 +698,10 @@ where
692698 ) ) ;
693699
694700 // Cache of annual fixed costs per flow for each asset (only used for Full cost pricing)
695- let mut annual_fixed_costs: HashMap < _ , _ > = HashMap :: new ( ) ;
701+ let mut annual_fixed_costs = HashMap :: new ( ) ;
696702
697703 // Cache of annual activity limits for each asset (only used for Full cost pricing)
698- let mut annual_activity_limits: HashMap < _ , _ > = HashMap :: new ( ) ;
704+ let mut annual_activity_limits = HashMap :: new ( ) ;
699705
700706 // Accumulator map to collect costs from candidate assets. Similar to existing_accum,
701707 // but costs are weighted according to activity limits (i.e. assuming full utilisation).
@@ -813,7 +819,7 @@ fn add_marginal_cost_average_prices<'a, I, J>(
813819 year,
814820 commodities,
815821 & PricingStrategy :: MarginalCost ,
816- None :: < & HashMap < AssetRef , Activity > > ,
822+ /*annual_activities=*/ None ,
817823 )
818824 . collect ( ) ;
819825 let priced_groups: HashSet < _ > = group_prices. keys ( ) . cloned ( ) . collect ( ) ;
@@ -872,10 +878,17 @@ where
872878 I : Iterator < Item = ( & ' a AssetRef , & ' a TimeSliceID , Activity ) > ,
873879{
874880 // Validate supported strategies, and require annual activities for FullCost pricing.
875- assert ! ( matches!(
876- ( pricing_strategy, annual_activities) ,
877- ( PricingStrategy :: MarginalCost , _) | ( PricingStrategy :: FullCost , Some ( _) )
878- ) ) ;
881+ match pricing_strategy {
882+ PricingStrategy :: MarginalCost => assert ! (
883+ annual_activities. is_none( ) ,
884+ "Cannot provide annual_activities with marginal pricing strategy"
885+ ) ,
886+ PricingStrategy :: FullCost => assert ! (
887+ annual_activities. is_some( ) ,
888+ "annual_activities must be provided for full pricing strategy"
889+ ) ,
890+ _ => panic ! ( "Invalid pricing strategy" ) ,
891+ }
879892
880893 // Accumulator map to collect costs from existing assets. Collects a weighted average
881894 // for each (commodity, region, ts selection), across all contributing assets, weighted
@@ -888,16 +901,15 @@ where
888901 > = IndexMap :: new ( ) ;
889902
890903 // Cache of annual fixed costs per flow for each asset (only used for Full cost pricing)
891- let mut annual_fixed_costs: HashMap < _ , _ > = HashMap :: new ( ) ;
904+ let mut annual_fixed_costs = HashMap :: new ( ) ;
892905
893906 // Iterate over existing assets and their activities
894907 for ( asset, time_slice, activity) in activity_for_existing {
895908 let region_id = asset. region_id ( ) ;
896909
897910 // When using full cost pricing, skip assets with zero annual activity, since we cannot
898911 // calculate a fixed cost per flow.
899- let annual_activity = matches ! ( pricing_strategy, PricingStrategy :: FullCost )
900- . then ( || annual_activities. unwrap ( ) [ asset] ) ;
912+ let annual_activity = annual_activities. map ( |activities| activities[ asset] ) ;
901913 if annual_activity. is_some_and ( |annual_activity| annual_activity < Activity :: EPSILON ) {
902914 continue ;
903915 }
0 commit comments