pub struct System { /* private fields */ }Expand description
Top-level system representation.
Produced by cobre-io::load_case() or SystemBuilder in tests.
Consumed by solvers and analysis tools via shared reference.
Immutable and thread-safe after construction.
Entity collections are in canonical order (sorted by EntityId’s inner i32).
Lookup indices provide O(1) access by EntityId.
§Examples
use cobre_core::{Bus, DeficitSegment, EntityId, SystemBuilder};
let bus = Bus {
id: EntityId(1),
name: "Main Bus".to_string(),
deficit_segments: vec![],
excess_cost: 0.0,
};
let system = SystemBuilder::new()
.buses(vec![bus])
.build()
.expect("valid system");
assert_eq!(system.n_buses(), 1);
assert!(system.bus(EntityId(1)).is_some());Implementations§
Source§impl System
impl System
Sourcepub fn pumping_stations(&self) -> &[PumpingStation]
pub fn pumping_stations(&self) -> &[PumpingStation]
Returns all pumping stations in canonical ID order.
Sourcepub fn contracts(&self) -> &[EnergyContract]
pub fn contracts(&self) -> &[EnergyContract]
Returns all energy contracts in canonical ID order.
Sourcepub fn non_controllable_sources(&self) -> &[NonControllableSource]
pub fn non_controllable_sources(&self) -> &[NonControllableSource]
Returns all non-controllable sources in canonical ID order.
Sourcepub fn n_thermals(&self) -> usize
pub fn n_thermals(&self) -> usize
Returns the number of thermal plants in the system.
Sourcepub fn n_pumping_stations(&self) -> usize
pub fn n_pumping_stations(&self) -> usize
Returns the number of pumping stations in the system.
Sourcepub fn n_contracts(&self) -> usize
pub fn n_contracts(&self) -> usize
Returns the number of energy contracts in the system.
Sourcepub fn n_non_controllable_sources(&self) -> usize
pub fn n_non_controllable_sources(&self) -> usize
Returns the number of non-controllable sources in the system.
Sourcepub fn bus(&self, id: EntityId) -> Option<&Bus>
pub fn bus(&self, id: EntityId) -> Option<&Bus>
Returns the bus with the given ID, or None if not found.
Sourcepub fn line(&self, id: EntityId) -> Option<&Line>
pub fn line(&self, id: EntityId) -> Option<&Line>
Returns the line with the given ID, or None if not found.
Sourcepub fn hydro(&self, id: EntityId) -> Option<&Hydro>
pub fn hydro(&self, id: EntityId) -> Option<&Hydro>
Returns the hydro plant with the given ID, or None if not found.
Sourcepub fn thermal(&self, id: EntityId) -> Option<&Thermal>
pub fn thermal(&self, id: EntityId) -> Option<&Thermal>
Returns the thermal plant with the given ID, or None if not found.
Sourcepub fn pumping_station(&self, id: EntityId) -> Option<&PumpingStation>
pub fn pumping_station(&self, id: EntityId) -> Option<&PumpingStation>
Returns the pumping station with the given ID, or None if not found.
Sourcepub fn contract(&self, id: EntityId) -> Option<&EnergyContract>
pub fn contract(&self, id: EntityId) -> Option<&EnergyContract>
Returns the energy contract with the given ID, or None if not found.
Sourcepub fn non_controllable_source(
&self,
id: EntityId,
) -> Option<&NonControllableSource>
pub fn non_controllable_source( &self, id: EntityId, ) -> Option<&NonControllableSource>
Returns the non-controllable source with the given ID, or None if not found.
Sourcepub fn cascade(&self) -> &CascadeTopology
pub fn cascade(&self) -> &CascadeTopology
Returns a reference to the hydro cascade topology.
Sourcepub fn network(&self) -> &NetworkTopology
pub fn network(&self) -> &NetworkTopology
Returns a reference to the transmission network topology.
Sourcepub fn stages(&self) -> &[Stage]
pub fn stages(&self) -> &[Stage]
Returns all stages in canonical ID order (study and pre-study stages).
Sourcepub fn n_stages(&self) -> usize
pub fn n_stages(&self) -> usize
Returns the number of stages (study and pre-study) in the system.
Sourcepub fn stage(&self, id: i32) -> Option<&Stage>
pub fn stage(&self, id: i32) -> Option<&Stage>
Returns the stage with the given stage ID, or None if not found.
Stage IDs are i32. Study stages have non-negative IDs; pre-study
stages (used only for PAR model lag initialization) have negative IDs.
Sourcepub fn policy_graph(&self) -> &PolicyGraph
pub fn policy_graph(&self) -> &PolicyGraph
Returns a reference to the policy graph.
Sourcepub fn penalties(&self) -> &ResolvedPenalties
pub fn penalties(&self) -> &ResolvedPenalties
Returns a reference to the pre-resolved penalty table.
Sourcepub fn bounds(&self) -> &ResolvedBounds
pub fn bounds(&self) -> &ResolvedBounds
Returns a reference to the pre-resolved bounds table.
Sourcepub fn inflow_models(&self) -> &[InflowModel]
pub fn inflow_models(&self) -> &[InflowModel]
Returns all PAR(p) inflow models in canonical order (by hydro ID, then stage ID).
Sourcepub fn load_models(&self) -> &[LoadModel]
pub fn load_models(&self) -> &[LoadModel]
Returns all load models in canonical order (by bus ID, then stage ID).
Sourcepub fn correlation(&self) -> &CorrelationModel
pub fn correlation(&self) -> &CorrelationModel
Returns a reference to the correlation model.
Sourcepub fn initial_conditions(&self) -> &InitialConditions
pub fn initial_conditions(&self) -> &InitialConditions
Returns a reference to the initial conditions.
Sourcepub fn generic_constraints(&self) -> &[GenericConstraint]
pub fn generic_constraints(&self) -> &[GenericConstraint]
Returns all generic constraints in canonical ID order.
Sourcepub fn scenario_source(&self) -> &ScenarioSource
pub fn scenario_source(&self) -> &ScenarioSource
Returns a reference to the scenario source configuration.
Sourcepub fn rebuild_indices(&mut self)
pub fn rebuild_indices(&mut self)
Rebuild all O(1) lookup indices from the entity collections.
Required after deserialization: the HashMap lookup indices are not serialized
(per spec SS6.2 — they are derived from the entity collections). After
deserializing a System from JSON or any other format, call this method once
to restore O(1) access via bus, hydro, etc.
§Examples
use cobre_core::{Bus, DeficitSegment, EntityId, SystemBuilder};
let system = SystemBuilder::new()
.buses(vec![Bus {
id: EntityId(1),
name: "A".to_string(),
deficit_segments: vec![],
excess_cost: 0.0,
}])
.build()
.expect("valid system");
let json = serde_json::to_string(&system).unwrap();
let mut deserialized: cobre_core::System = serde_json::from_str(&json).unwrap();
deserialized.rebuild_indices();
// O(1) lookup now works after index rebuild.
assert!(deserialized.bus(EntityId(1)).is_some());