I have java application from which I'm calling a groovy class to compute the shortest path between 2 vertices in a graph.
Java:
public class Test {
public static void main(String[] args) {
TinkerGraph g = new TinkerGraph();
Vertex src = null;
src = g.addVertex(null);
src.setProperty("name",1);
src.setProperty("Type", "switch");
Vertex src1 = null;
src1 = g.addVertex(null);
src1.setProperty("name",2);
src1.setProperty("Type", "switch");
Vertex src2 = null;
src2 = g.addVertex(null);
src2.setProperty("name",3);
src2.setProperty("Type", "switch");
Vertex src3 = null;
src3 = g.addVertex(null);
src3.setProperty("name",4);
src3.setProperty("Type", "switch");
Edge e=null;
e=g.addEdge(null, src, src1, "connects");
Edge e1=null;
e1= g.addEdge(null, src1, src2, "connects");
Edge e2=null;
e2= g.addEdge(null, src2, src3, "connects");
System.out.println(GetRoute.getPathToHost(g));
}
}
Groovy:
class GetRoute {
static {
Gremlin.load()
}
public static Map<Vertex, Integer> getPathToHost(TinkerGraph g) {
g1.V[["name":1]].both.loop(2){!it.object.equals("name":4)}.Paths >> 1
}
}
My question is:
First of all the query is wrong. I've computed a function in gremlinpipe+java but it's pretty huge and I'm try to find a easier way with groovy. How do I refine this query?
Lets say my query prints all the vertices in the path between 2 vertices then how do I store it in let say an Map array or how do I print it onto the console?
Any help would be highly appreciated.
Regards