22use super :: super :: { input_err_msg, read_csv, try_insert} ;
33use crate :: ISSUES_URL ;
44use crate :: agent:: { AgentID , AgentMap , AgentObjectiveMap , DecisionRule , ObjectiveType } ;
5- use crate :: model:: ALLOW_BROKEN_OPTION_NAME ;
5+ use crate :: model:: { ALLOW_BROKEN_OPTION_NAME , broken_model_options_allowed } ;
66use crate :: units:: Dimensionless ;
77use crate :: year:: parse_year_str;
88use anyhow:: { Context , Result , ensure} ;
@@ -36,7 +36,6 @@ struct AgentObjectiveRaw {
3636/// * `model_dir` - Folder containing model configuration files
3737/// * `agents` - Map of agents
3838/// * `milestone_years` - Milestone years for the simulation
39- /// * `allow_broken_options` - Whether to allow broken model options
4039///
4140/// # Returns
4241///
@@ -45,24 +44,17 @@ pub fn read_agent_objectives(
4544 model_dir : & Path ,
4645 agents : & AgentMap ,
4746 milestone_years : & [ u32 ] ,
48- allow_broken_options : bool ,
4947) -> Result < HashMap < AgentID , AgentObjectiveMap > > {
5048 let file_path = model_dir. join ( AGENT_OBJECTIVES_FILE_NAME ) ;
5149 let agent_objectives_csv = read_csv ( & file_path) ?;
52- read_agent_objectives_from_iter (
53- agent_objectives_csv,
54- agents,
55- milestone_years,
56- allow_broken_options,
57- )
58- . with_context ( || input_err_msg ( & file_path) )
50+ read_agent_objectives_from_iter ( agent_objectives_csv, agents, milestone_years)
51+ . with_context ( || input_err_msg ( & file_path) )
5952}
6053
6154fn read_agent_objectives_from_iter < I > (
6255 iter : I ,
6356 agents : & AgentMap ,
6457 milestone_years : & [ u32 ] ,
65- allow_broken_options : bool ,
6658) -> Result < HashMap < AgentID , AgentObjectiveMap > >
6759where
6860 I : Iterator < Item = AgentObjectiveRaw > ,
@@ -109,7 +101,7 @@ where
109101 . collect_vec ( ) ;
110102 if !npv_years. is_empty ( ) {
111103 ensure ! (
112- allow_broken_options ,
104+ broken_model_options_allowed ( ) ,
113105 "The NPV option is BROKEN and should not be used. See: {ISSUES_URL}/716.\n \
114106 If you are sure that you want to enable it anyway, you need to set the \
115107 {ALLOW_BROKEN_OPTION_NAME} option to true."
@@ -251,7 +243,6 @@ mod tests {
251243 iter:: once ( objective_raw. clone ( ) ) ,
252244 & agents,
253245 & milestone_years,
254- false ,
255246 )
256247 . unwrap ( ) ;
257248 assert_eq ! ( actual, expected) ;
@@ -261,7 +252,7 @@ mod tests {
261252 fn test_read_agent_objectives_from_iter_invalid_no_objective_for_agent ( agents : AgentMap ) {
262253 // Missing objective for agent
263254 assert_error ! (
264- read_agent_objectives_from_iter( iter:: empty( ) , & agents, & [ 2020 ] , false ) ,
255+ read_agent_objectives_from_iter( iter:: empty( ) , & agents, & [ 2020 ] ) ,
265256 "Agent agent1 has no objectives"
266257 ) ;
267258 }
@@ -273,12 +264,7 @@ mod tests {
273264 ) {
274265 // Missing objective for milestone year
275266 assert_error ! (
276- read_agent_objectives_from_iter(
277- iter:: once( objective_raw) ,
278- & agents,
279- & [ 2020 , 2030 ] ,
280- false
281- ) ,
267+ read_agent_objectives_from_iter( iter:: once( objective_raw) , & agents, & [ 2020 , 2030 ] ) ,
282268 "Agent agent1 is missing objectives for the following milestone years: [2030]"
283269 ) ;
284270 }
@@ -294,7 +280,7 @@ mod tests {
294280 decision_lexico_order : None ,
295281 } ;
296282 assert_error ! (
297- read_agent_objectives_from_iter( [ bad_objective] . into_iter( ) , & agents, & [ 2020 ] , false ) ,
283+ read_agent_objectives_from_iter( [ bad_objective] . into_iter( ) , & agents, & [ 2020 ] ) ,
298284 "Field decision_weight should be empty for this decision rule"
299285 ) ;
300286 }
0 commit comments