Example #1
0
def warshall(matrix, not_connected_value=-1):
    """ The Implementation of the Warshall Algorithmus
    """
    check_type(matrix)
    check_shape(matrix)
    dim = matrix.shape[0]
    hull = matrix.copy()
    np.place(hull, hull == not_connected_value, float('inf'))
    for k in range(dim):
        for i in range(dim):
            if hull[i, k] == 1:
                for j in range(dim):
                    if hull[k, j] == 1:
                        hull[i, j] = 1
    np.place(hull, hull == float('inf'), not_connected_value)
    return hull
Example #2
0
def floyd(matrix, not_connected_value=-1):
    """ Floyd Algorithm
    """
    check_type(matrix)
    check_shape(matrix)
    dim = matrix.shape[0]
    dist = matrix.copy()
    np.place(dist, dist == not_connected_value, float('inf'))
    for k in range(dim):
        for i in range(dim):
            for j in range(dim):
                if j == i:
                    continue
                if dist[i, j] > dist[i, k] + dist[k, j]:
                    dist[i, j] = dist[i, k] + dist[k, j]
    np.place(dist, dist == float('inf'), not_connected_value)
    return dist