# if not has link between i, j or has short one for j in range(1, number): if not final[j] and min + \ graph.get_arc(k, j, 255) < short_path_weight[j]: short_path_weight[j] = min + graph.get_arc(k, j) short_vertexs[j] = k print(short_vertexs) print(short_path_weight) if __name__ == '__main__': from adjacency_matrix import AdjacencyMatrix test = AdjacencyMatrix(False, 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I') test.insert_arc('A', 'B', 1) test.insert_arc('A', 'C', 5) test.insert_arc('B', 'C', 3) test.insert_arc('B', 'D', 7) test.insert_arc('B', 'E', 5) test.insert_arc('C', 'E', 1) test.insert_arc('C', 'F', 7) test.insert_arc('D', 'G', 3) test.insert_arc('D', 'E', 2) test.insert_arc('E', 'F', 3) test.insert_arc('E', 'G', 6) test.insert_arc('E', 'H', 9) test.insert_arc('F', 'H', 5) test.insert_arc('G', 'H', 2) test.insert_arc('G', 'I', 7) test.insert_arc('H', 'I', 4)
print(graph.get_vertex_value(i)) for j in range(graph.get_number()): if graph.has_arc(i, j) and not vertex_visited[j]: depth_first_search(graph, j) def depth_first_search_traverse(graph): global vertex_visited for i in range(graph.get_number()): if not vertex_visited[i]: depth_first_search(graph, i) test = AdjacencyMatrix(False, 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I') test.insert_arc('A', 'B', 1) test.insert_arc('A', 'F', 1) test.insert_arc('B', 'G', 1) test.insert_arc('F', 'G', 1) test.insert_arc('E', 'F', 1) test.insert_arc('E', 'H', 1) test.insert_arc('D', 'E', 1) test.insert_arc('D', 'H', 1) test.insert_arc('G', 'H', 1) test.insert_arc('D', 'G', 1) test.insert_arc('D', 'I', 1) test.insert_arc('C', 'D', 1) test.insert_arc('C', 'I', 1) test.insert_arc('B', 'C', 1) test.insert_arc('B', 'I', 1)
while j < number: if lowcast[j] != 0 and lowcast[j] < min: min = lowcast[j] k = j j += 1 print(adjvex[k], k) lowcast[k] = 0 for j in range(1, number): if lowcast[j] != 0 and graph.get_arc(k, j, MAX) < lowcast[j]: lowcast[j] = graph.get_arc(k, j, MAX) adjvex[j] = k test = AdjacencyMatrix(False, 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I') test.insert_arc('A', 'B', 10) test.insert_arc('A', 'F', 11) test.insert_arc('B', 'G', 16) test.insert_arc('F', 'G', 17) test.insert_arc('E', 'F', 26) test.insert_arc('E', 'H', 7) test.insert_arc('D', 'E', 20) test.insert_arc('D', 'H', 16) test.insert_arc('G', 'H', 19) test.insert_arc('D', 'G', 24) test.insert_arc('D', 'I', 21) test.insert_arc('C', 'D', 22) test.insert_arc('C', 'I', 8) test.insert_arc('B', 'C', 18) test.insert_arc('B', 'I', 12)