Advertisement
makispaiktis

Greedy Alogritmhs - Visualize a network

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