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
impl SystemBuilder
Sourcepub fn new() -> Self
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.
Sourcepub fn pumping_stations(self, stations: Vec<PumpingStation>) -> Self
pub fn pumping_stations(self, stations: Vec<PumpingStation>) -> Self
Set the pumping station collection.
Sourcepub fn contracts(self, contracts: Vec<EnergyContract>) -> Self
pub fn contracts(self, contracts: Vec<EnergyContract>) -> Self
Set the energy contract collection.
Sourcepub fn non_controllable_sources(
self,
sources: Vec<NonControllableSource>,
) -> Self
pub fn non_controllable_sources( self, sources: Vec<NonControllableSource>, ) -> Self
Set the non-controllable source collection.
Sourcepub fn stages(self, stages: Vec<Stage>) -> Self
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.
Sourcepub fn policy_graph(self, policy_graph: PolicyGraph) -> Self
pub fn policy_graph(self, policy_graph: PolicyGraph) -> Self
Set the policy graph.
Sourcepub fn penalties(self, penalties: ResolvedPenalties) -> Self
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.
Sourcepub fn bounds(self, bounds: ResolvedBounds) -> Self
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.
Sourcepub fn resolved_generic_bounds(
self,
resolved_generic_bounds: ResolvedGenericConstraintBounds,
) -> Self
pub fn resolved_generic_bounds( self, resolved_generic_bounds: ResolvedGenericConstraintBounds, ) -> Self
Set the pre-resolved generic constraint RHS bound table.
Populated by cobre-io after converting raw parsed bound rows into
the indexed lookup structure.
Sourcepub fn resolved_load_factors(
self,
resolved_load_factors: ResolvedLoadFactors,
) -> Self
pub fn resolved_load_factors( self, resolved_load_factors: ResolvedLoadFactors, ) -> Self
Set the pre-resolved per-block load scaling factors.
Populated by cobre-io after resolving load_factors.json entries.
Sourcepub fn resolved_exchange_factors(
self,
resolved_exchange_factors: ResolvedExchangeFactors,
) -> Self
pub fn resolved_exchange_factors( self, resolved_exchange_factors: ResolvedExchangeFactors, ) -> Self
Set the pre-resolved per-block exchange capacity factors.
Populated by cobre-io after resolving exchange_factors.json entries.
Sourcepub fn resolved_ncs_bounds(self, resolved_ncs_bounds: ResolvedNcsBounds) -> Self
pub fn resolved_ncs_bounds(self, resolved_ncs_bounds: ResolvedNcsBounds) -> Self
Set the pre-resolved per-stage NCS available generation bounds.
Populated by cobre-io after resolving ncs_bounds.parquet entries.
Sourcepub fn resolved_ncs_factors(
self,
resolved_ncs_factors: ResolvedNcsFactors,
) -> Self
pub fn resolved_ncs_factors( self, resolved_ncs_factors: ResolvedNcsFactors, ) -> Self
Set the pre-resolved per-block NCS generation scaling factors.
Populated by cobre-io after resolving non_controllable_factors.json entries.
Sourcepub fn inflow_models(self, inflow_models: Vec<InflowModel>) -> Self
pub fn inflow_models(self, inflow_models: Vec<InflowModel>) -> Self
Set the PAR(p) inflow model collection.
Sourcepub fn load_models(self, load_models: Vec<LoadModel>) -> Self
pub fn load_models(self, load_models: Vec<LoadModel>) -> Self
Set the load model collection.
Sourcepub fn ncs_models(self, ncs_models: Vec<NcsModel>) -> Self
pub fn ncs_models(self, ncs_models: Vec<NcsModel>) -> Self
Set the NCS availability noise model collection.
Sourcepub fn correlation(self, correlation: CorrelationModel) -> Self
pub fn correlation(self, correlation: CorrelationModel) -> Self
Set the correlation model.
Sourcepub fn initial_conditions(self, initial_conditions: InitialConditions) -> Self
pub fn initial_conditions(self, initial_conditions: InitialConditions) -> Self
Set the initial conditions.
Sourcepub fn generic_constraints(
self,
generic_constraints: Vec<GenericConstraint>,
) -> Self
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.
Sourcepub fn scenario_source(self, scenario_source: ScenarioSource) -> Self
pub fn scenario_source(self, scenario_source: ScenarioSource) -> Self
Set the scenario source configuration.
Sourcepub fn build(self) -> Result<System, Vec<ValidationError>>
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.