pub struct ResolvedGenericConstraintBounds { /* private fields */ }Expand description
Pre-resolved RHS bound table for user-defined generic linear constraints.
Sparse (constraint_index, stage_id) index with O(1) lookup. Absent pairs
report is_active false and bounds_for_stage empty — no panic.
§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.
The default value in System when no generic constraints
are loaded; all queries 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 constraint_id: i32 to positional index;
rows with an absent constraint_id are silently skipped (caught upstream by
referential validation). raw_bounds must be sorted by (constraint_id, stage_id, block_id) ascending — the grouping into contiguous ranges relies on it.
§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_lower = 500.0,
// bound_upper = None.
let rows = vec![(10i32, 3i32, None::<i32>, Some(500.0f64), None::<f64>)];
let table = ResolvedGenericConstraintBounds::new(
&id_map,
rows.iter().map(|(cid, sid, bid, bl, bu)| (*cid, *sid, *bid, *bl, *bu)),
);
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].block_id, None);
assert_eq!(slice[0].bound_lower, Some(500.0));
assert_eq!(slice[0].bound_upper, None);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,
) -> &[GenericConstraintBoundEntry]
pub fn bounds_for_stage( &self, constraint_idx: usize, stage_id: i32, ) -> &[GenericConstraintBoundEntry]
Return the bound entries 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 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more