Need some help with Gremlin: If I know the start vertex and the end vertex and there are multiple paths between start and end BUT I have a couple of vertexes along the way. How can I find the correct path based on the data I have?
For instance here I what I have to find the paths from 'college' to 'finch'
g.V().has('station','college').
repeat(out().simplePath())
.until(has('station','finch'))
.path().by('station')
Results
==>[college, wellesley, bloor-yonge, rosedale, summerhill, st. clair, davisville, eglinton, lawrence, york mills, sheppard-yonge, north york centre, finch]
==>[college, dundas, queen, king, union, st. andrew, osgoode, st. patrick, queenspark, museum, st. george, bay, bloor-yonge, rosedale, summerhill, st. clair, davisville, eglinton, lawrence, york mills, sheppard-yonge, north york centre, finch]
But how to i get the correct path that went THROUGH 'dundas' for example?
Daniel Kuppitz's answer is much better than mine.
You can use a path-bound counter that you only increment if you find a certain element along the path:
Adding more necessary points (e.g. filter paths that go through
G
,H
andP
) is easy with this approach.However, if it's only one vertex that has to be part of the path, then sel-fish's answer is another valid option (don't know why it got downvoted).