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
impl ResolvedGenericConstraintBounds
Sourcepub fn empty() -> Self
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());Sourcepub fn new<I>(constraint_id_to_idx: &HashMap<i32, usize>, raw_bounds: I) -> Self
pub fn new<I>(constraint_id_to_idx: &HashMap<i32, usize>, raw_bounds: I) -> Self
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 domainconstraint_idto positional indexraw_bounds— sorted rows fromconstraints/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));Sourcepub fn is_active(&self, constraint_idx: usize, stage_id: i32) -> bool
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));Sourcepub fn bounds_for_stage(
&self,
constraint_idx: usize,
stage_id: i32,
) -> &[(Option<i32>, f64)]
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
impl Clone for ResolvedGenericConstraintBounds
Source§fn clone(&self) -> ResolvedGenericConstraintBounds
fn clone(&self) -> ResolvedGenericConstraintBounds
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl PartialEq for ResolvedGenericConstraintBounds
impl PartialEq for ResolvedGenericConstraintBounds
Source§fn eq(&self, other: &ResolvedGenericConstraintBounds) -> bool
fn eq(&self, other: &ResolvedGenericConstraintBounds) -> bool
self and other values to be equal, and is used by ==.