Erdos Renyi

Create an G{n,m} random graph with n nodes and m edges and report some properties.

This graph is sometimes called the Erdős-Rényi graph but is different from G{n,p} or binomial_graph which is also sometimes called the Erdős-Rényi graph.

plot erdos renyi

Out:

node degree clustering
0 3 0.333333
1 6 0.400000
2 4 0.333333
3 5 0.400000
4 4 0.333333
5 4 0.500000
6 3 0.000000
7 5 0.300000
8 2 1.000000
9 4 0.333333
0 5 4 6
1 8 5 9 7 2 3
2 9 4 7
3 5 9 4 7
4 5
5
6 9 7
7 8
8
9

# Author: Aric Hagberg (hagberg@lanl.gov)

#    Copyright (C) 2004-2019 by
#    Aric Hagberg <hagberg@lanl.gov>
#    Dan Schult <dschult@colgate.edu>
#    Pieter Swart <swart@lanl.gov>
#    All rights reserved.
#    BSD license.

import matplotlib.pyplot as plt
from networkx import nx

n = 10  # 10 nodes
m = 20  # 20 edges

G = nx.gnm_random_graph(n, m)

# some properties
print("node degree clustering")
for v in nx.nodes(G):
    print('%s %d %f' % (v, nx.degree(G, v), nx.clustering(G, v)))

# print the adjacency list
for line in nx.generate_adjlist(G):
    print(line)

nx.draw(G)
plt.show()

Total running time of the script: ( 0 minutes 0.119 seconds)

Gallery generated by Sphinx-Gallery