Optimization in matrix ?

I have matrix[4][4] for example:
' *  '
'  * '
'     '
'     '
enter in matrix(for example) with coordinates [0][0]
and exit [0][3].
How to find optimizing way from enter to exit ?
Thank's
zmeyAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
yairyConnect With a Mentor Commented:
if there are no blocks between
the enter and exit point:
I would calculate each step the Length
from the immidiate neighbour points to me to the exit point.
I would choose the shortest length each time.


If there might be block, it isn't as simple.
one should can use Backtracking
to find the path.

heres a recurse "rough" definition:

f(location, matrix)
{
  if you are at the enter pos and have
  nowhere to go - quit, failer.
  else
  if you are in the Exit point -
  quit, Success.
  else
  if you don't have any place to go
  (all is block (except the from where
  you came)) mark the place as DeadEnd.
  <do nothing, the recurse will pop you
  to the prev. position>
  else
  call f(Location, matrix) for all
  free places that aren't blocked or a dead end.
}


Any questions ....

0
 
ozoCommented:
What do you wish to optimize?
0
 
Ernest022699Commented:
What you want is a maze-solving solution, not a matrix-solving solution.  A matrix is just a way of storing/representing a maze (such as a minefield).

The solution will depend on whether you allow wrapping, etc.  We need the rules.
0
All Courses

From novice to tech pro — start learning today.