Search in sources :

Example 1 with ShortestPath

use of org.neo4j.graphalgo.impl.path.ShortestPath in project graphdb by neo4j-attic.

the class TestShortestPath method makeSureDescentStopsWhenPathIsFound.

@Test
public void makeSureDescentStopsWhenPathIsFound() throws Exception {
    /*
         * (a)==>(b)==>(c)==>(d)==>(e)
         *   \
         *    v
         *    (f)-->(g)-->(h)-->(i)
         */
    graph.makeEdgeChain("a,b,c,d,e");
    graph.makeEdgeChain("a,b,c,d,e");
    graph.makeEdgeChain("a,f,g,h,i");
    Node a = graph.getNode("a");
    Node b = graph.getNode("b");
    Node c = graph.getNode("c");
    final Set<Node> allowedNodes = new HashSet<Node>(Arrays.asList(a, b, c));
    PathFinder<Path> finder = new ShortestPath(100, Traversal.expanderForAllTypes(Direction.OUTGOING)) {

        @Override
        protected Collection<Node> filterNextLevelNodes(Collection<Node> nextNodes) {
            for (Node node : nextNodes) {
                if (!allowedNodes.contains(node)) {
                    fail("Node " + node.getProperty(KEY_ID) + " shouldn't be expanded");
                }
            }
            return nextNodes;
        }
    };
    finder.findAllPaths(a, c);
}
Also used : ShortestPath(org.neo4j.graphalgo.impl.path.ShortestPath) Path(org.neo4j.graphdb.Path) Node(org.neo4j.graphdb.Node) ShortestPath(org.neo4j.graphalgo.impl.path.ShortestPath) Collection(java.util.Collection) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

Collection (java.util.Collection)1 HashSet (java.util.HashSet)1 Test (org.junit.Test)1 ShortestPath (org.neo4j.graphalgo.impl.path.ShortestPath)1 Node (org.neo4j.graphdb.Node)1 Path (org.neo4j.graphdb.Path)1