Skip to main content

rewire_directed_edges

Function rewire_directed_edges 

Source
pub fn rewire_directed_edges(
    graph: &Graph,
    prob: f64,
    loops: bool,
    mode: RewireDirectedMode,
    seed: u64,
) -> IgraphResult<Graph>
Expand description

Rewires one endpoint of directed edges with constant probability.

For directed graphs, rewires either the source or target of each edge independently with probability prob. This preserves the in-degree sequence (when rewiring targets, i.e. Out mode) or the out-degree sequence (when rewiring sources, i.e. In mode).

For undirected graphs, falls back to rewire_edges which rewires both endpoints.

§Arguments

  • graph — the input graph.
  • prob — rewiring probability in [0.0, 1.0].
  • loops — if true, rewired edges may form self-loops.
  • mode — which endpoint to rewire (Out = target, In = source).
  • seed — random seed for deterministic output.

§Examples

use rust_igraph::{Graph, rewire_directed_edges, RewireDirectedMode};

let mut g = Graph::new(5, true).unwrap();
g.add_edge(0, 1).unwrap();
g.add_edge(1, 2).unwrap();
g.add_edge(2, 3).unwrap();

let rg = rewire_directed_edges(&g, 0.5, false, RewireDirectedMode::Out, 42).unwrap();
assert_eq!(rg.vcount(), 5);
assert_eq!(rg.ecount(), 3);
assert!(rg.is_directed());