How to find all possible paths between two nodes in a 246 nodes system.

4 views (last 30 days)
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 Comment
John BG
John BG on 31 May 2016
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.

Sign in to comment.

Answers (1)

Walter Roberson
Walter Roberson on 31 May 2016
  2 Comments
Walter Roberson
Walter Roberson on 31 May 2016
Incorrect. That code has no built-in limits other than those imposed by MATLAB and the amount of memory you have available.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!