Warning

This documents an unmaintained version of NetworkX. Please upgrade to a maintained version and see the current NetworkX documentation.

networkx.generators.random_graphs.connected_watts_strogatz_graph

connected_watts_strogatz_graph(n, k, p, tries=100, seed=None)[source]

Returns a connected Watts–Strogatz small-world graph.

Attempts to generate a connected graph by repeated generation of Watts–Strogatz small-world graphs. An exception is raised if the maximum number of tries is exceeded.

Parameters:
  • n (int) – The number of nodes
  • k (int) – Each node is joined with its k nearest neighbors in a ring topology.
  • p (float) – The probability of rewiring each edge
  • tries (int) – Number of attempts to generate a connected graph.
  • seed (int, optional) – The seed for random number generator.