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

pathTo ignores .withDirection(GraphTraversal.AnyConnected) #62

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

pathTo ignores .withDirection(GraphTraversal.AnyConnected) #62

matthewrj opened this issue Sep 28, 2016 · 1 comment
Labels

Comments

@matthewrj
Copy link

@matthewrj matthewrj commented Sep 28, 2016

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
Copy link
Contributor

@peter-empen 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
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.