- 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?
Find lenght of shortest path from nodal incidence matrix
4 次查看(过去 30 天)
显示 更早的评论
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),
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/191286/image.png)
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
2018-6-15
回答(2 个)
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
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/189265/image.png)
2. Nodes
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/189266/image.png)
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)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Graph and Network Algorithms 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!