Bootstrap

floyd_warshall 代码

输入邻接矩阵(无权重,只有01),得到最短路劲矩阵

def floyd_warshall(adj_matrix):
    # Number of vertices in the graph
    n = adj_matrix.shape[0]

    # Convert adjacency matrix to float type and initialize the distance matrix
    dist_matrix = np.array(adj_matrix, dtype=float)

    # Set distance from every vertex to itself as 0
    for i in range(n):
        dist_matrix[i][i] = 0

    # Set distance for non-adjacent vertices as infinity
    for i in range(n):
        for j in range(n):
            if i != j and dist_matrix[i][j] == 0:
                dist_matrix[i][j] = float('inf')

    # Check and update shortest path using Floyd-Warshall algorithm
    for k in range(n):
        for i in range(n):
            for j in range(n):
                if dist_matrix[i][j] > dist_matrix[i][k] + dist_matrix[k][j]:
                    dist_matrix[i][j] = dist_matrix[i][k] + dist_matrix[k][j]

    return dist_matrix

悦读

道可道,非常道;名可名,非常名。 无名,天地之始,有名,万物之母。 故常无欲,以观其妙,常有欲,以观其徼。 此两者,同出而异名,同谓之玄,玄之又玄,众妙之门。

;