bfs_3.py 495 B

12345678910111213141516
  1. def DrawGraph(G):
  2. pos = nx.spring_layout(G)
  3. nx.draw(G, pos, with_labels = True) #with_labels=true is to show the node number in the output graph
  4. edge_labels = dict([((u,v,), d['length']) for u, v, d in G.edges(data = True)])
  5. nx.draw_networkx_edge_labels(G, pos, edge_labels = edge_labels, label_pos = 0.3, font_size = 11) #prints weight on all the edges
  6. return pos
  7. #main function
  8. if __name__== "__main__":
  9. G,source = CreateGraph()
  10. pos = DrawGraph(G)
  11. BFS(G, source, pos)
  12. plt.show()