Search in sources :

Example 1 with ShortestPathTraverser

use of com.baidu.hugegraph.traversal.algorithm.ShortestPathTraverser in project incubator-hugegraph by apache.

the class ShortestPathAPI 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("max_depth") int depth, @QueryParam("max_degree") @DefaultValue(DEFAULT_MAX_DEGREE) long maxDegree, @QueryParam("skip_degree") @DefaultValue("0") long skipDegree, @QueryParam("capacity") @DefaultValue(DEFAULT_CAPACITY) long capacity) {
    LOG.debug("Graph [{}] get shortest path from '{}', to '{}' with " + "direction {}, edge label {}, max depth '{}', " + "max degree '{}', skipped maxDegree '{}' and capacity '{}'", graph, source, target, direction, edgeLabel, depth, maxDegree, skipDegree, capacity);
    Id sourceId = VertexAPI.checkAndParseVertexId(source);
    Id targetId = VertexAPI.checkAndParseVertexId(target);
    Directions dir = Directions.convert(EdgeAPI.parseDirection(direction));
    HugeGraph g = graph(manager, graph);
    ShortestPathTraverser traverser = new ShortestPathTraverser(g);
    List<String> edgeLabels = edgeLabel == null ? ImmutableList.of() : ImmutableList.of(edgeLabel);
    HugeTraverser.Path path = traverser.shortestPath(sourceId, targetId, dir, edgeLabels, depth, maxDegree, skipDegree, capacity);
    return manager.serializer(g).writeList("path", path.vertices());
}
Also used : HugeGraph(com.baidu.hugegraph.HugeGraph) ShortestPathTraverser(com.baidu.hugegraph.traversal.algorithm.ShortestPathTraverser) Directions(com.baidu.hugegraph.type.define.Directions) HugeTraverser(com.baidu.hugegraph.traversal.algorithm.HugeTraverser) Id(com.baidu.hugegraph.backend.id.Id) Produces(jakarta.ws.rs.Produces) Timed(com.codahale.metrics.annotation.Timed) GET(jakarta.ws.rs.GET)

Example 2 with ShortestPathTraverser

use of com.baidu.hugegraph.traversal.algorithm.ShortestPathTraverser in project incubator-hugegraph by apache.

the class AllShortestPathsAPI 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("max_depth") int depth, @QueryParam("max_degree") @DefaultValue(DEFAULT_MAX_DEGREE) long maxDegree, @QueryParam("skip_degree") @DefaultValue("0") long skipDegree, @QueryParam("capacity") @DefaultValue(DEFAULT_CAPACITY) long capacity) {
    LOG.debug("Graph [{}] get shortest path from '{}', to '{}' with " + "direction {}, edge label {}, max depth '{}', " + "max degree '{}', skipped degree '{}' and capacity '{}'", graph, source, target, direction, edgeLabel, depth, maxDegree, skipDegree, capacity);
    Id sourceId = VertexAPI.checkAndParseVertexId(source);
    Id targetId = VertexAPI.checkAndParseVertexId(target);
    Directions dir = Directions.convert(EdgeAPI.parseDirection(direction));
    HugeGraph g = graph(manager, graph);
    ShortestPathTraverser traverser = new ShortestPathTraverser(g);
    List<String> edgeLabels = edgeLabel == null ? ImmutableList.of() : ImmutableList.of(edgeLabel);
    HugeTraverser.PathSet paths = traverser.allShortestPaths(sourceId, targetId, dir, edgeLabels, depth, maxDegree, skipDegree, capacity);
    return manager.serializer(g).writePaths("paths", paths, false);
}
Also used : HugeGraph(com.baidu.hugegraph.HugeGraph) ShortestPathTraverser(com.baidu.hugegraph.traversal.algorithm.ShortestPathTraverser) Directions(com.baidu.hugegraph.type.define.Directions) HugeTraverser(com.baidu.hugegraph.traversal.algorithm.HugeTraverser) Id(com.baidu.hugegraph.backend.id.Id) Produces(jakarta.ws.rs.Produces) Timed(com.codahale.metrics.annotation.Timed) GET(jakarta.ws.rs.GET)

Aggregations

HugeGraph (com.baidu.hugegraph.HugeGraph)2 Id (com.baidu.hugegraph.backend.id.Id)2 HugeTraverser (com.baidu.hugegraph.traversal.algorithm.HugeTraverser)2 ShortestPathTraverser (com.baidu.hugegraph.traversal.algorithm.ShortestPathTraverser)2 Directions (com.baidu.hugegraph.type.define.Directions)2 Timed (com.codahale.metrics.annotation.Timed)2 GET (jakarta.ws.rs.GET)2 Produces (jakarta.ws.rs.Produces)2