Search in sources :

Example 1 with NodeWithWeight

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