pub struct ConstraintGraph { /* private fields */ }Expand description
Constraint dependency graph.
Models which constraints share variables. This enables:
- Graph coloring to find independent constraint sets
- Parallel propagation within independent sets
- Efficient incremental solving after small changes
Implementations§
Source§impl ConstraintGraph
impl ConstraintGraph
Sourcepub fn new(num_vars: usize) -> Self
pub fn new(num_vars: usize) -> Self
Create a new empty constraint graph over num_vars variables.
Sourcepub fn num_constraints(&self) -> usize
pub fn num_constraints(&self) -> usize
Number of constraints in the graph.
Sourcepub fn add_constraint(
&mut self,
constraint: Box<dyn FastConstraint>,
var_indices: Vec<usize>,
)
pub fn add_constraint( &mut self, constraint: Box<dyn FastConstraint>, var_indices: Vec<usize>, )
Add a constraint that touches the given variable indices.
The adjacency list is updated so that this constraint becomes adjacent to all existing constraints that share at least one variable index.
Sourcepub fn independent_sets(&self) -> Vec<Vec<usize>>
pub fn independent_sets(&self) -> Vec<Vec<usize>>
Greedy graph coloring — returns independent sets (constraints with same color).
Uses Welsh-Powell ordering (decreasing degree) for better coloring quality. Constraints in the same independent set can be checked/projected in parallel.
§Returns
A Vec<Vec<usize>> where each inner Vec is a set of constraint indices
that are mutually non-adjacent (i.e., share no variables).
Sourcepub fn propagate_parallel(&self, x: &mut Array1<f32>) -> PropagationResult
pub fn propagate_parallel(&self, x: &mut Array1<f32>) -> PropagationResult
Parallel constraint propagation.
Projects x using constraints in independent-set order.
Within each independent set, constraints are applied in parallel via rayon
(each one operates on disjoint variable subsets, so there are no races).
Falls back to sequential application when variable sets overlap within a color (the graph coloring guarantees no overlap for correctly registered constraints).
Auto Trait Implementations§
impl Freeze for ConstraintGraph
impl !RefUnwindSafe for ConstraintGraph
impl Send for ConstraintGraph
impl Sync for ConstraintGraph
impl Unpin for ConstraintGraph
impl UnsafeUnpin for ConstraintGraph
impl !UnwindSafe for ConstraintGraph
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more