rustworkx.generators.complete_graph#

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

Generate an undirected complete graph with n nodes.

A complete graph is a simple graph in which each pair of distinct vertices is connected by a unique edge. The complete graph on n nodes is the graph with the set of nodes {0, 1, ..., n-1} and the set of edges {(i, j) : i < j, 0 <= i < n, 0 <= j < n}. The number of edges in the complete graph is n*(n-1)/2.

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. 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 complete 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.complete_graph(5)
mpl_draw(graph)
../_images/rustworkx.generators.complete_graph_0_0.png