我创建了一个Erdős随机图,其格式为n×n对称矩阵,属性为稀疏。我正在尝试使用以下代码计算平均路径长度:
% Compute average path length for a network - the average shortest path
% INPUTS: adjL - matrix of weights/distances between nodes
% OUTPUTS: average path length: the average of the shortest paths between every two edges
% Note: works for directed/undirected networks
% GB, December 8, 2005
function l = ave_path_length(adj)
n=size(adj,1);
dij = [];
for i=1:n; dij=[dij; simple_dijkstra(adj,i) ]; end
l = sum(sum(dij))/(n^2-n); % sum and average across everything but the diagonal
它在以下链接中使用Dijkstra算法: http://strategic.mit.edu/docs/matlab_networks/simple_dijkstra.m
然而,Matlab变得很忙,我没有得到结果。任何提示都表示赞赏。