forked from skyrahul/DTA2020
-
Notifications
You must be signed in to change notification settings - Fork 0
/
generateGraph.py
31 lines (30 loc) · 1.39 KB
/
generateGraph.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
from imports import *
from initialize import *
from start_simulation import start_simulation
''' -------------------------------------------------------------------------------
-------------------FUNCTION TO GENERATE GRAPH BASED ON INPUT DATA------------------
-----------------------------------------------------------------------------------'''
#GUI related
def generate_graph(param,count):
global node_count,edge_count
G = nx.Graph()
graph_edges = []
node = [i+1 for i in range(node_count)]
start, end, length, width, density = zip(*param)
for i in range(edge_count):
graph_edges.append([int(start[i].get()),int(end[i].get())])
G.add_nodes_from(node)
G.add_edges_from(graph_edges)
edge_label = defaultdict(int)
node_label = defaultdict(int)
for i in range(len(graph_edges)):
edge_label[tuple(graph_edges[i])] = i+1
for i in range(len(node)):
node_label[i+1] = i+1
pos = nx.random_layout(G)
nx.draw_networkx_nodes(G,pos,nodelist = node)
nx.draw_networkx_edges(G,pos,edgelist= graph_edges,edge_color='r')
nx.draw_networkx_labels(G,pos,labels = node_label,font_size=16)
nx.draw_networkx_edge_labels(G,pos,edge_labels= edge_label)
Button(root, text='Start Simulation', fg='blue', bg='white', font=("Times New Roman", 20, "bold"),command= start_simulation).grid(row= max(count + 2,17), column=1, pady='20')
plt.show()