Skip to main content

SystemBuilder

Struct SystemBuilder 

Source
pub struct SystemBuilder { /* private fields */ }
Expand description

Builder for constructing a validated, immutable System.

Accepts entity collections, sorts entities by ID, checks for duplicate IDs, builds topology, and returns the System. All entity collections default to empty; only supply the collections your test case requires.

§Examples

use cobre_core::{Bus, DeficitSegment, EntityId, SystemBuilder};

let system = SystemBuilder::new()
    .buses(vec![
        Bus { id: EntityId(2), name: "B".to_string(), deficit_segments: vec![], excess_cost: 0.0 },
        Bus { id: EntityId(1), name: "A".to_string(), deficit_segments: vec![], excess_cost: 0.0 },
    ])
    .build()
    .expect("valid system");

// Canonical ordering: id=1 comes before id=2.
assert_eq!(system.buses()[0].id, EntityId(1));
assert_eq!(system.buses()[1].id, EntityId(2));

Implementations§

Source§

impl SystemBuilder

Source

pub fn new() -> Self

Create a new empty builder. All entity collections start empty.

New fields default to empty/default values so that pre-existing tests continue to work without modification.

Source

pub fn buses(self, buses: Vec<Bus>) -> Self

Set the bus collection.

Source

pub fn lines(self, lines: Vec<Line>) -> Self

Set the line collection.

Source

pub fn hydros(self, hydros: Vec<Hydro>) -> Self

Set the hydro plant collection.

Source

pub fn thermals(self, thermals: Vec<Thermal>) -> Self

Set the thermal plant collection.

Source

pub fn pumping_stations(self, stations: Vec<PumpingStation>) -> Self

Set the pumping station collection.

Source

pub fn contracts(self, contracts: Vec<EnergyContract>) -> Self

Set the energy contract collection.

Source

pub fn non_controllable_sources( self, sources: Vec<NonControllableSource>, ) -> Self

Set the non-controllable source collection.

Source

pub fn stages(self, stages: Vec<Stage>) -> Self

Set the stage collection (study and pre-study stages).

Stages are sorted by id in build to canonical order.

Source

pub fn policy_graph(self, policy_graph: PolicyGraph) -> Self

Set the policy graph.

Source

pub fn penalties(self, penalties: ResolvedPenalties) -> Self

Set the pre-resolved penalty table.

Populated by cobre-io after the three-tier penalty cascade is applied.

Source

pub fn bounds(self, bounds: ResolvedBounds) -> Self

Set the pre-resolved bounds table.

Populated by cobre-io after base bounds are overlaid with stage overrides.

Source

pub fn inflow_models(self, inflow_models: Vec<InflowModel>) -> Self

Set the PAR(p) inflow model collection.

Source

pub fn load_models(self, load_models: Vec<LoadModel>) -> Self

Set the load model collection.

Source

pub fn correlation(self, correlation: CorrelationModel) -> Self

Set the correlation model.

Source

pub fn initial_conditions(self, initial_conditions: InitialConditions) -> Self

Set the initial conditions.

Source

pub fn generic_constraints( self, generic_constraints: Vec<GenericConstraint>, ) -> Self

Set the generic constraint collection.

Constraints are sorted by id in build to canonical order.

Source

pub fn scenario_source(self, scenario_source: ScenarioSource) -> Self

Set the scenario source configuration.

Source

pub fn build(self) -> Result<System, Vec<ValidationError>>

Build the System.

Sorts all entity collections by EntityId (canonical ordering). Checks for duplicate IDs within each collection. Validates all cross-reference fields (e.g., bus_id, downstream_id) against the appropriate index to ensure every referenced entity exists. Builds CascadeTopology and NetworkTopology. Validates the cascade graph for cycles and checks hydro filling configurations. Constructs lookup indices.

Returns Err with a list of all validation errors found across all collections. All invalid references across all entity types are collected before returning — no short-circuiting on first error.

§Errors

Returns Err(Vec<ValidationError>) if:

  • Duplicate IDs are detected in any entity collection.
  • Any cross-reference field refers to an entity ID that does not exist.
  • The hydro cascade graph contains a cycle.
  • Any hydro filling configuration is invalid (non-positive inflow or missing entry_stage_id).

All errors across all collections are reported together.

Trait Implementations§

Source§

impl Default for SystemBuilder

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

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.