Skip to main content

graph_power

Function graph_power 

Source
pub fn graph_power(graph: &Graph, order: u32) -> IgraphResult<Graph>
Expand description

Returns the k-th power of a graph as a simple graph.

In the k-th power, vertex u is connected to vertex v if v is reachable from u within at most k steps. The result is always simple (no self-loops, no multi-edges).

By convention, the zeroth power has no edges. The first power is the simplified original graph.

§Arguments

  • graph — the input graph.
  • order — non-negative integer, the power to raise the graph to.

§Examples

use rust_igraph::{Graph, graph_power};

// Path: 0-1-2-3
let mut g = Graph::with_vertices(4);
g.add_edge(0, 1).unwrap();
g.add_edge(1, 2).unwrap();
g.add_edge(2, 3).unwrap();

let p2 = graph_power(&g, 2).unwrap();
assert_eq!(p2.vcount(), 4);
// Edges: (0,1),(0,2),(1,2),(1,3),(2,3) = 5
assert_eq!(p2.ecount(), 5);