use of com.baidu.hugegraph.traversal.algorithm.SingleSourceShortestPathTraverser 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);
}
use of com.baidu.hugegraph.traversal.algorithm.SingleSourceShortestPathTraverser 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