pub struct Graph {
pub n_vertices: usize,
pub edges: Vec<(usize, usize, f64)>,
}Expand description
Graph for MaxCut warm-start.
Fields§
§n_vertices: usizeNumber of vertices.
edges: Vec<(usize, usize, f64)>Weighted edge list: (u, v, weight).
Implementations§
Source§impl Graph
impl Graph
Sourcepub fn laplacian(&self) -> Array2<f64>
pub fn laplacian(&self) -> Array2<f64>
Compute the graph Laplacian L = D - A.
D is the diagonal degree matrix (weighted degrees) and A is the
weighted adjacency matrix.
Sourcepub fn fiedler_vector(&self) -> Result<Vec<f64>>
pub fn fiedler_vector(&self) -> Result<Vec<f64>>
Compute the Fiedler vector (second-smallest eigenvector of the Laplacian).
Uses inverse power iteration with a small shift λ = 0.1 to avoid the trivial zero eigenvalue, deflating the constant component at each step so the iteration converges to the Fiedler vector rather than the all-ones eigenvector.
Returns a unit vector whose entries are the vertex assignments in [-1, 1].
§Errors
Returns MLError::NumericalError if the shifted Laplacian is singular.
Sourcepub fn maxcut_value(&self, assignments: &[f64]) -> f64
pub fn maxcut_value(&self, assignments: &[f64]) -> f64
Compute the MaxCut value for the given vertex assignments.
For each edge (u, v, w), adds w * (1 − sign(a_u) * sign(a_v)) / 2 to the total.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Graph
impl RefUnwindSafe for Graph
impl Send for Graph
impl Sync for Graph
impl Unpin for Graph
impl UnsafeUnpin for Graph
impl UnwindSafe for Graph
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.