How to find all possible paths between two nodes in a 246 nodes system.
조회 수: 4 (최근 30일)
이전 댓글 표시
ld=[1 2 2; 1 3 2; 1 4 3; 2 3 3; 3 4 2; 4 5 4; 4 6 4; 5 6 3];
first two column represent edge (node connectivity) of graph and third column represent distance between that line. For example: I want to know all paths from 3 to 4.
My answer will be :
[3 4]
[3 1 4]
[3 2 1 4]
Please help me to solve this. I already use Dijkstra algorithm but Dijkstra algorithm is in xy plane or xyz plane, which is not like my problem.
댓글 수: 1
John BG
2016년 5월 31일
the column on the right is distance, so for the matrix example you can check whether there is a path defined between 3 and 4 with:
intersect(find(A(:,1)==3),find(A(:,1)==4))
Empty matrix: 0-by-1
If you allow the matrix to have multiple hops between start and stop nodes, then you may want to use a cell instead of a array of integers, because while a line may have just 2 nodes, the start and stop, next line may have for instance 20 hops between start and stop.
답변 (1개)
Walter Roberson
2016년 5월 31일
댓글 수: 2
Walter Roberson
2016년 5월 31일
Incorrect. That code has no built-in limits other than those imposed by MATLAB and the amount of memory you have available.
참고 항목
카테고리
Help Center 및 File Exchange에서 Dijkstra algorithm에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!