1234567891011121314151617 |
- def DrawGraph(G,color):
- pos = nx.spring_layout(G)
- nx.draw(G, pos, with_labels = True, edge_color = color) #with_labels=true is to show the node number in the output graph
- edge_labels = nx.get_edge_attributes(G,'length')
- nx.draw_networkx_edge_labels(G, pos, edge_labels = edge_labels, font_size = 11) #prints weight on all the edges
- return pos
- #main function
- if __name__ == "__main__":
- G = CreateGraph()
- plt.figure(1)
- pos = DrawGraph(G,'black')
- opGraph = christofedes(G, pos)
- plt.figure(2)
- pos1 = DrawGraph(opGraph,'r')
- plt.show()
|