use of com.baidu.hugegraph.traversal.algorithm.SingleSourceShortestPathTraverser.NodeWithWeight in project incubator-hugegraph by apache.
the class WeightedShortestPathAPI method get.
@GET
@Timed
@Produces(APPLICATION_JSON_WITH_CHARSET)
public String get(@Context GraphManager manager, @PathParam("graph") String graph, @QueryParam("source") String source, @QueryParam("target") String target, @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("with_vertex") boolean withVertex) {
LOG.debug("Graph [{}] get weighted shortest path between '{}' and " + "'{}' with direction {}, edge label {}, weight property {}, " + "max degree '{}', skip degree '{}', capacity '{}', " + "and with vertex '{}'", graph, source, target, direction, edgeLabel, weight, maxDegree, skipDegree, capacity, withVertex);
Id sourceId = VertexAPI.checkAndParseVertexId(source);
Id targetId = VertexAPI.checkAndParseVertexId(target);
Directions dir = Directions.convert(EdgeAPI.parseDirection(direction));
E.checkArgumentNotNull(weight, "The weight property can't be null");
HugeGraph g = graph(manager, graph);
SingleSourceShortestPathTraverser traverser = new SingleSourceShortestPathTraverser(g);
NodeWithWeight path = traverser.weightedShortestPath(sourceId, targetId, dir, edgeLabel, weight, maxDegree, skipDegree, capacity);
Iterator<Vertex> iterator = QueryResults.emptyIterator();
if (path != null && withVertex) {
assert !path.node().path().isEmpty();
iterator = g.vertices(path.node().path().toArray());
}
return manager.serializer(g).writeWeightedPath(path, iterator);
}
Aggregations