Here's an implementation of the A-star algorithm in Python:
main.py759 chars26 lines
This implementation assumes that the graph is represented using a class with the following methods:
neighbors(node)
: returns the list of neighbors of node
cost(node, next)
: returns the cost of the edge connecting node
to next
heuristic(node, goal)
: returns the estimated cost from node
to the goal
These methods need to be implemented according to the particular problem that you're trying to solve.
gistlibby LogSnag