Simple shortest path problem in matrix.
이전 댓글 표시
Hi,
I have a very simple problem.
I have a matrix which elements can have values 1 or 0 only. I need to find the shortest path from the first to last row.
Any movement across the element with the value 1 is free.
Any vertical or horizontal movement is worth 1 and any diagonal movement is worth sqrt(2) when the movement is across the element with the value 0.
I would very much appreciate any help with this.
Regards!
댓글 수: 10
Azzi Abdelmalek
2013년 2월 16일
What is the size of your matrix?
Walter Roberson
2013년 2월 16일
To confirm:
Moving from 1 to 1 is free, whether the movement is horizontal, vertical or diagonal?
Moving from 0 to 0 costs 1 when the movement is horizontal or vertical, and sqrt(2) when the movement is diagonal?
How about the costs to move from 0 to 1, or from 1 to 0, in the various directions?
Seeker
2013년 2월 16일
Seeker
2013년 2월 16일
편집: Azzi Abdelmalek
2013년 2월 16일
Image Analyst
2013년 2월 16일
And not a single one of the 66 submissions in the File Exchange could be adapted to your problem? Surely at least one of them could be a good starting point.
Azzi Abdelmalek
2013년 2월 16일
편집: Azzi Abdelmalek
2013년 2월 16일
You said from the first row to the last row. Which value from the first row? Also you have to specify what do you mean by diagonal: a(1,1) to a(2,3) is it a diagonal?
Seeker
2013년 2월 16일
Azzi Abdelmalek
2013년 2월 16일
편집: Azzi Abdelmalek
2013년 2월 16일
Ok. I understand, but this is not a simple problem like you said!
Seeker
2013년 2월 16일
답변 (3개)
Image Analyst
2013년 2월 16일
0 개 추천
Try the File Exchange first: http://www.mathworks.com/matlabcentral/fileexchange/index?utf8=%E2%9C%93&term=shortest+path
Alex Foreever
2013년 2월 16일
0 개 추천
This is a wild suggestion.
consider the matrix as a tree such that 1)each adjacent elements with values 0 are nodes. 2)Distance between nodes representing vertically and horizontally adjacent elements are 1. 3)Similarly put distance between diagonally adjacent nodes as root(2).
Then perform a shortest distance algorithm on it.
댓글 수: 5
Seeker
2013년 2월 16일
Image Analyst
2013년 2월 16일
Alex, that's what many of the files in the File Exchange that I suggested do, such as this one: http://www.mathworks.com/matlabcentral/fileexchange/26723-demonstration-of-astar-a, which uses the A* algorithm, my favorite. You have a matrix (or an image) but it can of course be considered as a tree. For some reason, Seeker does not see how they apply to his situation.
Seeker
2013년 2월 16일
Walter Roberson
2013년 2월 16일
First, I am a novice in Matlab
What computer language are you more advanced in? Chances are you could write the program in that language and then transcribe it to MATLAB.
Image Analyst
2013년 2월 17일
Well what you're asking for is not trivial. It's not something one of us could bang out in five minutes and give to you. It's not going to be some short program of 20 or 30 lines. It would take a lot longer than 5 minutes, hence my suggestion to look at people who have already spent that time developing and debugging their program.
Walter Roberson
2013년 2월 16일
0 개 추천
If your image has any two adjacent 0 pixels adjacent to the shortest path that involves only 1's, then there is no solution to the problem, as the path can move back and forth between the two 0's indefinitely without increasing the cost.
댓글 수: 1
Seeker
2013년 2월 16일
편집: Walter Roberson
2013년 2월 16일
카테고리
도움말 센터 및 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!