Search in sources :

Example 1 with PathSet

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

the class DoubleWayMultiPathsRecords method linkPath.

@Watched
protected final PathSet linkPath(int source, int target, boolean ring) {
    PathSet paths = new PathSet();
    PathSet sources = this.linkSourcePath(source);
    PathSet targets = this.linkTargetPath(target);
    for (Path tpath : targets) {
        tpath.reverse();
        for (Path spath : sources) {
            if (!ring) {
                // Avoid loop in path
                if (CollectionUtils.containsAny(spath.vertices(), tpath.vertices())) {
                    continue;
                }
            }
            List<Id> ids = new ArrayList<>(spath.vertices());
            ids.addAll(tpath.vertices());
            Id crosspoint = this.id(this.movingForward ? target : source);
            paths.add(new Path(crosspoint, ids));
        }
    }
    return paths;
}
Also used : Path(com.baidu.hugegraph.traversal.algorithm.HugeTraverser.Path) PathSet(com.baidu.hugegraph.traversal.algorithm.HugeTraverser.PathSet) ArrayList(java.util.ArrayList) Id(com.baidu.hugegraph.backend.id.Id) Watched(com.baidu.hugegraph.perf.PerfUtil.Watched)

Example 2 with PathSet

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

the class KoutRecords method paths.

@Override
public PathSet paths(long limit) {
    PathSet paths = new PathSet();
    Stack<Record> records = this.records();
    IntIterator iterator = records.peek().keys();
    while ((limit == NO_LIMIT || limit-- > 0L) && iterator.hasNext()) {
        paths.add(this.linkPath(records.size() - 1, iterator.next()));
    }
    return paths;
}
Also used : IntIterator(com.baidu.hugegraph.util.collection.IntIterator) PathSet(com.baidu.hugegraph.traversal.algorithm.HugeTraverser.PathSet) Record(com.baidu.hugegraph.traversal.algorithm.records.record.Record)

Example 3 with PathSet

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

the class ShortestPathRecords method findPath.

@Override
public PathSet findPath(Id target, Function<Id, Boolean> filter, boolean all, boolean ring) {
    assert !ring;
    PathSet paths = new PathSet();
    int targetCode = this.code(target);
    int parentCode = this.current();
    // If cross point exists, shortest path found, concat them
    if (this.movingForward() && this.targetContains(targetCode) || !this.movingForward() && this.sourceContains(targetCode)) {
        if (!filter.apply(target)) {
            return paths;
        }
        paths.add(this.movingForward() ? this.linkPath(parentCode, targetCode) : this.linkPath(targetCode, parentCode));
        this.pathFound = true;
        if (!all) {
            return paths;
        }
    }
    /*
         * Not found shortest path yet, node is added to current layer if:
         * 1. not in sources and newVertices yet
         * 2. path of node doesn't have loop
         */
    if (!this.pathFound && this.isNew(targetCode)) {
        this.addPath(targetCode, parentCode);
    }
    return paths;
}
Also used : PathSet(com.baidu.hugegraph.traversal.algorithm.HugeTraverser.PathSet)

Example 4 with PathSet

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

the class DoubleWayMultiPathsRecords method linkPathLayer.

private PathSet linkPathLayer(Stack<Record> all, int id, int layerIndex) {
    PathSet results = new PathSet();
    if (layerIndex == 0) {
        Id sid = this.id(id);
        results.add(new Path(Lists.newArrayList(sid)));
        return results;
    }
    Id current = this.id(id);
    Record layer = all.elementAt(layerIndex);
    IntIterator iterator = layer.get(id);
    while (iterator.hasNext()) {
        int parent = iterator.next();
        PathSet paths = this.linkPathLayer(all, parent, layerIndex - 1);
        paths.append(current);
        results.addAll(paths);
    }
    return results;
}
Also used : Path(com.baidu.hugegraph.traversal.algorithm.HugeTraverser.Path) IntIterator(com.baidu.hugegraph.util.collection.IntIterator) PathSet(com.baidu.hugegraph.traversal.algorithm.HugeTraverser.PathSet) Record(com.baidu.hugegraph.traversal.algorithm.records.record.Record) Id(com.baidu.hugegraph.backend.id.Id)

Example 5 with PathSet

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

the class KneighborRecords method paths.

@Override
public PathSet paths(long limit) {
    PathSet paths = new PathSet();
    Stack<Record> records = this.records();
    for (int i = 1; i < records.size(); i++) {
        IntIterator iterator = records.get(i).keys();
        while ((limit == NO_LIMIT || limit > 0L) && iterator.hasNext()) {
            paths.add(this.linkPath(i, iterator.next()));
            limit--;
        }
    }
    return paths;
}
Also used : IntIterator(com.baidu.hugegraph.util.collection.IntIterator) PathSet(com.baidu.hugegraph.traversal.algorithm.HugeTraverser.PathSet) Record(com.baidu.hugegraph.traversal.algorithm.records.record.Record)

Aggregations

PathSet (com.baidu.hugegraph.traversal.algorithm.HugeTraverser.PathSet)6 Record (com.baidu.hugegraph.traversal.algorithm.records.record.Record)3 IntIterator (com.baidu.hugegraph.util.collection.IntIterator)3 Id (com.baidu.hugegraph.backend.id.Id)2 Watched (com.baidu.hugegraph.perf.PerfUtil.Watched)2 Path (com.baidu.hugegraph.traversal.algorithm.HugeTraverser.Path)2 ArrayList (java.util.ArrayList)1