BellmanFord_3.py 502 B

12345678910111213
  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. bellmanFord(G, source, pos)
  12. plt.show()