Shortest Path in a 3D Matrix
古いコメントを表示
I have a 3D matrix with all 1 or 0 and two random elements. How can I calculate the shortest path between them and check how many elements with 1 are in the path? Thanks in advance.
4 件のコメント
James Tursa
2015 年 6 月 2 日
Define shortest path. What about ties?
jan smith
2015 年 6 月 2 日
Alfonso Nieto-Castanon
2015 年 6 月 2 日
that definition does not lead to unique trajectories. Consider in 2d-space:
0 0 1 2 3 0
0 0 0 0 0 4
or
0 0 1 0 0 0
0 0 0 2 3 4
or
0 0 1 2 0 0
0 0 0 0 3 4
all have the same number of elements. What should the algorithm do with these multiple optimal paths?
Image Analyst
2015 年 6 月 2 日
Steve talks about the non-uniqueness of paths in part 2 of his blog: http://blogs.mathworks.com/steve/2011/11/26/exploring-shortest-paths-part-2/
採用された回答
その他の回答 (3 件)
Walter Roberson
2015 年 6 月 2 日
0 投票
The same way as with a 2D matrix; you build a connectivity list and run a shortest path algorithm on it.
Image Analyst
2015 年 6 月 2 日
0 投票
Steve has a blog on that: http://blogs.mathworks.com/steve/2011/11/01/exploring-shortest-paths-part-1/ though I don't know if bwdistgeodesic works on 3D images.
3 件のコメント
Walter Roberson
2015 年 6 月 2 日
bwdistgeodesic is not documented as working on 3D images. In particular the description of how it works is in terms of 2D.
Alex Taylor
2015 年 6 月 3 日
bwdistgeodesic does work on 3-D data.
Image Analyst
2015 年 6 月 3 日
Alex, I don't think the documentation is entirely clear. All the help says is "BW is a logical matrix." I've seen some people say "matrix" means only a 2-D array whereas anything 3-D or higher should be called "array" instead of "matrix." I'm not sure I agree with that, and sometimes I use them interchangeably. But nonetheless I think the documentation could be clearer on the dimensionality that it accepts. If it works for a n-D array where n can be any integer, then it might say that explicitly. Sometime you have separate n versions of functions, like convhull and convhulln, and bwlabel and bwlabeln. So sometimes people assume it's only 2-D unless it makes it clear in the documentation that it's for n-D.
ahmad karim
2015 年 6 月 3 日
0 投票
Plese, i have travelling salesman cost function but its give me error when i implement it plese can any one help me ?
% cost function for traveling salesperson problem % Haupt & Haupt % 2003 function dist=tspfun(pop) global iga x y [Npop,Ncity]=size(pop); tour=[pop pop(:,1)]; %distance between cities for ic=1:Ncity for id=1:Ncity dcity(ic,id)=sqrt((x(ic)-x(id))^2+(y(ic)-y(id))^2); end % id end %ic % cost of each chromosome for ic=1:Npop dist(ic,1)=0; for id=1:Ncity dist(ic,1)=dist(ic)+dcity(tour(ic,id),tour(ic,id+1)); end % id end % ic
1 件のコメント
Image Analyst
2015 年 6 月 3 日
The traveling salesman problem is not really related to the shortest path algorithm in imaging. TSP has to visit every node, in imaging we don't. I suggest you start your own question in a new discussion thread.
カテゴリ
ヘルプ センター および 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!