Use Shortest path in directed graph
이전 댓글 표시
Hello,
I have a Graph that has a few nodes and edges. There is actually a specific reason to not use an undirected graph but a directed one. In this example I need to find the shortest path in between Node 8 and Noe 6. I know that there is no actual right way to solve it, because it is a directed graph.
But I actually need the directed graph for other parts of the calculation, so I cannot change that. Is there a workaround for this problem?

Thank you in advance!
답변 (1개)
Walter Roberson
2020년 5월 13일
1 개 추천
No, there is no solution to that.
If you start at node 8, then you can move to node 4 or node 7. However, both of those nodes have only inputs and no outputs, so you cannot move from 4 or 7 to anywhere else.
If you start at node 6, then instead of going through a number of steps to prove that no path works, just look at the destination node 8 and notice it has no inputs, so there is no way to reach it from node 6.
Thus, if you start at 8 you cannot get to 6, and if you start at 6 you cannot get to 8.
Therefore there is no directed path between node 6 and node 8.
댓글 수: 3
Phillipp
2020년 5월 13일
Walter Roberson
2020년 5월 13일
Let your current directed graph be G. Then
uG = graph(G.Edges); %creates an undirected graph
Now you can run the shortest path algorithm on uG.
Note: when you construct the undirected graph this way, then any weight information in the original graph is carried over.
Phillipp
2020년 5월 13일
카테고리
도움말 센터 및 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!