Sign in to follow this  
Madpierrot

multi goal pathfinding with A*

Recommended Posts

I'm using A* for a pacman path finding algorithm that returns the shortest path to eat all the dots. Runs perfectly, but when there are too many dots it bogs down so I'm looking for some ideas for a good heuristic for each state. Ones I've tried that seem to work (and I believe are admissible) are: (sum of distances of pacman to all dots) / (number of dots) and cumulative sum of the minimum of the distance of pacman to a dot, and from that dot to every other dot. So this is like a regular path finding scenario except there are multiple goals. It's similar to the traveling salesman problem (finding the shortest path) except that it's alright to visit the same position on the grid more than once.

Share this post


Link to post
Share on other sites
Actually those problems are different. In Ashaman73's, you're trying to reach a terminal set with more than one node. In Madpierrot's, you're trying to visit every node in a certain set.

Despite the allowance for multiple visits it still sounds like TSP to me, but I might give it a bit more thought.

Share this post


Link to post
Share on other sites
Definitely looks like Travelling Salesman to me too, so A* is probably not the best tool. Having said that, the second heuristic looks pretty accurate - if you can precalculate the distances (or cache them as you calculate them) to make it a simple integer look-up then this method should be reasonably fast, I'd think.

If you do really just have too many dots to handle, the first thing I'd try and consider is massively reducing the state space by collapsing adjacent dots that lie on the same path (ie. between junctions) into one node so that it can be assumed that if you get one of them, you'll get all of them. On a typical board this might reduce the number of nodes to consider by a factor of 4 or more.

Share this post


Link to post
Share on other sites
Thanks for the replies. I ended up calculating the minimum spanning trees (treating each dot as a node), caching the result and modifying it as the states changed. It still doesn't run quickly enough yet but its getting the job done. Collapsing adjacent dots into one dot is interesting and I may modify my state representation to make that possible.

Thanks for the replies.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this