Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Finding path back from the goal does not work when the graph has loops #1

Open
tsahyt opened this issue Jun 16, 2016 · 3 comments
Open

Comments

@tsahyt
Copy link

tsahyt commented Jun 16, 2016

When given a graph that has loops on every vertex, the aStar function never returns, even after a path has been found. The actual search seems to succeed, but building the path back to the start never finishes.

As a minimal example, I've been able to reproduce the problem with this (with S denoting Data.HashSet):

ghci> aStar (\x -> S.fromList [x, x - 1, x + 1]) (\_ _ -> 1) (const 0) (== 10) 1

ghci then hangs on Just. This indicates that the goal has been found and that the problem occurs in line 78 (or 133). It happens for both the monadic and normal versions of the function.

@cloudhead
Copy link

x shouldn't be considered adjacent to x, should it?

@tsahyt
Copy link
Author

tsahyt commented Jul 20, 2016

That depends entirely on the underlying state space. In general, graphs can have loops, i.e. nodes which are their own successors. The original A* paper does not exclude such graphs, and to my knowledge most other A* implementations work for graphs that have loops. The original A* paper is unfortunately behind a paywall, so I'll cite the relevant definition here

A graph G is defined to be a set nodes and a set {e_ij} of directed line segments called arcs. If e_pq is an element of the set {e_ij}, then we say that there is an arc from node n_p to node n_q and that n_q is a successor of n_p.

Note that this does not exclude arcs e_ii for node n_i. Of course, using such an arc would yield a suboptimal solution (assuming it has cost > 0), but the algorithm should still work regardless. Indeed, as formulated in the paper it does work. I'd argue that it should at least be noted somewhere (e.g. Haddock documentation) that this implementation only works for graphs without loops.

@cloudhead
Copy link

Ah I wasn't aware of the terminology there, thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants