Skip to main content

simplify

Function simplify 

Source
pub fn simplify(
    graph: &Graph,
    remove_multiple: bool,
    remove_loops: bool,
) -> IgraphResult<Graph>
Expand description

Return a copy of graph with self-loops and/or parallel edges removed.

  • remove_multiple โ€” collapse parallel edges to a single edge between each ordered pair (directed) / unordered pair (undirected).
  • remove_loops โ€” drop every self-loop edge (v, v).

If both flags are false this returns a structural clone of graph.

Edge attributes are dropped (Phase-1 minimal slice โ€” see module docs).

ยงExamples

use rust_igraph::{Graph, simplify};

// Triangle plus a self-loop and a parallel edge.
let mut g = Graph::with_vertices(3);
g.add_edge(0, 0).unwrap();
g.add_edge(0, 1).unwrap();
g.add_edge(0, 1).unwrap();
g.add_edge(1, 2).unwrap();
g.add_edge(2, 0).unwrap();

let s = simplify(&g, true, true).unwrap();
assert_eq!(s.vcount(), 3);
assert_eq!(s.ecount(), 3);