Search in sources :

Example 1 with Path

use of com.baidu.hugegraph.traversal.algorithm.HugeTraverser.Path 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 Path

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

the class ShortestPathRecords method linkPath.

private Path linkPath(int source, int target) {
    Path sourcePath = this.linkSourcePath(source);
    Path targetPath = this.linkTargetPath(target);
    sourcePath.reverse();
    List<Id> ids = new ArrayList<>(sourcePath.vertices());
    ids.addAll(targetPath.vertices());
    return new Path(ids);
}
Also used : Path(com.baidu.hugegraph.traversal.algorithm.HugeTraverser.Path) ArrayList(java.util.ArrayList) Id(com.baidu.hugegraph.backend.id.Id)

Example 3 with Path

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

the class SingleWayMultiPathsRecords method linkPath.

protected final Path linkPath(int layerIndex, int target) {
    List<Id> ids = CollectionFactory.newList(CollectionType.EC);
    IntMap layer = this.layer(layerIndex);
    if (!layer.containsKey(target)) {
        throw new HugeException("Failed to get path for %s", this.id(target));
    }
    // Collect self node
    ids.add(this.id(target));
    // Concat parents
    for (int i = layerIndex; i > 0; i--) {
        layer = this.layer(i);
        // Uptrack parents
        target = layer.get(target);
        ids.add(this.id(target));
    }
    Collections.reverse(ids);
    return new Path(ids);
}
Also used : Path(com.baidu.hugegraph.traversal.algorithm.HugeTraverser.Path) IntMap(com.baidu.hugegraph.util.collection.IntMap) Id(com.baidu.hugegraph.backend.id.Id) HugeException(com.baidu.hugegraph.HugeException)

Example 4 with Path

use of com.baidu.hugegraph.traversal.algorithm.HugeTraverser.Path 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 Path

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

the class ShortestPathRecords method linkPath.

private Path linkPath(Stack<Record> all, int node) {
    int size = all.size();
    List<Id> ids = new ArrayList<>(size);
    ids.add(this.id(node));
    int value = node;
    for (int i = size - 1; i > 0; i--) {
        IntMap layer = ((Int2IntRecord) all.elementAt(i)).layer();
        value = layer.get(value);
        ids.add(this.id(value));
    }
    return new Path(ids);
}
Also used : Path(com.baidu.hugegraph.traversal.algorithm.HugeTraverser.Path) Int2IntRecord(com.baidu.hugegraph.traversal.algorithm.records.record.Int2IntRecord) ArrayList(java.util.ArrayList) IntMap(com.baidu.hugegraph.util.collection.IntMap) Id(com.baidu.hugegraph.backend.id.Id)

Aggregations

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