Search in sources :

Example 11 with Traverser

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

the class Dijkstra 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 = TRAVERSAL.expand(expander).order(new SelectorFactory(costEvaluator)).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)

Example 12 with Traverser

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

the class DepthPitfallGraphTest method canPreFilterNodes.

private void canPreFilterNodes(TraversalDescription description) {
    Traverser traverser = description.uniqueness(Uniqueness.NONE).evaluator(Evaluators.atDepth(2)).traverse(referenceNode());
    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 13 with Traverser

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

the class DepthPitfallGraphTest method testAllUniqueNodePathsAreReturned.

private void testAllUniqueNodePathsAreReturned(TraversalDescription description) throws Exception {
    Traverser traverser = description.uniqueness(Uniqueness.NODE_PATH).traverse(referenceNode());
    expectPaths(traverser, NODE_UNIQUE_PATHS);
}
Also used : Traverser(org.neo4j.graphdb.traversal.Traverser)

Example 14 with Traverser

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

the class DepthPitfallGraphTest method testRelationshipsAreReturnedOnceWhenSufficientRecentlyUnique.

private void testRelationshipsAreReturnedOnceWhenSufficientRecentlyUnique(TraversalDescription description) throws Exception {
    Traverser traverser = description.uniqueness(Uniqueness.RELATIONSHIP_RECENT, THE_WORLD_AS_WE_KNOW_IT.length).traverse(referenceNode());
    expectRelationships(traverser, THE_WORLD_AS_WE_KNOW_IT);
}
Also used : Traverser(org.neo4j.graphdb.traversal.Traverser)

Example 15 with Traverser

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

the class DepthPitfallGraphTest method testAllUniqueRelationshipPathsAreReturned.

private void testAllUniqueRelationshipPathsAreReturned(TraversalDescription description) throws Exception {
    Set<String> expected = new HashSet<String>(Arrays.asList(NODE_UNIQUE_PATHS));
    expected.addAll(Arrays.asList(RELATIONSHIP_UNIQUE_EXTRA_PATHS));
    Traverser traverser = description.uniqueness(Uniqueness.RELATIONSHIP_PATH).traverse(referenceNode());
    expectPaths(traverser, expected);
}
Also used : Traverser(org.neo4j.graphdb.traversal.Traverser) HashSet(java.util.HashSet)

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