pub fn site_percolation(
graph: &Graph,
vertex_order: &[VertexId],
) -> IgraphResult<SitePercolation>Expand description
Site percolation: the size of the largest component as vertices
(sites) of graph are activated in the order specified by
vertex_order.
Each activation step:
- Mark the vertex active.
- For every neighbor that is already active, add the connecting edge and union the two trees.
- Record
giant_sizeandedge_countafter the step.
vertex_order must contain valid ids (< graph.vcount()) and
must not repeat — duplicates return
IgraphError::InvalidArgument; out-of-range ids return
IgraphError::VertexOutOfRange. The order may be a strict
subset of all vertices (skip = “never activated”).
Edge direction is ignored (matches upstream — percolation is
purely a connectivity model). Parallel edges count separately;
self-loops on the just-activated vertex contribute two to
edge_count (the loop appears twice in the all-neighbor walk
for IGRAPH_LOOPS semantics).
To shuffle into a random order, generate the permutation with your own RNG. We don’t take an RNG to keep the API deterministic and dependency-free.
Counterpart of igraph_site_percolation from
references/igraph/src/connectivity/percolation.c:328.
§Examples
use rust_igraph::{Graph, site_percolation};
// Path 0-1-2-3, activate vertices in id order.
let mut g = Graph::with_vertices(4);
g.add_edges(vec![(0u32, 1u32), (1, 2), (2, 3)]).unwrap();
let p = site_percolation(&g, &[0, 1, 2, 3]).unwrap();
// Activating 0: no edges added (no active neighbors), giant = 1.
// Activating 1: edge (0,1) activates, giant = 2.
// Activating 2: edge (1,2) activates, giant = 3.
// Activating 3: edge (2,3) activates, giant = 4.
assert_eq!(p.giant_size, vec![1, 2, 3, 4]);
assert_eq!(p.edge_count, vec![0, 1, 2, 3]);