rustworkx.barabasi_albert_graph#

barabasi_albert_graph(n, m, seed=None, initial_graph=None)#

Generate a random graph using Barabási–Albert preferential attachment

A graph is grown to $n$ nodes by adding new nodes each with $m$ edges that are preferentially attached to existing nodes with high degree. All the edges and nodes added to this graph will have weights of None.

The algorithm performed by this function is described in:

A. L. Barabási and R. Albert “Emergence of scaling in random networks”, Science 286, pp 509-512, 1999.

Parameters:
  • n (int) – The number of nodes to extend the graph to.

  • m (int) – The number of edges to attach from a new node to existing nodes.

  • seed (int) – An optional seed to use for the random number generator.

  • initial_graph (PyGraph) – An optional initial graph to use as a starting point. star_graph() is used to create an m node star graph to use as a starting point. If specified the input graph will be modified in place.

Returns:

A PyGraph object

Return type:

PyGraph