daily pastebin goal
39%
SHARE
TWEET

Untitled

a guest Dec 15th, 2018 68 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. def remove_edge(G,edge):
  3.     v = vertices(G)
  4.     G[v[edge[0]]].remove(v[edge[1]])
  5.     G[v[edge[1]]].remove(v[edge[0]])
  6.  
  7. def add_edge(G,edge):
  8.     v = vertices(G)
  9.     G[v[edge[0]]].append(v[edge[1]])
  10.     G[v[edge[1]]].append(v[edge[0]])
  11.  
  12. def get_bridges(G):
  13.     V =vertices(G)
  14.     bridges = []
  15.     my_edges = edges(G)
  16.     for edge in my_edges:
  17.         print(edge)
  18.         remove_edge(G,edge) #ERROR HERE <-------------------------------------------
  19.  
  20.         BFS(G,edge[0])
  21.         if G[V [edge[1]]].distance == INFINITY:
  22.             bridges.append(edge)
  23.         clear(G)
  24.  
  25.         add_edge(edge)
  26.  
  27.  
  28.     return bridges
  29.  
  30. def no_cycles(G):
  31.     V = vertices(G)
  32.     no_cycles = True
  33.     for s in V: #begin elke keer bij andere node
  34.         clear(G)
  35.         s.visited = True
  36.         s.predecessor = None
  37.         for v in V: # iedereen attribuut 'visited'
  38.             if v != s:
  39.                 v.visited = False
  40.                 v.predecessor = None
  41.         q = myqueue()
  42.         q.enqueue(s)
  43.         while q:
  44.             u = q.dequeue()
  45.             for v in G[u]:
  46.                 #print (u, ':', v, end=', ')
  47.                 if v != u.predecessor: # v is niet waar die van daar komt
  48.                     if not v.visited:
  49.                         v.visited = True
  50.                         v.predecessor = u
  51.                         q.enqueue(v)
  52.                     else:
  53.                         #print("FALSE", end= ' ')
  54.                         no_cycles = False
  55.  
  56.     return no_cycles
  57.  
  58. if __name__ == '__main__':
  59.     v4 = [Vertex(i) for i in range(8)]
  60.  
  61.     G4 = {v4[0]:[v4[1],v4[3]],
  62.          v4[1]:[v4[0],v4[2]],
  63.          v4[2]:[v4[1],v4[3],v4[4]],
  64.          v4[3]:[v4[0],v4[2]],
  65.          v4[4]:[v4[2],v4[5],v4[6]],
  66.          v4[5]:[v4[4],v4[6]],
  67.          v4[6]:[v4[4],v4[5],v4[7]],
  68.          v4[7]:[v4[6]]}
  69.  
  70.  
  71.     print(edges(G4))
  72.     remove_edge(G4,(7,6))
  73.     print(edges(G4))
  74.     add_edge(G4,(7,6))
  75.     print(edges(G4))
  76.     print(get_bridges(G4))
  77.  
  78.  
  79. ERROR MSG :
  80. Ik snap niet hoe, ik roep ze precies op de zelfde manier aan.
  81.  
  82.  
  83. Traceback (most recent call last):
  84.   File "C:\DATA\Study Jaar 2\Algoritmen & Datastructuren\Practicum\Week 5\Opdracht 5.3.py", line 183, in <module>
  85.     print(get_bridges(G4))
  86.   File "C:\DATA\Study Jaar 2\Algoritmen & Datastructuren\Practicum\Week 5\Opdracht 5.3.py", line 124, in get_bridges
  87.     remove_edge(G,(edge))
  88.   File "C:\DATA\Study Jaar 2\Algoritmen & Datastructuren\Practicum\Week 5\Opdracht 5.3.py", line 110, in remove_edge
  89.     G[v[edge[0]]].remove(v[edge[1]])
  90. TypeError: list indices must be integers or slices, not Vertex
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top