Commit e2ab3569 authored by UNHALE NILESH ARUN's avatar UNHALE NILESH ARUN

update filegen

parent 001cc416
......@@ -2,9 +2,14 @@ import hashlib
from numpy.random import randint
import sys
import networkx as nx
import numpy
import matplotlib.pyplot as plt
from networkx.algorithms import community
'''
Generates a file of nodes
'''
f = open("Nodes1.dat", "w")
for i in range(int(sys.argv[1])):
......@@ -13,27 +18,64 @@ for i in range(int(sys.argv[1])):
f.close()
# G = nx.Graph()
# G=nx.complete_graph(100)
# G1=nx.path_graph(100)
G2=nx.erdos_renyi_graph(int(sys.argv[1]),0.1)
# G3=nx.fast_gnp_random_graph(100,0.1)
# G4=nx.connected_caveman_graph(100,0)
# print(nx.is_connected(G2))
# print(G2.edges())
if nx.is_connected(G2):
'''
Generates a graph given degree sequence
'''
sequence = numpy.random.uniform(2,4.1,int(sys.argv[1])).round()
while 1:
sequence1 = numpy.random.random_integers(2,4,int(sys.argv[1]))
try :
G5 = nx.random_degree_sequence_graph(list(sequence1),tries=10)
break
except nx.NetworkXUnfeasible :
pass
except nx.NetworkXError:
pass
print(sorted(G5.degree()))
if nx.is_connected(G5):
print("Graph is connected")
f = open("Links1.dat", "w")
count = 0
for edge in G2.edges():
for edge in G5.edges():
# print(edge)
# print(str(edge[0])+'\t'+str(edge[1])+'\n')
f.write(str(edge[0])+'\t'+str(edge[1])+'\n')
count += 1
f.close()
print('Nodes: ',sys.argv[1],'Edges: ',count)
print('Nodes: ',sys.argv[1],'Edges: ',count)
'''
generates a file given nodes and randomly links
'''
# G2=nx.erdos_renyi_graph(int(sys.argv[1]),0.1)
#
# if nx.is_connected(G2):
# f = open("Links1.dat", "w")
# count = 0
# for edge in G2.edges():
# # print(edge)
# # print(str(edge[0])+'\t'+str(edge[1])+'\n')
# f.write(str(edge[0])+'\t'+str(edge[1])+'\n')
# count += 1
# f.close()
#
# print('Nodes: ',sys.argv[1],'Edges: ',count)
# G = nx.Graph()
# G=nx.complete_graph(100)
# G1=nx.path_graph(100)
# G3=nx.fast_gnp_random_graph(100,0.1)
# G4=nx.connected_caveman_graph(100,0)
# print(nx.is_connected(G2))
# print(G2.edges())
# nx.draw(G)
#
# from igraph import Graph
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment