Skip to content

Commit 2ab3ed7

Browse files
authored
Merge pull request #1094 from EnergySystemsModellingLab/unhide-npv2
Unhide NPV and add test (take 2)
2 parents 99cd132 + 097a942 commit 2ab3ed7

File tree

7 files changed

+1297
-34
lines changed

7 files changed

+1297
-34
lines changed

src/example/patches.rs

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,26 @@ static PATCHES: LazyLock<PatchMap> = LazyLock::new(get_all_patches);
1313

1414
/// Get all patches
1515
fn get_all_patches() -> PatchMap {
16-
[(
17-
// The simple example with gas boiler process made divisible
18-
"simple_divisible",
19-
vec![
20-
FilePatch::new("processes.csv")
21-
.with_deletion("RGASBR,Gas boiler,all,RSHEAT,2020,2040,1.0,")
22-
.with_addition("RGASBR,Gas boiler,all,RSHEAT,2020,2040,1.0,1000"),
23-
],
24-
)]
16+
[
17+
(
18+
// The simple example with gas boiler process made divisible
19+
"simple_divisible",
20+
vec![
21+
FilePatch::new("processes.csv")
22+
.with_deletion("RGASBR,Gas boiler,all,RSHEAT,2020,2040,1.0,")
23+
.with_addition("RGASBR,Gas boiler,all,RSHEAT,2020,2040,1.0,1000"),
24+
],
25+
),
26+
// The simple example with objective type set to NPV for one agent
27+
(
28+
"simple_npv",
29+
vec![
30+
FilePatch::new("agent_objectives.csv")
31+
.with_deletion("A0_RES,all,lcox,,")
32+
.with_addition("A0_RES,all,npv,,"),
33+
],
34+
),
35+
]
2536
.into_iter()
2637
.collect()
2738
}

src/input/agent/objective.rs

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
//! Code for reading agent objectives from a CSV file.
22
use super::super::{input_err_msg, read_csv, try_insert};
3-
use crate::ISSUES_URL;
43
use crate::agent::{AgentID, AgentMap, AgentObjectiveMap, DecisionRule, ObjectiveType};
5-
use crate::model::{ALLOW_BROKEN_OPTION_NAME, broken_model_options_allowed};
64
use crate::units::Dimensionless;
75
use crate::year::parse_year_str;
86
use anyhow::{Context, Result, ensure};
97
use itertools::Itertools;
10-
use log::warn;
118
use serde::Deserialize;
129
use std::collections::HashMap;
1310
use std::path::Path;
@@ -93,24 +90,6 @@ where
9390
missing_years.is_empty(),
9491
"Agent {agent_id} is missing objectives for the following milestone years: {missing_years:?}"
9592
);
96-
97-
let npv_years = milestone_years
98-
.iter()
99-
.copied()
100-
.filter(|year| agent_objectives[year] == ObjectiveType::NetPresentValue)
101-
.collect_vec();
102-
if !npv_years.is_empty() {
103-
ensure!(
104-
broken_model_options_allowed(),
105-
"The NPV option is BROKEN and should not be used. See: {ISSUES_URL}/716.\n\
106-
If you are sure that you want to enable it anyway, you need to set the \
107-
{ALLOW_BROKEN_OPTION_NAME} option to true."
108-
);
109-
warn!(
110-
"Agent {agent_id} is using NPV in years {npv_years:?}. \
111-
The NPV option is BROKEN and should not be used. See: {ISSUES_URL}/716."
112-
);
113-
}
11493
}
11594

11695
Ok(all_objectives)

src/patch.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,17 +108,22 @@ impl ModelPatch {
108108
}
109109
}
110110

111+
/// Represents all rows and columns of a CSV file.
112+
///
113+
/// Assumes that each row is unique (as it should be for all MUSE2 input files).
114+
type CSVTable = IndexSet<Vec<String>>;
115+
111116
/// Structure to hold patches for a model csv file.
112-
#[derive(Debug, Clone)]
117+
#[derive(Clone)]
113118
pub struct FilePatch {
114119
/// The file that this patch applies to (e.g. "agents.csv")
115120
filename: String,
116121
/// The header row (optional). If `None`, the header is not checked against base files.
117122
header_row: Option<Vec<String>>,
118123
/// Rows to delete (each row is a vector of fields)
119-
to_delete: IndexSet<Vec<String>>,
124+
to_delete: CSVTable,
120125
/// Rows to add (each row is a vector of fields)
121-
to_add: IndexSet<Vec<String>>,
126+
to_add: CSVTable,
122127
}
123128

124129
impl FilePatch {
@@ -229,7 +234,7 @@ fn modify_base_with_patch(base: &str, patch: &FilePatch) -> Result<String> {
229234
}
230235

231236
// Read all rows from the base, preserving order and checking for duplicates
232-
let mut base_rows: IndexSet<Vec<String>> = IndexSet::new();
237+
let mut base_rows: CSVTable = CSVTable::new();
233238
for result in reader.records() {
234239
let record = result?;
235240

tests/data/simple_npv/assets.csv

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
asset_id,process_id,region_id,agent_id,group_id,commission_year,decommission_year,capacity
2+
0,GASDRV,GBR,A0_GEX,,2020,2030,4002.26
3+
1,GASPRC,GBR,A0_GPR,,2020,2030,3782.13
4+
2,WNDFRM,GBR,A0_ELC,,2020,,3.964844
5+
3,GASCGT,GBR,A0_ELC,,2020,,2.43
6+
4,RGASBR,GBR,A0_RES,,2020,2035,2900.0
7+
5,RELCHP,GBR,A0_RES,,2020,2035,399.98
8+
6,RELCHP,GBR,A0_RES,,2030,,3290.2365652888325
9+
7,RGASBR,GBR,A0_RES,,2030,,3655.8184058764805
10+
8,GASCGT,GBR,A0_ELC,,2030,,33.820477802912976
11+
9,GASPRC,GBR,A0_GPR,,2030,,879.1648830751317
12+
10,GASDRV,GBR,A0_GEX,,2030,,923.1231272288879
13+
11,RGASBR,GBR,A0_RES,,2040,,4011.65737547648
14+
12,RELCHP,GBR,A0_RES,,2040,,802.3314750952961
15+
13,GASCGT,GBR,A0_ELC,,2040,,3.7231090668357614
16+
14,GASPRC,GBR,A0_GPR,,2040,,94.9477829022087
17+
15,GASDRV,GBR,A0_GEX,,2040,,99.6951720473196

0 commit comments

Comments
 (0)