Frage

I have the following code snippet which I use to find the shortest path between two nodes:

GremlinPipeline<String, List> pathPipe = new GremlinPipeline<String, List>(v1)
            .as("similar")
            .out("similar")
            .loop("similar", new PipeFunction<LoopBundle<Vertex>, Boolean>() {
                //@Override
                public Boolean compute(LoopBundle<Vertex> bundle) {
                    return bundle.getLoops() < 5 && bundle.getObject() != v2;
                }
            })
            .path()

Now I wonder how can I print the results. I try this:

Iterator iter = pathPipe.iterator(); while(iter.hasNext()) { System.out.println(iter.next()); }

But I have the following strange results:

[v[#9:0], v[#9:1], v[#9:0]]
[v[#9:0], v[#9:1], v[#9:2]]
[v[#9:0], v[#9:1], v[#9:3]]
[v[#9:0], v[#9:1], v[#9:4]]
[v[#9:0], v[#9:1], v[#9:5]]
[v[#9:0], v[#9:1], v[#9:6]]
[v[#9:0], v[#9:1], v[#9:7]]
[v[#9:0], v[#9:1], v[#9:8]]
[v[#9:0], v[#9:1], v[#9:9]]
[v[#9:0], v[#9:1], v[#9:10]]
[v[#9:0], v[#9:1], v[#9:11]]
[v[#9:0], v[#9:1], v[#9:12]]
[v[#9:0], v[#9:1], v[#9:13]]
[v[#9:0], v[#9:1], v[#9:14]]
[v[#9:0], v[#9:1], v[#9:15]]
[v[#9:0], v[#9:1], v[#9:16]]

Note that I am trying to find the shortest path between nodes v[#9:0] and v[#9:1].

Is there a problem on my find shortest path code or there is an other way to print my results?

I use oriented 1.6.2.

War es hilfreich?

Lösung

My gremlin-java/pipeline isn't as good as my gremlin-groovy, but one problem I see is that you aren't dealing with vertex equality properly in Java. This part:

&& bundle.getObject() != v2

is valid for Groovy, but in Java I would write it as:

&& !bundle.getObject().equals(v2)
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top