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

pathTo ignores .withDirection(GraphTraversal.AnyConnected) #62

Closed
matthewrj opened this Issue Sep 28, 2016 · 1 comment

Comments

Projects
None yet
2 participants
@matthewrj

pathTo and shortestPathTo do not find a path if there is a path going the opposite direction to the edges and .withDirection(GraphTraversal.AnyConnected) is provided.

val g = Graph(1 ~> 2)
val path = g.get(2).withDirection(GraphTraversal.AnyConnected).pathTo(g.get(1))
println(path) // -> None
@peter-empen

This comment has been minimized.

Show comment
Hide comment
@peter-empen

peter-empen Oct 9, 2016

Contributor

Hi Matthew,

this behaviour is intentional - sorry for not having documented it explicitely. Here are the reasons:

Examining the Path type you will realize that it contains the inner nodes and, lazily, the inner edges that are on a path of the given graph. The library is designed such that you cannot compose a Path that contains non-existing nodes or edges with respect to the underlying graph. So pathTo and shortestPathTo can never return a non-existing path.

To achieve the desired result, you could build an inverse respectively undirected graph prior to calling pathTo or shortestPathTo.

More efficienly, a new Path method inverse could be added to the Path class that returns a sequence of nodes/edges. Certainly you can achieve this on your own as well.

Just tell me how to proceed.

Contributor

peter-empen commented Oct 9, 2016

Hi Matthew,

this behaviour is intentional - sorry for not having documented it explicitely. Here are the reasons:

Examining the Path type you will realize that it contains the inner nodes and, lazily, the inner edges that are on a path of the given graph. The library is designed such that you cannot compose a Path that contains non-existing nodes or edges with respect to the underlying graph. So pathTo and shortestPathTo can never return a non-existing path.

To achieve the desired result, you could build an inverse respectively undirected graph prior to calling pathTo or shortestPathTo.

More efficienly, a new Path method inverse could be added to the Path class that returns a sequence of nodes/edges. Certainly you can achieve this on your own as well.

Just tell me how to proceed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment