-
Notifications
You must be signed in to change notification settings - Fork 0
/
grapher.py
52 lines (42 loc) · 1.26 KB
/
grapher.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import networkx as nx
import matplotlib.pyplot as plt
import verilog_parser
'''
in_n: input nodes;
out_n: output nodes;
nodes: gates;
edges: wire connections
'''
def grapher(in_n, out_n, nodes, edges, verbose=0):
G=nx.DiGraph()
G.add_nodes_from(in_n)
G.add_nodes_from(out_n)
G.add_nodes_from(nodes)
colour_map = []
size = []
for node in G:
if node in in_n:
colour_map.append('blue')
elif node in out_n:
colour_map.append('red')
else:
colour_map.append('green')
size.append(530*len(node))
for i in edges:
for j in i[2]:
G.add_edge(i[1], j, weight=6)
if(verbose):
import os
term_size = os.get_terminal_size()
print("\n")
[print('-', end='') for i in range(int((term_size.columns-5)/2))]
print("PATHS", end='')
[print('-', end='') for i in range(int((term_size.columns-5)/2))]
print("\n")
for i in in_n:
for j in out_n:
for path in nx.all_simple_paths(G, source=i, target=j):
print(path)
print()
nx.draw(G, with_labels=True, node_color=colour_map, node_size=size, arrowsize=20, pos=nx.spring_layout(G, k=7))
plt.show()