Search in sources :

Example 1 with WeightedPaths

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);
}
Also used : Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) HugeGraph(com.baidu.hugegraph.HugeGraph) Directions(com.baidu.hugegraph.type.define.Directions) Id(com.baidu.hugegraph.backend.id.Id) WeightedPaths(com.baidu.hugegraph.traversal.algorithm.SingleSourceShortestPathTraverser.WeightedPaths) SingleSourceShortestPathTraverser(com.baidu.hugegraph.traversal.algorithm.SingleSourceShortestPathTraverser) Produces(jakarta.ws.rs.Produces) Timed(com.codahale.metrics.annotation.Timed) GET(jakarta.ws.rs.GET)

Aggregations

HugeGraph (com.baidu.hugegraph.HugeGraph)1 Id (com.baidu.hugegraph.backend.id.Id)1 SingleSourceShortestPathTraverser (com.baidu.hugegraph.traversal.algorithm.SingleSourceShortestPathTraverser)1 WeightedPaths (com.baidu.hugegraph.traversal.algorithm.SingleSourceShortestPathTraverser.WeightedPaths)1 Directions (com.baidu.hugegraph.type.define.Directions)1 Timed (com.codahale.metrics.annotation.Timed)1 GET (jakarta.ws.rs.GET)1 Produces (jakarta.ws.rs.Produces)1 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)1