@@ -14,6 +14,7 @@ use indexmap::IndexMap;
1414use serde:: Serialize ;
1515use std:: any:: Any ;
1616use std:: cmp:: Ordering ;
17+ use std:: rc:: Rc ;
1718
1819pub mod coefficients;
1920mod constraints;
@@ -60,7 +61,7 @@ pub struct AppraisalOutput {
6061 /// The comparison metric to compare investment decisions
6162 pub metric : Box < dyn MetricTrait > ,
6263 /// Capacity and activity coefficients used in the appraisal
63- pub coefficients : ObjectiveCoefficients ,
64+ pub coefficients : Rc < ObjectiveCoefficients > ,
6465}
6566
6667impl AppraisalOutput {
@@ -223,7 +224,7 @@ fn calculate_lcox(
223224 asset : & AssetRef ,
224225 max_capacity : Option < AssetCapacity > ,
225226 commodity : & Commodity ,
226- coefficients : & ObjectiveCoefficients ,
227+ coefficients : & Rc < ObjectiveCoefficients > ,
227228 demand : & DemandMap ,
228229) -> Result < AppraisalOutput > {
229230 let results = perform_optimisation (
@@ -263,7 +264,7 @@ fn calculate_npv(
263264 asset : & AssetRef ,
264265 max_capacity : Option < AssetCapacity > ,
265266 commodity : & Commodity ,
266- coefficients : & ObjectiveCoefficients ,
267+ coefficients : & Rc < ObjectiveCoefficients > ,
267268 demand : & DemandMap ,
268269) -> Result < AppraisalOutput > {
269270 let results = perform_optimisation (
@@ -311,7 +312,7 @@ pub fn appraise_investment(
311312 max_capacity : Option < AssetCapacity > ,
312313 commodity : & Commodity ,
313314 objective_type : & ObjectiveType ,
314- coefficients : & ObjectiveCoefficients ,
315+ coefficients : & Rc < ObjectiveCoefficients > ,
315316 demand : & DemandMap ,
316317) -> Result < AppraisalOutput > {
317318 let appraisal_method = match objective_type {
@@ -526,6 +527,14 @@ mod tests {
526527 assert ! ( compare_asset_fallback( & asset2, & asset3) . is_gt( ) ) ;
527528 }
528529
530+ fn objective_coeffs ( ) -> Rc < ObjectiveCoefficients > {
531+ Rc :: new ( ObjectiveCoefficients {
532+ capacity_coefficient : MoneyPerCapacity ( 0.0 ) ,
533+ activity_coefficients : IndexMap :: new ( ) ,
534+ unmet_demand_coefficient : MoneyPerFlow ( 0.0 ) ,
535+ } )
536+ }
537+
529538 /// Creates appraisal from corresponding assets and metrics
530539 ///
531540 /// # Panics
@@ -547,11 +556,7 @@ mod tests {
547556 . map ( |( asset, metric) | AppraisalOutput {
548557 asset : AssetRef :: from ( asset) ,
549558 capacity : AssetCapacity :: Continuous ( Capacity ( 10.0 ) ) ,
550- coefficients : ObjectiveCoefficients {
551- capacity_coefficient : MoneyPerCapacity ( 0.0 ) ,
552- activity_coefficients : IndexMap :: new ( ) ,
553- unmet_demand_coefficient : MoneyPerFlow ( 0.0 ) ,
554- } ,
559+ coefficients : objective_coeffs ( ) ,
555560 activity : IndexMap :: new ( ) ,
556561 unmet_demand : IndexMap :: new ( ) ,
557562 metric,
@@ -876,11 +881,7 @@ mod tests {
876881 . map ( |metric| AppraisalOutput {
877882 asset : AssetRef :: from ( asset. clone ( ) ) ,
878883 capacity : AssetCapacity :: Continuous ( Capacity ( 0.0 ) ) ,
879- coefficients : ObjectiveCoefficients {
880- capacity_coefficient : MoneyPerCapacity ( 0.0 ) ,
881- activity_coefficients : IndexMap :: new ( ) ,
882- unmet_demand_coefficient : MoneyPerFlow ( 0.0 ) ,
883- } ,
884+ coefficients : objective_coeffs ( ) ,
884885 activity : IndexMap :: new ( ) ,
885886 unmet_demand : IndexMap :: new ( ) ,
886887 metric,
0 commit comments