muse2/agent.rs
1//! Agents drive the economy of the MUSE 2.0 simulation, through relative investment in different
2//! assets.
3use crate::commodity::CommodityID;
4use crate::id::{define_id_getter, define_id_type};
5use crate::process::Process;
6use crate::region::RegionID;
7use crate::units::{Dimensionless, Money};
8use indexmap::{IndexMap, IndexSet};
9use serde_string_enum::DeserializeLabeledStringEnum;
10use std::collections::HashMap;
11use std::rc::Rc;
12
13define_id_type! {AgentID}
14
15/// A map of [`Agent`]s, keyed by agent ID
16pub type AgentMap = IndexMap<AgentID, Agent>;
17
18/// A map of cost limits for an agent, keyed by year
19pub type AgentCostLimitsMap = HashMap<u32, AgentCostLimits>;
20
21/// A map of commodity portions for an agent, keyed by commodity and year
22pub type AgentCommodityPortionsMap = HashMap<(CommodityID, u32), Dimensionless>;
23
24/// A map for the agent's search space, keyed by commodity and year
25pub type AgentSearchSpaceMap = HashMap<(CommodityID, u32), Rc<Vec<Rc<Process>>>>;
26
27/// A map of objectives for an agent, keyed by commodity and year.
28///
29/// NB: As we currently only support the "single" decision rule, the only parameter we need for
30/// objectives is the type.
31pub type AgentObjectiveMap = HashMap<u32, ObjectiveType>;
32
33/// An agent in the simulation
34#[derive(Debug, Clone, PartialEq)]
35pub struct Agent {
36 /// A unique identifier for the agent.
37 pub id: AgentID,
38 /// A text description of the agent.
39 pub description: String,
40 /// The proportion of the commodity production that the agent is responsible for.
41 pub commodity_portions: AgentCommodityPortionsMap,
42 /// The processes that the agent will consider investing in.
43 pub search_space: AgentSearchSpaceMap,
44 /// The decision rule that the agent uses to decide investment.
45 pub decision_rule: DecisionRule,
46 /// Cost limits (e.g. capital cost, annual operating cost)
47 pub cost_limits: AgentCostLimitsMap,
48 /// The regions in which this agent operates.
49 pub regions: IndexSet<RegionID>,
50 /// The agent's objectives.
51 pub objectives: AgentObjectiveMap,
52}
53define_id_getter! {Agent, AgentID}
54
55/// The cost limits for an agent in a particular year
56#[derive(Debug, Clone, PartialEq)]
57pub struct AgentCostLimits {
58 /// The maximum capital cost the agent will pay.
59 pub capex_limit: Option<Money>,
60 /// The maximum annual operating cost (fuel plus var_opex etc) that the agent will pay.
61 pub annual_cost_limit: Option<Money>,
62}
63
64/// The decision rule for a particular objective
65#[derive(Debug, Clone, PartialEq)]
66pub enum DecisionRule {
67 /// Used when there is only a single objective
68 Single,
69 /// A simple weighting of objectives
70 Weighted,
71 /// Objectives are considered in a specific order
72 Lexicographical {
73 /// The tolerance around the main objective to consider secondary objectives. This is an absolute value of maximum deviation in the units of the main objective.
74 tolerance: f64,
75 },
76}
77
78/// The type of objective for the agent
79#[derive(Debug, Clone, Copy, PartialEq, DeserializeLabeledStringEnum)]
80pub enum ObjectiveType {
81 /// Average cost of one unit of output commodity over its lifetime
82 #[string = "lcox"]
83 LevelisedCostOfX,
84}