Advertisement
makispaiktis

Greedy Algorithms - Visualize network 3

May 29th, 2020 (edited)
759
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.59 KB | None | 0 0
  1. from heapq import heappush
  2. from heapq import heappop
  3. # Heappop returns the element of the heap with the minimum value
  4.  
  5.  
  6. def prim(edges):
  7.     return 1
  8.  
  9. def visualize(edges):
  10.     from pyvis.network import Network
  11.     G = Network()
  12.     for u, v, weight in edges:
  13.         G.add_node(u)
  14.         G.add_node(v)
  15.         G.add_edge(u, v, label=str(weight))
  16.     G.show("network.html")
  17.  
  18.  
  19. edges = [('A', 'B', 2), ('A', 'C', 3), ('A', 'D', 3), ('B', 'C', 4),
  20.       ('B', 'E', 3), ('C', 'D', 5), ('C', 'E', 1), ('C', 'F', 6),
  21.       ('D', 'F', 7), ('E', 'F', 8), ('F', 'G', 9)]
  22. visualize(edges)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement