I have a directed graph in which all vertices are connected, ultimately,
to a single root vertex.
I want to examine all the paths from the root to each of the leaves,
and count the number of paths with cycles.
I came up with this, after reading the gremlin docs:
g.V.out.simplePath.filter{ it.path == null }.count()
and also tried this variation:
g.V.out.cyclicPath.filter{ it != null }.count()
In both cases, I though if the response was zero, then I didn't have
any cycles.
But then, I deliberately added a cycle, and retried both.
Both gave me 0 again, which is clearly wrong.
Then I realized g.V.out produces just all the individual edges between
vertices, and I wasn't getting the full set of paths that I need.
After reading this thread[1] and looking at this recipe[2], I realized
I need something with a loop(), to capture all the possible paths.
Ideally, since I do have a root vertex to start from, it would be a
variation of this:
g.v(A).out.loop(1){it.loops<=N && !(it.object.id in [A,B])}.filter{it.id==B}.path
where A is the id of the root vertex, but for all possible B, with an
indeterminate depth of N.
Is there a single expression for something like that?
[1] https://groups.google.com/d/topic/gremlin-users/UeFPpdz73h4/discussion
[2] http://www.tinkerpop.com/docs/wikidocs/gremlin/2.1.0/Finding-All-Paths-Between-2-Vertices.html