Find lenght of shortest path from nodal incidence matrix

조회 수: 2 (최근 30일)
Marc Gebhardt
Marc Gebhardt 2018년 6월 15일
댓글: Guillaume 2018년 6월 15일
Hello, I want to find the lenght of the shortest path between two nodes out of the given nodal-terminal-incidence-matrix (nti). In the nti the number of rows equals the number of nodes and the number of columns equals the number of terminals. Every connection of two nodes is represented by a single path with two terminals. The first on the first node, second on second node. So for instance for a 4-node graph (see picture),
the nti is
KKT=[1 0 0 0 1 0 0 0;
0 1 0 0 0 0 1 0;
0 0 1 0 0 1 0 0;
0 0 0 1 0 0 0 1];
How can i calculate the adjacency-matrix from this and how can i find now the length of shortest path?
  댓글 수: 1
Guillaume
Guillaume 2018년 6월 15일
  • As far as I can tell that KKT matrix tells you nothing about connectivity. It only tells you which node belongs to which terminal.
  • Do the terminals actually matter. You could certainly store the adjacency matrix for the nodes and completely forget about the terminals.
  • Shortest path between what and what?

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

답변 (2개)

Marc Gebhardt
Marc Gebhardt 2018년 6월 15일
I have already calculated the adjacence and incidence matrix with this code, where the vectors fN and tN are from-node and to-node information:
fN1=find(nti(:,:)==1);
fN=fN1(1:2:size(fN1,1)-1);
[fN,~]=ind2sub(size(nti),fN);
tN=fN1(2:2:size(fN1,1));
[tN,~]=ind2sub(size(nti),tN);
G=graph(fN,tN);
inc=incidence(G);
adj=adjacency(G);
Now I have to find the lenght of each shortest path between two nodes.

Rostislav Teryaev
Rostislav Teryaev 2018년 6월 15일
편집: Rostislav Teryaev 2018년 6월 15일
It seems not like an incidence matrix. Incidence matrix represents nodes connections. There are can be two approaches:
1. Terminals as graph nodes
IncTerminals = [1 1 0 0 1 0 0 0
1 1 0 0 0 0 1 0
0 0 1 1 0 1 0 0
0 0 1 1 0 0 0 1
1 0 0 0 1 1 0 0
0 0 1 0 1 1 0 0
0 1 0 0 0 0 1 1
0 0 0 1 0 0 1 1]
2. Nodes as graph nodes
IncNodes = [1 1 1 0
1 1 0 1
1 0 1 1
0 1 1 1]
But I can not remember wether it possible or not to convert incinence matrix to adjacency matrix or build a graph object with it.
But it is possible to build any kind of matrix or graph object if you would set edges as a pairs of nodes (check the doc for graph function). Again two ways:
1. Terminals as graph nodes
s = [1 1 2 3 3 4 5 7]; % Vector of starting nodes
t = [2 5 7 4 6 8 6 8]; % Vector of target nodes
2. Nodes as graph nodes
s = [1 1 2 3]; % Vector of starting nodes
t = [2 3 4 4]; % Vector of target nodes
Now you can create a graph object by
G = graph(s,t);
plotting it by
plot(G)
gives
1. Terminals
2. Nodes
Then you can extract from graph object any matrix you want
Adj = adjacency(G);
or
Inc = incidence(G);
And the shortest path also
P = shortestpath(G,1,3)
  댓글 수: 1
Marc Gebhardt
Marc Gebhardt 2018년 6월 15일
Yeah, but now I got it, that with
distances(G)
you can get the wanted values.

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

카테고리

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