Advertisement
makispaiktis

Greedy Alogritmhs - Visualize a network 2

May 27th, 2020 (edited)
1,197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.65 KB | None | 0 0
  1. # Visualization
  2. def visualize(edges, colors):
  3.     from pyvis.network import Network
  4.     # Create a network
  5.     net = Network()
  6.     edges = [(edges[i][0], edges[i][1], edges[i][2], colors[i]) for i in range(len(edges))]
  7.  
  8.     for u, v, weight, color in edges:
  9.         net.add_node(u)
  10.         net.add_node(v)
  11.         net.add_edge(u, v, label=str(weight), color=color)
  12.         # print(u, v, weight)
  13.     net.show('network.html')
  14.  
  15.  
  16.  
  17.  
  18. # MAIN FUNCTION
  19. edges = [('A', 'B', 1),
  20.         ('B', 'C', 4),
  21.         ('B', 'D', 2),
  22.         ('C', 'D', 6),
  23.         ('A', 'D', 3)]
  24.  
  25. colors = ['red', 'blue', 'blue', 'blue', 'blue']
  26.  
  27. visualize(edges, colors)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement