use of com.baidu.hugegraph.traversal.algorithm.MultiNodeShortestPathTraverser in project incubator-hugegraph by apache.
the class MultiNodeShortestPathAPI method post.
@POST
@Timed
@Consumes(APPLICATION_JSON)
@Produces(APPLICATION_JSON_WITH_CHARSET)
public String post(@Context GraphManager manager, @PathParam("graph") String graph, Request request) {
E.checkArgumentNotNull(request, "The request body can't be null");
E.checkArgumentNotNull(request.vertices, "The vertices of request can't be null");
E.checkArgument(request.step != null, "The steps of request can't be null");
LOG.debug("Graph [{}] get multiple node shortest path from " + "vertices '{}', with step '{}', max_depth '{}', capacity " + "'{}' and with_vertex '{}'", graph, request.vertices, request.step, request.maxDepth, request.capacity, request.withVertex);
HugeGraph g = graph(manager, graph);
Iterator<Vertex> vertices = request.vertices.vertices(g);
EdgeStep step = step(g, request.step);
List<HugeTraverser.Path> paths;
try (MultiNodeShortestPathTraverser traverser = new MultiNodeShortestPathTraverser(g)) {
paths = traverser.multiNodeShortestPath(vertices, step, request.maxDepth, request.capacity);
}
if (!request.withVertex) {
return manager.serializer(g).writePaths("paths", paths, false);
}
Set<Id> ids = new HashSet<>();
for (HugeTraverser.Path p : paths) {
ids.addAll(p.vertices());
}
Iterator<Vertex> iter = QueryResults.emptyIterator();
if (!ids.isEmpty()) {
iter = g.vertices(ids.toArray());
}
return manager.serializer(g).writePaths("paths", paths, false, iter);
}
Aggregations