pub struct GraphPartitioner {
pub num_partitions: usize,
pub method: PartitionMethod,
pub max_iterations: usize,
}Expand description
Configures and runs graph partitioning.
Fields§
§num_partitions: usizeNumber of partitions k.
method: PartitionMethodAlgorithm selection.
max_iterations: usizeMaximum iterations (used by LabelPropagation and improvement loops).
Implementations§
Source§impl GraphPartitioner
impl GraphPartitioner
Sourcepub fn new(num_partitions: usize) -> Self
pub fn new(num_partitions: usize) -> Self
Create a partitioner with the default method (Greedy) and 20 iterations.
Sourcepub fn with_method(self, method: PartitionMethod) -> Self
pub fn with_method(self, method: PartitionMethod) -> Self
Select the partitioning method.
Sourcepub fn with_max_iterations(self, max_iter: usize) -> Self
pub fn with_max_iterations(self, max_iter: usize) -> Self
Override the maximum iteration count.
Sourcepub fn partition(
&self,
nodes: &[String],
edges: &[(String, String)],
) -> PartitionResult
pub fn partition( &self, nodes: &[String], edges: &[(String, String)], ) -> PartitionResult
Partition the graph and return a PartitionResult.
§Arguments
nodes– list of node identifiers (must be unique).edges– list of(from, to)string pairs; direction is ignored.
Sourcepub fn greedy_partition(
nodes: &[String],
edges: &[(String, String)],
k: usize,
) -> Vec<usize>
pub fn greedy_partition( nodes: &[String], edges: &[(String, String)], k: usize, ) -> Vec<usize>
Greedy round-robin assignment with a single local-improvement sweep.
Returns a per-node partition vector (indices into nodes).
Sourcepub fn label_propagation(
nodes: &[String],
edges: &[(String, String)],
k: usize,
max_iter: usize,
) -> Vec<usize>
pub fn label_propagation( nodes: &[String], edges: &[(String, String)], k: usize, max_iter: usize, ) -> Vec<usize>
Iterative label propagation.
Each node adopts the most frequent label among its neighbours.
Labels are initialised in round-robin fashion and the propagation
continues for at most max_iter rounds or until convergence.
Sourcepub fn bisection_partition(
nodes: &[String],
edges: &[(String, String)],
k: usize,
) -> Vec<usize>
pub fn bisection_partition( nodes: &[String], edges: &[(String, String)], k: usize, ) -> Vec<usize>
Recursive bisection: repeatedly split the largest partition by BFS.
Sourcepub fn count_cut_edges(assignments: &[usize], edges: &[(usize, usize)]) -> usize
pub fn count_cut_edges(assignments: &[usize], edges: &[(usize, usize)]) -> usize
Count edges whose endpoints are in different partitions.
Sourcepub fn balance_score(assignments: &[usize], k: usize) -> f64
pub fn balance_score(assignments: &[usize], k: usize) -> f64
Balance score in [0, 1]. 1.0 = perfectly balanced.
Defined as min_size / max_size where sizes are partition cardinalities.
Returns 1.0 for empty assignments or k=1.
Trait Implementations§
Source§impl Clone for GraphPartitioner
impl Clone for GraphPartitioner
Source§fn clone(&self) -> GraphPartitioner
fn clone(&self) -> GraphPartitioner
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for GraphPartitioner
impl RefUnwindSafe for GraphPartitioner
impl Send for GraphPartitioner
impl Sync for GraphPartitioner
impl Unpin for GraphPartitioner
impl UnsafeUnpin for GraphPartitioner
impl UnwindSafe for GraphPartitioner
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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