function surf_rank ( A )

%*****************************************************************************80
%
%% surf_rank uses the "random surfer" method for node rankings of a digraph.
%
%  Licensing:
%
%    This code is distributed under the GNU LGPL license.
%
%  Modified:
%
%    29 February 2020
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    integer A(N,N): the incidence matrix.
%
  steps = 100000;

  fprintf ( 1, '\n' );
  fprintf ( 1, 'surf_rank:\n' );
  fprintf ( 1, '  Given an NxN incidence matrix A,\n' );
  fprintf ( 1, '  compute the transition matrix T,\n' );
  fprintf ( 1, '  and then repeatedly visit nodes, keeping track of\n' );
  fprintf ( 1, '  how often you visited.\n' );
  fprintf ( 1, '\n' );
  fprintf ( 1, '  15 per cent of the time, simply take a random jump to a node.\n' );
  fprintf ( 1, '  The rest of the time, follow a random link from the current node.\n' );
  fprintf ( 1, '\n' );
  fprintf ( 1, '  When done, the node weight is the number of visits\n' );
  fprintf ( 1, '  normalized by the total number of visits.\n' );

  n = size ( A, 1 );

  r(1:n) = 0;
%
%  Get the transition matrix from the incidence matrix.
%
  T = inc_to_transition ( A );
%
%  Choose a random starting position.
%
  j = randi ( n, 1, 1 );
%
%  Carry out many moves.
%
  for k = 1 : steps

    p1 = rand ( );
    q1 = 0.15;

    if ( p1 <= q1 )

      j = randi ( n, 1, 1 );

    else

      p2 = rand ( );
      q2 = 0.0;
      for i = 1 : n
        q2 = q2 + T(i,j);
        if ( p2 <= q2 )
          j = i;
          break
        end
      end

    end
 
    r(j) = r(j) + 1;

  end
%
%  Normalize the counts.
%
  r = r / steps;

  fprintf ( 1, '\n' );
  r8vec_print ( n, r, '  Rankings:' );

  return
end
