# erdos_renyi.py
# Casper van Velzen, University of Amsterdam, 11030275
# generates random graphs and writes relevant statistics to a csv
# requires the networkX package to work
import networkx as nx
import csv
# number of nodes
n = 652
# chance to connect two nodes (nr of connections / max number of connectons)
p = 5841 / ((n * (n - 1)) / 2)
print(p)
nr_of_graphs = 1000
outputfile = 'er_phonoclx.csv'
data = {}
with open(outputfile, 'w', newline='') as csv_file:
writer = csv.writer(csv_file)
for i in range(nr_of_graphs):
print("Graph nr: " + str(i))
G = nx.fast_gnp_random_graph(n, p, seed=i)
print("Number of nodes (full): " + str(nx.number_of_nodes(G)))
print("Number of edges (full): " + str(nx.number_of_edges(G)))
data[i] = {}
biggest_comp = max(nx.connected_component_subgraphs(G), key=len)
nodes = nx.number_of_nodes(biggest_comp)
print("Biggest comp nodes: " + str(nodes))
data[i]["Big_comp_nodes"] = nodes
edges = nx.number_of_edges(biggest_comp)
print("Biggest comp edges: " + str(edges))
data[i]["Big_comp_edges"] = edges
apl = nx.average_shortest_path_length(biggest_comp)
print("APL: " + str(apl))
data[i]["APL"] = apl
cc = nx.average_clustering(biggest_comp)
print("CC: " + str(cc))
data[i]["CC"] = cc
print("***")
row = []
for key, value in data[i].items():
row.append(value)
writer.writerow(row)