kruskals_quick_union_6.py 445 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 = nx.get_edge_attributes(G, 'length')
  5. nx.draw_networkx_edge_labels(G, pos, edge_labels = edge_labels, font_size = 11) # prints weight on all the edges
  6. return pos
  7. # main function
  8. if __name__ == "__main__":
  9. G = CreateGraph()
  10. pos = DrawGraph(G)
  11. kruskals(G, pos)
  12. plt.show()