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::{
14    ALLOW_DANGEROUS_OPTION_NAME, ModelParameters, dangerous_model_options_enabled,
15};
16
17/// Model definition
18pub struct Model {
19    /// Path to model folder
20    pub model_path: PathBuf,
21    /// Parameters from the model TOML file
22    pub parameters: ModelParameters,
23    /// Agents for the simulation
24    pub agents: AgentMap,
25    /// Commodities for the simulation
26    pub commodities: CommodityMap,
27    /// Processes for the simulation
28    pub processes: ProcessMap,
29    /// Information about seasons and time slices
30    pub time_slice_info: TimeSliceInfo,
31    /// Regions for the simulation
32    pub regions: RegionMap,
33    /// User-defined assets
34    pub user_assets: Vec<AssetRef>,
35    /// Commodity ordering for each milestone year
36    pub investment_order: HashMap<u32, Vec<InvestmentSet>>,
37}
38
39impl Model {
40    /// Iterate over the model's milestone years.
41    pub fn iter_years(&self) -> impl Iterator<Item = u32> + '_ {
42        self.parameters.milestone_years.iter().copied()
43    }
44
45    /// Iterate over the model's regions (region IDs).
46    pub fn iter_regions(&self) -> indexmap::map::Keys<'_, RegionID, Region> {
47        self.regions.keys()
48    }
49
50    /// Iterate over all the markets in the model.
51    pub fn iter_markets(&self) -> impl Iterator<Item = (CommodityID, RegionID)> + '_ {
52        self.commodities.keys().flat_map(move |commodity_id| {
53            self.regions
54                .keys()
55                .map(move |region_id| (commodity_id.clone(), region_id.clone()))
56        })
57    }
58}