function toms097_test ( )

%*****************************************************************************80
%
%% toms097_test() tests toms097().
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    01 March 2019
%
%  Author:
%
%    John Burkardt
%
  addpath ( '../toms097' );

  timestamp ( );
  fprintf ( 1, '\n' );
  fprintf ( 1, 'toms097_test():\n' );
  fprintf ( 1, '  MATLAB/Octave version %s\n', version ( ) );
  fprintf ( 1, '  Test toms097().\n' );

  floyd_test ( );
%
%  Terminate.
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'toms097_test():\n' );
  fprintf ( 1, '  Normal end of execution.\n' );
  fprintf ( 1, '\n' );
  timestamp ( );

  rmpath ( '../toms097' );

  return
end
function floyd_test ( )

%*****************************************************************************80
%
%% floyd_test tests floyd().
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    01 March 2014
%
%  Author:
%
%    John Burkardt
%
  n = 6;

  A = [ ...
     0.0,  2.0,  5.0, -1.0, -1.0, -1.0; ...
    -1.0,  0.0,  7.0,  1.0, -1.0,  8.0; ...
    -1.0, -1.0,  0.0,  4.0, -1.0, -1.0; ...
    -1.0, -1.0, -1.0,  0.0,  3.0, -1.0; ...
    -1.0, -1.0,  2.0, -1.0,  0.0,  3.0; ...
    -1.0,  5.0, -1.0,  2.0,  4.0,  0.0 ];
 
  fprintf ( 1, '\n' );
  fprintf ( 1, 'floyd_test():\n' );
  fprintf ( 1, '  floyd() uses Floyd''s algorithm to find the\n' );
  fprintf ( 1, '  shortest distance between all pairs of nodes\n' );
  fprintf ( 1, '  in a directed graph, starting from the initial array\n' );
  fprintf ( 1, '  of direct node-to-node distances.\n' );

  fprintf ( 1, '\n' );
  fprintf ( 1, '  In the initial direct distance array, if\n' );
  fprintf ( 1, '    A(I,J) = -1,\n' );
  fprintf ( 1, '  this indicates there is NO directed link from\n' );
  fprintf ( 1, '  node I to node J.  In that case, the value of\n' );
  fprintf ( 1, '  of A(I,J) is essentially "infinity".\n' );

  fprintf ( 1, '\n' );
  fprintf ( 1, '  Initial direct-link distance matrix:\n' );
  fprintf ( 1, '\n' );
  disp ( A )

  for j = 1 : n
    for i = 1 : n
      if ( A(i,j) == -1.0 )
        A(i,j) = Inf;
      end
    end
  end 

  B = floyd ( A );

  for j = 1 : n
    for i = 1 : n
      if ( B(i,j) == Inf )
        B(i,j) = -1.0;
      end
    end
  end

  fprintf ( 1, '\n' );
  fprintf ( 1, '  In the final shortest distance array, if\n' );
  fprintf ( 1, '    B(I,J) = -1,\n' );
  fprintf ( 1, '  this indicates there is NO directed path from\n' );
  fprintf ( 1, '  node I to node J.\n' );

  fprintf ( 1, '\n' );
  fprintf ( 1, '  Final distance matrix:\n' );
  fprintf ( 1, '\n' );
  disp ( B )

  return
end
function timestamp ( )

%*****************************************************************************80
%
%% timestamp() prints the current YMDHMS date as a timestamp.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    14 February 2003
%
%  Author:
%
%    John Burkardt
%
  t = now;
  c = datevec ( t );
  s = datestr ( c, 0 );
  fprintf ( 1, '%s\n', s );

  return
end

