Advertisement
Guest User

Untitled

a guest
Nov 26th, 2014
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.70 KB | None | 0 0
  1. def find_eulerian_tour(graph):
  2.     tour = []
  3.  
  4.     current_vertex = graph[0][0]
  5.     tour.append(current_vertex)
  6.  
  7.     while len(graph) > 0:
  8.         print(graph, current_vertex)
  9.         for edge in graph:
  10.             if current_vertex in edge:
  11.                 if edge[0] == current_vertex:
  12.                     current_vertex = edge[1]
  13.                 else:
  14.                     current_vertex = edge[0]
  15.  
  16.                 graph.remove(edge)
  17.                 tour.append(current_vertex)
  18.                 break
  19.         else:
  20.             # Edit to account for case no tour is possible
  21.             return False
  22.     return tour
  23.  
  24. graph = [(1, 2), (2, 3), (3, 1), (3, 4), (4, 3)]
  25. print(find_eulerian_tour(graph))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement