function surf_graph ( n, a )

%*****************************************************************************80
%
%% SURF_GRAPH uses the "random surfer" method for node rankings of a digraph.
%
%  Licensing:
%
%    This code is distributed under the GNU LGPL license.
%
%  Modified:
%
%    04 September 2015
%
%  Author:
%
%    John Burkardt
%
%  Parameters:
%
%    Input, integer N, the number of nodes.
%
%    Input, integer A(N,N), the adjacency matrix.
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'SURF_GRAPH:\n' );
  fprintf ( 1, '  Given an NxN adjacency 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' );

  v(1:n) = 0;
%
%  Get the Google version of the transition matrix.
%
  t = adj_to_google ( n, a );
%
%  Choose a random starting position.
%
  j = randi ( n, 1, 1 );
%
%  Carry out many moves.
%
  n_test = 100000;

  for k = 1 : n_test

    p1 = rand ( );
    t1 = 0.15;

    if ( p1 <= t1 )

      j = randi ( n, 1, 1 );

    else

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

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

  end
%
%  Normalize the counts.
%
  v = v / n_test;

  fprintf ( 1, '\n' );
  r8vec_transpose_print ( n, v, '  Node weights:' );

  return
end
