0

I have a 2D int array which I processed and got from an image. Each index can be thought as weight of that pixel. I want to find a path between 2 indexes (I'll give these indexes as input) that has the least cost. It would be great if the direction of movements can be modified (like only down&left, up&left. or all. etc. otherwise it may be down, left and right)

How can i do that in C#?

2
  • Could you write a mini example Commented Mar 13, 2012 at 14:17
  • possible duplicate of 2D array path finding Commented Mar 16, 2012 at 11:36

2 Answers 2

1

Regardless of language, I would calculate the cost for a direct path first. This will became the first base line. Then I would recursively search for a shorter path. You can make a few boundary checks to reduce the recursion.

  1. Any path that is >= the base line (or current best) is terminated
  2. Any path that would hit an index twice is terminated
  3. Any successful path sets the new base line (or best)
Sign up to request clarification or add additional context in comments.

Comments

0

The A* algorithm (as was already tagged :)) is a good choice for this.

See, for example, How to implement an A* algorithm?

2 Comments

what can you say about the directions issue?
My intuition says that instead of allowing to add cells diagonal (or whatever) from the current cell to the list of open cells to search, allow only those that fit your constraints. It's been a while since I've used A* though, so I'm not sure it'll end up as it should...

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.