why the command of finding the all short paths for graph ( graphallshortestpaths ) give me wrong numbers
Show older comments
Dear,
I'm trying to find all short paths between vertices so I used graphallshortestpaths,
but for my matrix
A=[1 1 0 0 1
1 1 1 0 0
0 0 0 1 0
0 0 1 1 1
1 0 0 0 0];
I got error for using the command
graphallshortestpaths(A)
Error using graphalgs
Input argument should be a sparse array.
Error in graphallshortestpaths (line 85)
dist = graphalgs('all',debug_level,directed,G);
Error in FitnessDiameter (line 92)
p=graphallshortestpaths(A)
so I used this code
[r,c]=find(A);
edgelist=[r,c];
edgelist = unique(edgelist, 'rows');
sz = max(edgelist(:));
DG = sparse(edgelist(:,1), edgelist(:,2), 1, sz, sz);% correct
matrix=full(DG)
%view(biograph(DG,[],'ShowWeights','on'));
p=graphallshortestpaths(DG)
I got result, but I got this matrix
P = [0 1 2 3 1
1 0 1 2 2
3 4 0 1 2
2 3 1 0 1
1 2 3 4 0];
and its wrong because the result should be symmetric matrix.
P = [0 1 2 3 1
1 0 1 2 1
2 1 0 1 2
3 2 1 0 1
1 1 2 1 0];
I don't know why.
It doesn't mentioned which type of matrix this command work. I have sparse matrix, and I want to find all short paths so I can find the diameter.
can anyone help me please.
thanks for any help.
Nadia
Accepted Answer
More Answers (0)
Categories
Find more on Graph and Network Algorithms in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!