rustworkx.generators.barbell_graph#
- barbell_graph(num_mesh_nodes=None, num_path_nodes=None, multigraph=True, mesh_weights=None, path_weights=None)#
Generate an undirected barbell graph where two identical complete graphs are connected by a path.
If
num_path_nodes(described below) is not specified then this is equivalent to two complete graphs joined together.- Parameters:
num_mesh_nodes (int) – The number of nodes to generate the mesh graphs with. Node weights will be None if this is specified. If both
num_mesh_nodesandmesh_weightsare set, this will be ignored andmesh_weightswill 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_nodesandpath_weightsare set, this will be ignored andpath_weightswill be used.multigraph (bool) – When set to
False, the outputPyGraphobject 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.mesh_weights (Sequence[Any]) – A sequence of node weights for the path, typically a list. If both
num_mesh_nodesandmesh_weightsare set,num_mesh_nodeswill be ignored andmesh_weightswill be used.path_weights (Sequence[Any]) – A sequence of node weights for the path, typically a list. If both
num_path_nodesandpath_weightsare set,num_path_nodeswill be ignored andpath_weightswill be used.
- Returns:
The generated barbell graph
- Return type:
- Raises:
IndexError – If
num_mesh_nodesis not specified
import rustworkx.generators from rustworkx.visualization import mpl_draw graph = rustworkx.generators.barbell_graph(4, 2) mpl_draw(graph)