muse2/
model.rs

1//! The model represents the static input data provided by the user.
2use crate::agent::AgentMap;
3use crate::commodity::{CommodityID, CommodityMap};
4use crate::process::ProcessMap;
5use crate::region::{Region, RegionID, RegionMap};
6use crate::simulation::investment::InvestmentSet;
7use crate::time_slice::TimeSliceInfo;
8use std::collections::HashMap;
9use std::path::PathBuf;
10
11pub mod parameters;
12pub use parameters::{ALLOW_BROKEN_OPTION_NAME, ModelParameters, broken_model_options_allowed};
13
14/// Model definition
15pub struct Model {
16    /// Path to model folder
17    pub model_path: PathBuf,
18    /// Parameters from the model TOML file
19    pub parameters: ModelParameters,
20    /// Agents for the simulation
21    pub agents: AgentMap,
22    /// Commodities for the simulation
23    pub commodities: CommodityMap,
24    /// Processes for the simulation
25    pub processes: ProcessMap,
26    /// Information about seasons and time slices
27    pub time_slice_info: TimeSliceInfo,
28    /// Regions for the simulation
29    pub regions: RegionMap,
30    /// Commodity ordering for each milestone year
31    pub investment_order: HashMap<u32, Vec<InvestmentSet>>,
32}
33
34impl Model {
35    /// Iterate over the model's milestone years.
36    pub fn iter_years(&self) -> impl Iterator<Item = u32> + '_ {
37        self.parameters.milestone_years.iter().copied()
38    }
39
40    /// Iterate over the model's regions (region IDs).
41    pub fn iter_regions(&self) -> indexmap::map::Keys<'_, RegionID, Region> {
42        self.regions.keys()
43    }
44
45    /// Iterate over all the markets in the model.
46    pub fn iter_markets(&self) -> impl Iterator<Item = (CommodityID, RegionID)> + '_ {
47        self.commodities.keys().flat_map(move |commodity_id| {
48            self.regions
49                .keys()
50                .map(move |region_id| (commodity_id.clone(), region_id.clone()))
51        })
52    }
53}