function B = floyd ( A )

%*****************************************************************************80
%
%% floyd() computes the shortest distance between all pairs of points.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    05 March 2022
%
%  Author:
%
%    John Burkardt
%
%  Reference:
%
%    Robert Floyd,
%    Algorithm 97, Shortest Path,
%    Communications of the ACM,
%    Volume 5, Number 6, June 1962, page 345.
%
%  Input:
%
%    real A(N,N): the length of the direct link between 
%    nodes I and J, or Inf if there is no direct link.
%
%  Output:
%
%    real B(N,N): the distance between nodes I and J.
%
  B = A;
  n = size ( A, 1 );

  for k = 1 : n
    for i = 1 : n
      for j = 1 : n
        B(i,j) = min ( B(i,j), B(i,k) + B(k,j) );
      end
    end
  end

  return
end
