pub fn permute_vertices(
graph: &Graph,
permutation: &[VertexId],
) -> IgraphResult<Graph>Expand description
Creates a new graph with vertices permuted according to the given mapping.
permutation[i] specifies which old vertex becomes new vertex i.
In other words, new vertex i gets all edges that old vertex
permutation[i] had, with endpoints remapped accordingly.
The permutation must be a valid bijection on [0, n).
§Arguments
graph— the input graph.permutation— slice of lengthnwherepermutation[new] = old.
§Errors
Returns InvalidArgument if:
permutation.len() != graph.vcount()- Any value is out of range
[0, n) - Any value appears more than once (not a valid permutation)
§Examples
use rust_igraph::{Graph, permute_vertices};
let mut g = Graph::with_vertices(3);
g.add_edge(0, 1).unwrap();
g.add_edge(1, 2).unwrap();
// Reverse the vertex ordering: new 0 = old 2, new 1 = old 1, new 2 = old 0
let perm = [2, 1, 0];
let pg = permute_vertices(&g, &perm).unwrap();
assert_eq!(pg.vcount(), 3);
assert_eq!(pg.ecount(), 2);