对于弗洛伊德-华沙算法代码实现,使用如下的例子作为算法运行的例子:
添加图片注释,不超过 140 字(可选)
先使用代码并配合适当的数据结构将图中节点
vertex_list = [0, 1, 2, 3, 4, 5, 6, 7, 8] #记录图中所有节点 edge_vertex = {} #记录相连节点 edge_vertex[0] = [1] edge_vertex[1] = [7] edge_vertex[2] = [1, 5] edge_vertex[3] = [2, 4] edge_vertex[4] = [5] edge_vertex[5] = [3, 6] edge_vertex[6] = [8] edge_vertex[7] = [6, 8 ,0] edge_vertex[8] = [2] edges = np.zeros((len(vertex_list), len(vertex_list))).astype(int) #记录边的长度 for i in range(len(vertex_list)): for j in range(len(vertex_list)): edges[i][j] = sys.maxsize edges[0][1] = 4 edges[1][7] = 11 edges[7][0] = 8 edges[2][1] = 8 edges[2][5] = 4 edges[3][2] = 7 edges[3][4] = 9 edges[4][5] = 10 edges[5][3] &#