use of com.baidu.hugegraph.traversal.algorithm.SingleSourceShortestPathTraverser.WeightedPaths in project incubator-hugegraph by apache.
the class SingleSourceShortestPathAPI method get.
@GET
@Timed
@Produces(APPLICATION_JSON_WITH_CHARSET)
public String get(@Context GraphManager manager, @PathParam("graph") String graph, @QueryParam("source") String source, @QueryParam("direction") String direction, @QueryParam("label") String edgeLabel, @QueryParam("weight") String weight, @QueryParam("max_degree") @DefaultValue(DEFAULT_MAX_DEGREE) long maxDegree, @QueryParam("skip_degree") @DefaultValue("0") long skipDegree, @QueryParam("capacity") @DefaultValue(DEFAULT_CAPACITY) long capacity, @QueryParam("limit") @DefaultValue(DEFAULT_PATHS_LIMIT) long limit, @QueryParam("with_vertex") boolean withVertex) {
LOG.debug("Graph [{}] get single source shortest path from '{}' " + "with direction {}, edge label {}, weight property {}, " + "max degree '{}', limit '{}' and with vertex '{}'", graph, source, direction, edgeLabel, weight, maxDegree, withVertex);
Id sourceId = VertexAPI.checkAndParseVertexId(source);
Directions dir = Directions.convert(EdgeAPI.parseDirection(direction));
HugeGraph g = graph(manager, graph);
SingleSourceShortestPathTraverser traverser = new SingleSourceShortestPathTraverser(g);
WeightedPaths paths = traverser.singleSourceShortestPaths(sourceId, dir, edgeLabel, weight, maxDegree, skipDegree, capacity, limit);
Iterator<Vertex> iterator = QueryResults.emptyIterator();
assert paths != null;
if (!paths.isEmpty() && withVertex) {
iterator = g.vertices(paths.vertices().toArray());
}
return manager.serializer(g).writeWeightedPaths(paths, iterator);
}
Aggregations