Search in sources :

Example 6 with Traverser

use of org.neo4j.graphdb.traversal.Traverser in project neo4j by neo4j.

the class DepthPitfallGraphTest method canPreFilterNodes.

private void canPreFilterNodes(TraversalDescription description) {
    Traverser traverser = description.uniqueness(Uniqueness.NONE).evaluator(atDepth(2)).traverse(node("1"));
    expectPaths(traverser, "1,2,6", "1,3,5", "1,4,5", "1,5,3", "1,5,4", "1,5,6");
}
Also used : Traverser(org.neo4j.graphdb.traversal.Traverser)

Example 7 with Traverser

use of org.neo4j.graphdb.traversal.Traverser in project neo4j by neo4j.

the class DepthPitfallGraphTest method canPruneTraversalAtSpecificDepth.

private void canPruneTraversalAtSpecificDepth(TraversalDescription description) {
    Traverser traverser = description.uniqueness(Uniqueness.NONE).evaluator(toDepth(1)).traverse(node("1"));
    expectNodes(traverser, "1", "2", "3", "4", "5");
}
Also used : Traverser(org.neo4j.graphdb.traversal.Traverser)

Example 8 with Traverser

use of org.neo4j.graphdb.traversal.Traverser in project neo4j by neo4j.

the class DepthPitfallGraphTest method testNodesAreReturnedOnceWhenSufficientRecentlyUnique.

private void testNodesAreReturnedOnceWhenSufficientRecentlyUnique(TraversalDescription description) {
    Traverser traverser = description.uniqueness(Uniqueness.NODE_RECENT, 6).traverse(node("1"));
    expectNodes(traverser, "1", "2", "3", "4", "5", "6");
}
Also used : Traverser(org.neo4j.graphdb.traversal.Traverser)

Example 9 with Traverser

use of org.neo4j.graphdb.traversal.Traverser in project neo4j by neo4j.

the class SmallestGraphEverTest method execute.

private void execute(TraversalDescription traversal, Uniqueness uniqueness) {
    try (Transaction transaction = beginTx()) {
        Traverser traverser = traversal.uniqueness(uniqueness).traverse(node("1"));
        assertFalse("empty traversal", Iterables.count(traverser) == 0);
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction) Traverser(org.neo4j.graphdb.traversal.Traverser)

Example 10 with Traverser

use of org.neo4j.graphdb.traversal.Traverser in project neo4j-mobile-android by neo4j-contrib.

the class ExperimentalAStar method findAllPaths.

public Iterable<WeightedPath> findAllPaths(Node start, final Node end) {
    Predicate<Path> filter = new Predicate<Path>() {

        public boolean accept(Path position) {
            return position.endNode().equals(end);
        }
    };
    final Traverser traverser = traversalDescription.order(new SelectorFactory(end)).filter(filter).traverse(start);
    return new Iterable<WeightedPath>() {

        public Iterator<WeightedPath> iterator() {
            return new StopAfterWeightIterator(traverser.iterator(), costEvaluator);
        }
    };
}
Also used : Path(org.neo4j.graphdb.Path) WeightedPath(org.neo4j.graphalgo.WeightedPath) WeightedPath(org.neo4j.graphalgo.WeightedPath) BestFirstSelectorFactory(org.neo4j.graphalgo.impl.util.BestFirstSelectorFactory) Traverser(org.neo4j.graphdb.traversal.Traverser) StopAfterWeightIterator(org.neo4j.graphalgo.impl.util.StopAfterWeightIterator) Predicate(org.neo4j.helpers.Predicate)

Aggregations

Traverser (org.neo4j.graphdb.traversal.Traverser)44 Test (org.junit.Test)19 Path (org.neo4j.graphdb.Path)15 Transaction (org.neo4j.graphdb.Transaction)10 HashSet (java.util.HashSet)6 Node (org.neo4j.graphdb.Node)6 Predicate (org.neo4j.helpers.Predicate)6 Set (java.util.Set)4 Stack (java.util.Stack)4 WeightedPath (org.neo4j.graphalgo.WeightedPath)4 BestFirstSelectorFactory (org.neo4j.graphalgo.impl.util.BestFirstSelectorFactory)4 StopAfterWeightIterator (org.neo4j.graphalgo.impl.util.StopAfterWeightIterator)4 Relationship (org.neo4j.graphdb.Relationship)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 LiteDepthFirstSelector (org.neo4j.graphalgo.impl.util.LiteDepthFirstSelector)2 BranchOrderingPolicy (org.neo4j.graphdb.traversal.BranchOrderingPolicy)2 BranchSelector (org.neo4j.graphdb.traversal.BranchSelector)2 TraversalBranch (org.neo4j.graphdb.traversal.TraversalBranch)2 TraversalDescription (org.neo4j.graphdb.traversal.TraversalDescription)2