Note

This is the documentation for the current state of the development branch of rustworkx. The documentation or APIs here can change prior to being released.

rustworkx.generators.lollipop_graph#

lollipop_graph(num_mesh_nodes=None, num_path_nodes=None, mesh_weights=None, path_weights=None, multigraph=True)#

Generate an undirected lollipop graph where a mesh (complete) graph is connected to a path.

If neither num_path_nodes nor path_weights (both described below) are specified then this is equivalent to complete_graph()

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

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

  • mesh_weights (list) – A list of node weights for the mesh graph. If both num_mesh_nodes and mesh_weights are set num_mesh_nodes will be ignored and mesh_weights will be used.

  • path_weights (list) – A list of node weights for the path. If both num_path_nodes and path_weights are set num_path_nodes will be ignored and path_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 lollipop graph

Return type:

PyGraph

Raises:

IndexError – If neither num_mesh_nodes or mesh_weights are specified

import rustworkx.generators
from rustworkx.visualization import mpl_draw

graph = rustworkx.generators.lollipop_graph(4, 2)
mpl_draw(graph)
../_images/rustworkx.generators.lollipop_graph_0_0.png