Skip to content

Commit 2da91a0

Browse files
committed
Drop demand field from AppraisalOutput
The demand map is the same for all `AppraisalOutput`s for a given appraisal iteration, so there's no need to store it. If many assets are being appraised, it could result in many clones.
1 parent 878534f commit 2da91a0

4 files changed

Lines changed: 7 additions & 9 deletions

File tree

src/fixture.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,6 @@ pub fn time_slice_info2() -> TimeSliceInfo {
382382
pub fn appraisal_output(asset: Asset, time_slice: TimeSliceID) -> AppraisalOutput {
383383
let activity_coefficients = indexmap! { time_slice.clone() => MoneyPerActivity(0.5) };
384384
let activity = indexmap! { time_slice.clone() => Activity(10.0) };
385-
let demand = indexmap! { time_slice.clone() => Flow(100.0) };
386385
let unmet_demand = indexmap! { time_slice.clone() => Flow(5.0) };
387386
AppraisalOutput {
388387
asset: AssetRef::from(asset),
@@ -393,7 +392,6 @@ pub fn appraisal_output(asset: Asset, time_slice: TimeSliceID) -> AppraisalOutpu
393392
unmet_demand_coefficient: MoneyPerFlow(10000.0),
394393
},
395394
activity,
396-
demand,
397395
unmet_demand,
398396
metric: Box::new(LCOXMetric::new(MoneyPerActivity(4.14))),
399397
}

src/output.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -467,11 +467,12 @@ impl DebugDataWriter {
467467
milestone_year: u32,
468468
run_description: &str,
469469
appraisal_results: &[AppraisalOutput],
470+
demand: &IndexMap<TimeSliceID, Flow>,
470471
) -> Result<()> {
471472
for result in appraisal_results {
472473
for (time_slice, activity) in &result.activity {
473474
let activity_coefficient = result.coefficients.activity_coefficients[time_slice];
474-
let demand = result.demand[time_slice];
475+
let demand = demand[time_slice];
475476
let unmet_demand = result.unmet_demand[time_slice];
476477
let row = AppraisalResultsTimeSliceRow {
477478
milestone_year,
@@ -564,13 +565,15 @@ impl DataWriter {
564565
milestone_year: u32,
565566
run_description: &str,
566567
appraisal_results: &[AppraisalOutput],
568+
demand: &IndexMap<TimeSliceID, Flow>,
567569
) -> Result<()> {
568570
if let Some(wtr) = &mut self.debug_writer {
569571
wtr.write_appraisal_results(milestone_year, run_description, appraisal_results)?;
570572
wtr.write_appraisal_time_slice_results(
571573
milestone_year,
572574
run_description,
573575
appraisal_results,
576+
demand,
574577
)?;
575578
}
576579

@@ -1006,6 +1009,7 @@ mod tests {
10061009
let milestone_year = 2020;
10071010
let run_description = "test_run".to_string();
10081011
let dir = tempdir().unwrap();
1012+
let demand = indexmap! {time_slice.clone() => Flow(100.0) };
10091013

10101014
// Write appraisal time slice results
10111015
{
@@ -1015,6 +1019,7 @@ mod tests {
10151019
milestone_year,
10161020
&run_description,
10171021
&[appraisal_output],
1022+
&demand,
10181023
)
10191024
.unwrap();
10201025
writer.flush().unwrap();

src/simulation/investment.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -796,6 +796,7 @@ fn select_best_assets(
796796
year,
797797
&format!("{} {} round {}", &commodity.id, &agent.id, round),
798798
&outputs_for_opts,
799+
&demand,
799800
)?;
800801

801802
sort_appraisal_outputs_by_investment_priority(&mut outputs_for_opts);

src/simulation/investment/appraisal.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,6 @@ pub struct AppraisalOutput {
6161
pub metric: Box<dyn MetricTrait>,
6262
/// Capacity and activity coefficients used in the appraisal
6363
pub coefficients: ObjectiveCoefficients,
64-
/// Demand profile used in the appraisal
65-
pub demand: DemandMap,
6664
}
6765

6866
impl AppraisalOutput {
@@ -252,7 +250,6 @@ fn calculate_lcox(
252250
unmet_demand: results.unmet_demand,
253251
metric: Box::new(LCOXMetric::new(cost_index)),
254252
coefficients: coefficients.clone(),
255-
demand: demand.clone(),
256253
})
257254
}
258255

@@ -299,7 +296,6 @@ fn calculate_npv(
299296
unmet_demand: results.unmet_demand,
300297
metric: Box::new(NPVMetric::new(profitability_index)),
301298
coefficients: coefficients.clone(),
302-
demand: demand.clone(),
303299
})
304300
}
305301

@@ -557,7 +553,6 @@ mod tests {
557553
unmet_demand_coefficient: MoneyPerFlow(0.0),
558554
},
559555
activity: IndexMap::new(),
560-
demand: IndexMap::new(),
561556
unmet_demand: IndexMap::new(),
562557
metric,
563558
})
@@ -887,7 +882,6 @@ mod tests {
887882
unmet_demand_coefficient: MoneyPerFlow(0.0),
888883
},
889884
activity: IndexMap::new(),
890-
demand: IndexMap::new(),
891885
unmet_demand: IndexMap::new(),
892886
metric,
893887
})

0 commit comments

Comments
 (0)