Java program shortestpath orientdb -
i have code in java program. have built graph, call , want calculate shortest path nothing. want result in java console. can me please.....
orientgraphfactory factory = new orientgraphfactory("plocal:db_path", "admin", "admin"); orientgraph db = factory.gettx(); ( int i=0; i<=number_nodes; i++){ for(int j=0; j<=number_nodes;j++) { (vertex v : db.getvertices("vertexid", i)) { (vertex v1 : db.getvertices("vertexid", j)) { (edge e : db.getedges()) { if (e.getvertex(direction.in).equals(v)) { if (e.getvertex(direction.out).equals(v1)){ string query = "select expand(shortestpath("+v+","+v1+",'out') "; iterable<orientvertex> res = db.command(new ocommandsql(query)).execute(); while (res.iterator().hasnext()) { orientvertex vf = res.iterator().next(); system.out.println("id="+vf.getproperty("vertexid")); } } } } } } } }
in string query
"select expand(shortestpath("+v+","+v1+",'out') "
you open 2 brackets close 1 of them
i tried structure
and code
for ( int i=0; i<=2; i++){ for(int j=0; j<=2;j++) { (vertex v : g.getvertices("vertexid", i)) { (vertex v1 : g.getvertices("vertexid", j)) { (edge e : g.getedges()) { if (e.getvertex(direction.in).equals(v)) { if (e.getvertex(direction.out).equals(v1)){ string query = "select expand(shortestpath('"+v.getid()+"','"+v1.getid()+"','both'))"; iterable<orientvertex> res = g.command(new ocommandsql(query)).execute(); while (res.iterator().hasnext()) { orientvertex vf = res.iterator().next(); system.out.println("id="+vf.getproperty("vertexid")); } } } } } } }
}
and worked.
hope helps.
Comments
Post a Comment