@@ -11,6 +11,7 @@ use anyhow::Result;
1111use costs:: annual_fixed_cost;
1212use erased_serde:: Serialize as ErasedSerialize ;
1313use indexmap:: IndexMap ;
14+ use optimisation:: ResultsMap ;
1415use serde:: Serialize ;
1516use std:: any:: Any ;
1617use std:: cmp:: Ordering ;
@@ -65,6 +66,22 @@ pub struct AppraisalOutput {
6566}
6667
6768impl AppraisalOutput {
69+ /// Create a new `AppraisalOutput`
70+ pub fn new < T : MetricTrait > (
71+ asset : AssetRef ,
72+ results : ResultsMap ,
73+ metric : T ,
74+ coefficients : Rc < ObjectiveCoefficients > ,
75+ ) -> Self {
76+ Self {
77+ asset,
78+ capacity : results. capacity ,
79+ activity : results. activity ,
80+ unmet_demand : results. unmet_demand ,
81+ metric : Box :: new ( metric) ,
82+ coefficients,
83+ }
84+ }
6885 /// Compare this appraisal to another on the basis of the comparison metric.
6986 ///
7087 /// Note that if the metrics are approximately equal (as determined by the [`approx_eq!`] macro)
@@ -244,14 +261,12 @@ fn calculate_lcox(
244261 & coefficients. activity_coefficients ,
245262 ) ;
246263
247- Ok ( AppraisalOutput {
248- asset : asset. clone ( ) ,
249- capacity : results. capacity ,
250- activity : results. activity ,
251- unmet_demand : results. unmet_demand ,
252- metric : Box :: new ( LCOXMetric :: new ( cost_index) ) ,
253- coefficients : coefficients. clone ( ) ,
254- } )
264+ Ok ( AppraisalOutput :: new (
265+ asset. clone ( ) ,
266+ results,
267+ LCOXMetric :: new ( cost_index) ,
268+ coefficients. clone ( ) ,
269+ ) )
255270}
256271
257272/// Calculate NPV for a hypothetical investment in the given asset.
@@ -290,14 +305,12 @@ fn calculate_npv(
290305 & coefficients. activity_coefficients ,
291306 ) ;
292307
293- Ok ( AppraisalOutput {
294- asset : asset. clone ( ) ,
295- capacity : results. capacity ,
296- activity : results. activity ,
297- unmet_demand : results. unmet_demand ,
298- metric : Box :: new ( NPVMetric :: new ( profitability_index) ) ,
299- coefficients : coefficients. clone ( ) ,
300- } )
308+ Ok ( AppraisalOutput :: new (
309+ asset. clone ( ) ,
310+ results,
311+ NPVMetric :: new ( profitability_index) ,
312+ coefficients. clone ( ) ,
313+ ) )
301314}
302315
303316/// Appraise the given investment with the specified objective type
0 commit comments