rustworkx.generators.path_graph#

path_graph(num_nodes=None, weights=None, multigraph=True)#

Generate an undirected path graph

Parameters:
  • num_nodes (int) – The number of nodes to generate the graph with. Node weights will be None if this is specified. If both num_nodes and weights are set this will be ignored and weights will be used.

  • weights (list) – A list of node weights, the first element in the list will be the center node of the path graph. If both num_nodes and weights are set this will be ignored and weights will be used.

  • 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 path graph

Return type:

PyGraph

Raises:

IndexError – If neither num_nodes or weights are specified

import rustworkx.generators
from rustworkx.visualization import mpl_draw

graph = rustworkx.generators.path_graph(10)
mpl_draw(graph)
../_images/rustworkx.generators.path_graph_0_0.png