Skip to main content

simplify_and_colorize

Function simplify_and_colorize 

Source
pub fn simplify_and_colorize(graph: &Graph) -> IgraphResult<SimplifyAndColorize>
Expand description

Build a vertex- and edge-colored simple graph from graph.

Self-loops are removed and counted into vertex_color; parallel edges are merged and their multiplicity recorded in edge_color. The result graph keeps the input’s vertex count (isolated vertices survive) and directedness.

On undirected graphs an edge given as (u, v) and one given as (v, u) denote the same edge and are merged; on directed graphs they are distinct arcs and are kept separate.

§Errors

Returns IgraphError::Internal only if a colour count or an edge id would overflow (not reachable for graphs that fit in memory), and propagates any error from rebuilding the result graph.

§Examples

use rust_igraph::{Graph, simplify_and_colorize};

// Undirected: two parallel 0-1 edges and one self-loop on vertex 1.
let mut g = Graph::new(2, false).unwrap();
g.add_edge(0, 1).unwrap();
g.add_edge(0, 1).unwrap();
g.add_edge(1, 1).unwrap();
let r = simplify_and_colorize(&g).unwrap();
assert_eq!(r.graph.ecount(), 1);
assert_eq!(r.vertex_color, vec![0, 1]); // one self-loop on vertex 1
assert_eq!(r.edge_color, vec![2]);      // edge 0-1 merged from 2 copies