Skip to main content

ResolvedPenalties

Struct ResolvedPenalties 

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

Pre-resolved penalty table for all entities across all stages.

Populated by cobre-io after the three-tier penalty cascade is applied. Provides O(1) lookup via direct array indexing.

Internal layout: data[entity_idx * n_stages + stage_idx] — iterating stages for a fixed entity accesses a contiguous memory region.

§Construction

Use ResolvedPenalties::new to allocate the table with a given default value, then populate by writing into the flat slice returned by the internal accessors. cobre-io is responsible for filling the data.

§Examples

use cobre_core::resolved::{
    BusStagePenalties, HydroStagePenalties, LineStagePenalties,
    NcsStagePenalties, ResolvedPenalties,
};

let hydro_default = HydroStagePenalties {
    spillage_cost: 0.01,
    diversion_cost: 0.02,
    fpha_turbined_cost: 0.03,
    storage_violation_below_cost: 1000.0,
    filling_target_violation_cost: 5000.0,
    turbined_violation_below_cost: 500.0,
    outflow_violation_below_cost: 500.0,
    outflow_violation_above_cost: 500.0,
    generation_violation_below_cost: 500.0,
    evaporation_violation_cost: 500.0,
    water_withdrawal_violation_cost: 500.0,
};
let bus_default = BusStagePenalties { excess_cost: 100.0 };
let line_default = LineStagePenalties { exchange_cost: 5.0 };
let ncs_default = NcsStagePenalties { curtailment_cost: 50.0 };

let table = ResolvedPenalties::new(
    3, 2, 1, 4, 5,
    hydro_default, bus_default, line_default, ncs_default,
);

// Hydro 1, stage 2 returns the default penalties.
let p = table.hydro_penalties(1, 2);
assert!((p.spillage_cost - 0.01).abs() < f64::EPSILON);

Implementations§

Source§

impl ResolvedPenalties

Source

pub fn empty() -> Self

Return an empty penalty table with zero entities and zero stages.

Used as the default value in System when no penalty resolution has been performed yet (e.g., when building a System from raw entity collections without cobre-io).

§Examples
use cobre_core::ResolvedPenalties;

let empty = ResolvedPenalties::empty();
assert_eq!(empty.n_stages(), 0);
Source

pub fn new( n_hydros: usize, n_buses: usize, n_lines: usize, n_ncs: usize, n_stages: usize, hydro_default: HydroStagePenalties, bus_default: BusStagePenalties, line_default: LineStagePenalties, ncs_default: NcsStagePenalties, ) -> Self

Allocate a new resolved-penalties table filled with the given defaults.

n_stages must be > 0. Entity counts may be 0 (empty vectors are valid).

§Arguments
  • n_hydros — number of hydro plants
  • n_buses — number of buses
  • n_lines — number of transmission lines
  • n_ncs — number of non-controllable sources
  • n_stages — number of study stages
  • hydro_default — initial value for all (hydro, stage) cells
  • bus_default — initial value for all (bus, stage) cells
  • line_default — initial value for all (line, stage) cells
  • ncs_default — initial value for all (ncs, stage) cells
Source

pub fn hydro_penalties( &self, hydro_index: usize, stage_index: usize, ) -> HydroStagePenalties

Return the resolved penalties for a hydro plant at a specific stage.

Source

pub fn bus_penalties( &self, bus_index: usize, stage_index: usize, ) -> BusStagePenalties

Return the resolved penalties for a bus at a specific stage.

Source

pub fn line_penalties( &self, line_index: usize, stage_index: usize, ) -> LineStagePenalties

Return the resolved penalties for a line at a specific stage.

Source

pub fn ncs_penalties( &self, ncs_index: usize, stage_index: usize, ) -> NcsStagePenalties

Return the resolved penalties for a non-controllable source at a specific stage.

Source

pub fn hydro_penalties_mut( &mut self, hydro_index: usize, stage_index: usize, ) -> &mut HydroStagePenalties

Return a mutable reference to the hydro penalty cell for in-place update.

Used by cobre-io during penalty cascade resolution to set resolved values.

Source

pub fn bus_penalties_mut( &mut self, bus_index: usize, stage_index: usize, ) -> &mut BusStagePenalties

Return a mutable reference to the bus penalty cell for in-place update.

Source

pub fn line_penalties_mut( &mut self, line_index: usize, stage_index: usize, ) -> &mut LineStagePenalties

Return a mutable reference to the line penalty cell for in-place update.

Source

pub fn ncs_penalties_mut( &mut self, ncs_index: usize, stage_index: usize, ) -> &mut NcsStagePenalties

Return a mutable reference to the NCS penalty cell for in-place update.

Source

pub fn n_stages(&self) -> usize

Return the number of stages in this table.

Trait Implementations§

Source§

impl Clone for ResolvedPenalties

Source§

fn clone(&self) -> ResolvedPenalties

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ResolvedPenalties

Source§

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

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

impl PartialEq for ResolvedPenalties

Source§

fn eq(&self, other: &ResolvedPenalties) -> 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 ResolvedPenalties

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.