rustworkx.generators.generalized_petersen_graph#

generalized_petersen_graph(n, k, multigraph=True)#

Generate a generalized Petersen graph \(G(n, k)\) with \(2n\) nodes and \(3n\) edges. See Watkins [1] for more details.

Note

The Petersen graph itself is denoted \(G(5, 2)\)

Parameters:
  • n (int) – number of nodes in the internal star and external regular polygon.

  • k (int) – shift that changes the internal star graph.

  • multigraph (bool) – When set to False the output PyGraph object will not be not be a multigraph and won’t allow parallel edges to be added. Instead calls which would create a parallel edge will update the existing edge.

Returns:

The generated generalized Petersen graph.

Return type:

PyGraph

Raises:
  • IndexError – If either n or k are not valid

  • TypeError – If either n or k are not non-negative integers

import rustworkx.generators
from rustworkx.visualization import mpl_draw

# Petersen Graph is G(5, 2)
graph = rustworkx.generators.generalized_petersen_graph(5, 2)
layout = rustworkx.shell_layout(graph, nlist=[[0, 1, 2, 3, 4],[6, 7, 8, 9, 5]])
mpl_draw(graph, pos=layout)
../_images/rustworkx.generators.generalized_petersen_graph_0_0.png
# Möbius–Kantor Graph is G(8, 3)
graph = rustworkx.generators.generalized_petersen_graph(8, 3)
layout = rustworkx.shell_layout(
  graph, nlist=[[0, 1, 2, 3, 4, 5, 6, 7], [10, 11, 12, 13, 14, 15, 8, 9]]
)
mpl_draw(graph, pos=layout)
../_images/rustworkx.generators.generalized_petersen_graph_1_0.png