Skip to main content

surge_solution/
ids.rs

1// SPDX-License-Identifier: LicenseRef-PolyForm-Noncommercial-1.0.0
2//! Stable solution/report identifiers shared across dispatch and OPF.
3
4use surge_network::market::{CombinedCyclePlant, DispatchableLoad};
5use surge_network::network::Generator;
6
7pub fn default_machine_id(machine_id: Option<&str>) -> String {
8    machine_id.unwrap_or("1").to_string()
9}
10
11pub fn generator_resource_id(generator: &Generator) -> String {
12    if generator.id.is_empty() {
13        let machine_id = default_machine_id(generator.machine_id.as_deref());
14        if generator.storage.is_some() {
15            format!("storage:{}:{machine_id}", generator.bus)
16        } else {
17            format!("gen:{}:{machine_id}", generator.bus)
18        }
19    } else {
20        generator.id.clone()
21    }
22}
23
24pub fn dispatchable_load_resource_id(
25    dispatchable_load: &DispatchableLoad,
26    source_index: usize,
27) -> String {
28    if dispatchable_load.resource_id.is_empty() {
29        format!("dl:{}:{source_index}", dispatchable_load.bus)
30    } else {
31        dispatchable_load.resource_id.clone()
32    }
33}
34
35pub fn combined_cycle_plant_id(plant: Option<&CombinedCyclePlant>, plant_index: usize) -> String {
36    plant.map_or_else(
37        || format!("combined_cycle:{plant_index}"),
38        |plant| {
39            if !plant.id.is_empty() {
40                plant.id.clone()
41            } else if !plant.name.is_empty() {
42                plant.name.clone()
43            } else {
44                format!("combined_cycle:{plant_index}")
45            }
46        },
47    )
48}