pub fn rewire_edges(
graph: &Graph,
prob: f64,
loops: bool,
seed: u64,
) -> IgraphResult<Graph>Expand description
Rewires graph edges with constant probability.
Each endpoint of each edge is independently rewired to a uniformly
random vertex with probability prob. The result may contain self-loops
and multi-edges depending on the loops parameter.
Uses the provided RNG seed for reproducibility.
§Arguments
graph— the input graph.prob— rewiring probability in[0.0, 1.0].loops— iftrue, rewired edges may form self-loops; otherwise, the new endpoint is guaranteed different from the other endpoint.seed— random seed for deterministic output.
§Examples
use rust_igraph::{Graph, rewire_edges};
let mut g = Graph::with_vertices(10);
for i in 0..9u32 {
g.add_edge(i, i + 1).unwrap();
}
let rg = rewire_edges(&g, 0.5, false, 42).unwrap();
assert_eq!(rg.vcount(), 10);
assert_eq!(rg.ecount(), 9);