pub fn petersen_graph<G, T, F, H, M>(
n: usize,
k: usize,
default_node_weight: F,
default_edge_weight: H,
) -> Result<G, InvalidInputError>Expand description
Generate a generalized Petersen graph G(n, k) with 2n
nodes and 3n edges.
The Petersen graph itself is denoted G(5, 2)
n- Number of nodes in the internal star and external regular polygon. n > 2.k- Shift that changes the internal star graph. k > 0 and 2 * k < n.default_node_weight- A callable that will return the weight to use for newly created nodes. This is ignored ifweightsis specified.default_edge_weight- A callable that will return the weight object to use for newly created edges.bidirectional- Whether edges are added bidirectionally. If set totruethen for any edge(u, v)an edge(v, u)will also be added. If the graph is undirected this will result in a parallel edge.
ยงExample
use rustworkx_core::petgraph;
use rustworkx_core::generators::petersen_graph;
use rustworkx_core::petgraph::visit::EdgeRef;
let expected_edge_list = vec![
(0, 2),
(1, 3),
(2, 4),
(3, 0),
(4, 1),
(5, 6),
(6, 7),
(7, 8),
(8, 9),
(9, 5),
(5, 0),
(6, 1),
(7, 2),
(8, 3),
(9, 4),
];
let g: petgraph::graph::UnGraph<(), ()> = petersen_graph(
5,
2,
|| {()},
|| {()},
).unwrap();
assert_eq!(
expected_edge_list,
g.edge_references()
.map(|edge| (edge.source().index(), edge.target().index()))
.collect::<Vec<(usize, usize)>>(),
)