Skip to main content

System

Struct System 

Source
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

Source

pub fn buses(&self) -> &[Bus]

Returns all buses in canonical ID order.

Source

pub fn lines(&self) -> &[Line]

Returns all lines in canonical ID order.

Source

pub fn hydros(&self) -> &[Hydro]

Returns all hydro plants in canonical ID order.

Source

pub fn thermals(&self) -> &[Thermal]

Returns all thermal plants in canonical ID order.

Source

pub fn pumping_stations(&self) -> &[PumpingStation]

Returns all pumping stations in canonical ID order.

Source

pub fn contracts(&self) -> &[EnergyContract]

Returns all energy contracts in canonical ID order.

Source

pub fn non_controllable_sources(&self) -> &[NonControllableSource]

Returns all non-controllable sources in canonical ID order.

Source

pub fn n_buses(&self) -> usize

Returns the number of buses in the system.

Source

pub fn n_lines(&self) -> usize

Returns the number of lines in the system.

Source

pub fn n_hydros(&self) -> usize

Returns the number of hydro plants in the system.

Source

pub fn n_thermals(&self) -> usize

Returns the number of thermal plants in the system.

Source

pub fn n_pumping_stations(&self) -> usize

Returns the number of pumping stations in the system.

Source

pub fn n_contracts(&self) -> usize

Returns the number of energy contracts in the system.

Source

pub fn n_non_controllable_sources(&self) -> usize

Returns the number of non-controllable sources in the system.

Source

pub fn bus(&self, id: EntityId) -> Option<&Bus>

Returns the bus with the given ID, or None if not found.

Source

pub fn line(&self, id: EntityId) -> Option<&Line>

Returns the line with the given ID, or None if not found.

Source

pub fn hydro(&self, id: EntityId) -> Option<&Hydro>

Returns the hydro plant with the given ID, or None if not found.

Source

pub fn thermal(&self, id: EntityId) -> Option<&Thermal>

Returns the thermal plant with the given ID, or None if not found.

Source

pub fn pumping_station(&self, id: EntityId) -> Option<&PumpingStation>

Returns the pumping station with the given ID, or None if not found.

Source

pub fn contract(&self, id: EntityId) -> Option<&EnergyContract>

Returns the energy contract with the given ID, or None if not found.

Source

pub fn non_controllable_source( &self, id: EntityId, ) -> Option<&NonControllableSource>

Returns the non-controllable source with the given ID, or None if not found.

Source

pub fn cascade(&self) -> &CascadeTopology

Returns a reference to the hydro cascade topology.

Source

pub fn network(&self) -> &NetworkTopology

Returns a reference to the transmission network topology.

Source

pub fn stages(&self) -> &[Stage]

Returns all stages in canonical ID order (study and pre-study stages).

Source

pub fn n_stages(&self) -> usize

Returns the number of stages (study and pre-study) in the system.

Source

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.

Source

pub fn policy_graph(&self) -> &PolicyGraph

Returns a reference to the policy graph.

Source

pub fn penalties(&self) -> &ResolvedPenalties

Returns a reference to the pre-resolved penalty table.

Source

pub fn bounds(&self) -> &ResolvedBounds

Returns a reference to the pre-resolved bounds table.

Source

pub fn inflow_models(&self) -> &[InflowModel]

Returns all PAR(p) inflow models in canonical order (by hydro ID, then stage ID).

Source

pub fn load_models(&self) -> &[LoadModel]

Returns all load models in canonical order (by bus ID, then stage ID).

Source

pub fn correlation(&self) -> &CorrelationModel

Returns a reference to the correlation model.

Source

pub fn initial_conditions(&self) -> &InitialConditions

Returns a reference to the initial conditions.

Source

pub fn generic_constraints(&self) -> &[GenericConstraint]

Returns all generic constraints in canonical ID order.

Source

pub fn scenario_source(&self) -> &ScenarioSource

Returns a reference to the scenario source configuration.

Source

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());

Trait Implementations§

Source§

impl Debug for System

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for System

Source§

fn eq(&self, other: &System) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for System

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.