muse2/
model.rs

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