Simple shortest path problem in matrix.

조회 수: 2 (최근 30일)
Seeker
Seeker 2013년 2월 16일
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
Azzi Abdelmalek 2013년 2월 16일
편집: Azzi Abdelmalek 2013년 2월 16일
Ok. I understand, but this is not a simple problem like you said!
Seeker
Seeker 2013년 2월 16일
Yes, I realized that after spending the whole day trying to get a right approach.
Pretty elegant solution, but unfortunately it seems it isn't applicable to my problem.
Thank you anyway and any further suggestion is welcomed.

댓글을 달려면 로그인하십시오.

답변 (3개)

Image Analyst
Image Analyst 2013년 2월 16일
  댓글 수: 1
Seeker
Seeker 2013년 2월 16일
편집: Seeker 2013년 2월 16일
I did. But everything there looks like a overkill. Mine is much simpler problem and those functions are not really applicable.
Thank you, anyway.

댓글을 달려면 로그인하십시오.


Alex Foreever
Alex Foreever 2013년 2월 16일
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
Walter Roberson
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
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
Walter Roberson 2013년 2월 16일
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
Seeker 2013년 2월 16일
편집: Walter Roberson 2013년 2월 16일
Hm, good point. That's why I need the advice on this.
I was trying to solve it today using Steve's tutorial ( http://blogs.mathworks.com/steve/2011/11/26/exploring-shortest-paths-part-2/).
Here is the example what I need. As you can see it doesn't work well, but you can get an impression what it needs to do.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Operating on Diagonal Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by