Skip to main content

ResolvedGenericConstraintBounds

Struct ResolvedGenericConstraintBounds 

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

Pre-resolved RHS bound table for user-defined generic linear constraints.

Indexed by (constraint_index, stage_id) using a sparse HashMap. Provides O(1) lookup of the active bounds for LP row construction.

Entries are stored in a flat Vec<(Option<i32>, f64)> of (block_id, bound) pairs. Each (constraint_index, stage_id) key maps to a contiguous Range<usize> slice within that flat vec.

When no bounds exist for a (constraint_index, stage_id) pair, is_active returns false and bounds_for_stage returns an empty slice — there is no panic or error.

§Construction

Use ResolvedGenericConstraintBounds::empty as the default (no generic constraints), or ResolvedGenericConstraintBounds::new to build from parsed bound rows. cobre-io is responsible for populating the table.

§Examples

use cobre_core::ResolvedGenericConstraintBounds;

let empty = ResolvedGenericConstraintBounds::empty();
assert!(!empty.is_active(0, 0));
assert!(empty.bounds_for_stage(0, 0).is_empty());

Implementations§

Source§

impl ResolvedGenericConstraintBounds

Source

pub fn empty() -> Self

Return an empty table with no constraints and no bounds.

Used as the default value in System when no generic constraints are loaded. All queries on the empty table return false / empty slices.

§Examples
use cobre_core::ResolvedGenericConstraintBounds;

let t = ResolvedGenericConstraintBounds::empty();
assert!(!t.is_active(0, 0));
assert!(t.bounds_for_stage(99, 5).is_empty());
Source

pub fn new<I>(constraint_id_to_idx: &HashMap<i32, usize>, raw_bounds: I) -> Self
where I: Iterator<Item = (i32, i32, Option<i32>, f64)>,

Build a resolved table from sorted bound rows.

constraint_id_to_idx maps domain-level constraint_id: i32 values to positional indices in the constraint collection. Rows whose constraint_id is not present in that map are silently skipped (they would have been caught by referential validation upstream).

raw_bounds must be sorted by (constraint_id, stage_id, block_id) ascending (the ordering produced by parse_generic_constraint_bounds).

§Arguments
  • constraint_id_to_idx — maps domain constraint_id to positional index
  • raw_bounds — sorted rows from constraints/generic_constraint_bounds.parquet
§Examples
use std::collections::HashMap;
use cobre_core::ResolvedGenericConstraintBounds;

// Two constraints with IDs 10 and 20, mapped to positions 0 and 1.
let id_map: HashMap<i32, usize> = [(10, 0), (20, 1)].into_iter().collect();

// One bound row: constraint 10 at stage 3, block_id = None, bound = 500.0.
let rows = vec![(10i32, 3i32, None::<i32>, 500.0f64)];

let table = ResolvedGenericConstraintBounds::new(
    &id_map,
    rows.iter().map(|(cid, sid, bid, b)| (*cid, *sid, *bid, *b)),
);

assert!(table.is_active(0, 3));
assert!(!table.is_active(1, 3));

let slice = table.bounds_for_stage(0, 3);
assert_eq!(slice.len(), 1);
assert_eq!(slice[0], (None, 500.0));
Source

pub fn is_active(&self, constraint_idx: usize, stage_id: i32) -> bool

Return true if at least one bound entry exists for this constraint at the given stage.

Returns false for any unknown (constraint_idx, stage_id) pair.

§Examples
use cobre_core::ResolvedGenericConstraintBounds;

let empty = ResolvedGenericConstraintBounds::empty();
assert!(!empty.is_active(0, 0));
Source

pub fn bounds_for_stage( &self, constraint_idx: usize, stage_id: i32, ) -> &[(Option<i32>, f64)]

Return the (block_id, bound) pairs for a constraint at the given stage.

Returns an empty slice when no bounds exist for the (constraint_idx, stage_id) pair.

§Examples
use cobre_core::ResolvedGenericConstraintBounds;

let empty = ResolvedGenericConstraintBounds::empty();
assert!(empty.bounds_for_stage(0, 0).is_empty());

Trait Implementations§

Source§

impl Clone for ResolvedGenericConstraintBounds

Source§

fn clone(&self) -> ResolvedGenericConstraintBounds

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 ResolvedGenericConstraintBounds

Source§

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

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

impl PartialEq for ResolvedGenericConstraintBounds

Source§

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

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.