Advertisement
Guest User

Untitled

a guest
Feb 21st, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.54 KB | None | 0 0
  1. #!/usr/bin/env python
  2. import heapq
  3. from sets import Set
  4. import math
  5.  
  6. def Prim(G):
  7. a = [math.inf] * len(G[0])
  8. Q = [] # priority queue
  9. for v in range(len(G[0])):
  10. heapq.heappush(Q, v)
  11. S = Set([]) # set of explored nodes S <- phi
  12.  
  13. while (Q[0] != None): # Does this seem right?
  14. u = heapq.heappop(Q)
  15. S.union(u)
  16. for v in range(len(G[0])):
  17. if u == v:
  18. continue
  19. if v not in S and G[u][v] < a[v]:
  20. decrease priority a[v] to c_e
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement