필터 지우기
필터 지우기

How to find maximum eccentricity of a vertex of non-directed graph?

조회 수: 4 (최근 30일)
How to find maximum eccentricity of a vertex of non-directed graph?
  댓글 수: 7
Bruno Luong
Bruno Luong 2018년 10월 2일
편집: Bruno Luong 2018년 10월 2일
Did you check out FEX for shortest path algorithms? There are a bunch of them. Not sure if you need Floyd–Warshall algorithm or loop on Dijkstra for the all edges containing the considered vertex.
Anjani Chaudhary
Anjani Chaudhary 2018년 10월 3일
편집: Walter Roberson 2018년 10월 3일
I have a graph like this.
s = [1 1 1 2 2 2 2 3 3 3 4 4 4 5 5 5 5 6 6 6 7 7 7 7 8 8 8 8 9 9 10 10 11 11 12 12 12 12 13 13 13 14 14 14 15 15];
t = [3 8 15 3 7 8 13 1 2 11 8 10 15 7 8 10 12 7 14 13 2 5 6 12 1 2 4 5 12 14 4 5 3 13 5 7 9 14 2 6 11 6 9 12 1 4];
G = digraph(s,t)
A = adjacency(G)
TR = shortestpathtree(G,1);
p = plot(G);
A = adjacency(G)
highlight(p,TR,'EdgeColor','r')
Here I need to find eccentricity of each node and diameter of the graph. And at end check which node eccentricity is equal as the graph diameter.

댓글을 달려면 로그인하십시오.

채택된 답변

Walter Roberson
Walter Roberson 2018년 10월 3일
%need a graph
s = [1 1 2 3 3 4 4 6 6 7 8 7 5];
t = [2 3 4 4 5 5 6 1 8 1 3 2 8];
G = digraph(s,t);
%now process it
allnodes = unique(G.Edges.EndNodes);
numnodes = length(allnodes);
eccentricities = zeros(1, numnodes);
for N = 1 : numnodes
thisnode = allnodes(N);
[~, D] = shortestpathtree(G,thisnode);
eccentricities(N) = max(D);
end
graph_diameter = max(eccentricities);
  댓글 수: 7
Walter Roberson
Walter Roberson 2020년 10월 7일
s = [1 1 2 3 3 4 4 6 6 7 8 7 5];
t = [2 3 4 4 5 5 6 1 8 1 3 2 8];
G = digraph(s,t);
plot(G)

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Graph and Network Algorithms에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by