How to create a connected graph in networkx

I want to create a connected graph in IPython

laptop via NetworkX

. I used to use

erdos_renyi_graph

      

to generate a random graph, but I never get a connected graph, I want to use this graph to prove that my graph is a small world network. But the non-viscous graph of the shortest shortest graph cannot be calculated. So please tell me how to create a linked graph via NetworkX

.

+3


source to share


2 answers


As you did not specify the exact parameters of your graph, I want to suggest playing with the probability of creating edges. The following function networkx allows you to provide the probability (p) for an edge to exist on the graph.

erdos_renyi_graph(n, p, seed=None, directed=False)

      

As an example:



G = nx.erdos_renyi_graph(500, 0.5, seed=123, directed=False)

      

provides you with a fully connected schedule.

+3


source


There are many graph generators forNetworkX

, you can use not only erdos_renyi_graph

(which can be adjusted to almost the second parameter):

Social media for you:



Community Charts :

  • caveman_graph(l, k)

    - Returns the caveman graph by l

    click size k

    .
  • connected_caveman_graph(l, k)

    - Returns the linked caveman graph by n

    click size k

    .
  • relaxed_caveman_graph(l, k, p[, seed, directed])

    - Bring back a relaxed caveman schedule .
  • random_partition_graph(sizes, p_in, p_out[, ...])

    - Return a custom graph of sections with section sizes.
  • planted_partition_graph(l, k, p_in, p_out[, ...])

    - We return the planted l

    -size chart
    .
  • gaussian_random_partition_graph(n, s, v, ...)

    - Create a Gaussian graph of random splits .
  • ring_of_cliques

etc.

+2


source







All Articles