function G = digraph_adj_to_google ( A )

%*****************************************************************************80
%
%% digraph_adj_to_google() converts an adjacency matrix to a Google transition matrix.
%
%  Discussion:
%
%    If the input adjacency matrix has a node I with no connectivity,
%    (A(I,1:N) = 0) then we artificially set T(1:N,I)=1/N, so that
%    the transition matrix property of having unit column sums is preserved.
%
%    For nodes with connectivity, we assume that 85 percent of the time
%    we will take a link at random, and 15 percent of the time, we will
%    jump to an arbitrary link.  
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    12 September 2024
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    integer A(N,N): the adjacency matrix.
%
%  Output:
%
%    real G(N,N): the Google matrix.
%
  n = size ( A, 1 );
%
%  Get the row sums.
%
  s = sum ( A' );

  p = 0.15;

  G = zeros ( n, n );

  for i = 1 : n
    if ( s(i) == 0.0 )
      G(i,:) = 1.0 / n;
    else
      G(i,:) = ( 1.0 - p ) * A(i,:) / s(i) + p / n;
    end
  end

  G = G';

  return
end
