Search in sources :

Example 1 with ExactDepthPathFinder

use of org.neo4j.graphalgo.impl.path.ExactDepthPathFinder in project neo4j by neo4j.

the class TestExactDepthPathFinder method shouldHandleDirectionalGraph.

@Test
public void shouldHandleDirectionalGraph() {
    // ALL DIRECTED from (a) towards (g)
    //     (b) ----------------- (c)      length 3
    //   /                          \
    // (a) - (h) - (i) - (j) - (k) - (g)  length 5
    //   \                          /
    //     (d) - (e) ------------ (f)     length 4
    graph.makeEdgeChain("a,b,c,g");
    graph.makeEdgeChain("a,d,e,f,g");
    graph.makeEdgeChain("a,h,i,j,k,g");
    Node a = graph.getNode("a");
    Node g = graph.getNode("g");
    assertPaths(new ExactDepthPathFinder(PathExpanders.forDirection(Direction.OUTGOING), 3, Integer.MAX_VALUE, false).findAllPaths(a, g), "a,b,c,g");
    assertPaths(new ExactDepthPathFinder(PathExpanders.forDirection(Direction.OUTGOING), 4, Integer.MAX_VALUE, false).findAllPaths(a, g), "a,d,e,f,g");
    assertPaths(new ExactDepthPathFinder(PathExpanders.forDirection(Direction.OUTGOING), 5, Integer.MAX_VALUE, false).findAllPaths(a, g), "a,h,i,j,k,g");
}
Also used : Node(org.neo4j.graphdb.Node) ExactDepthPathFinder(org.neo4j.graphalgo.impl.path.ExactDepthPathFinder) Test(org.junit.Test)

Example 2 with ExactDepthPathFinder

use of org.neo4j.graphalgo.impl.path.ExactDepthPathFinder in project neo4j by neo4j.

the class TestExactDepthPathFinder method shouldHandleSimpleChainEvenDepth.

@Test
public void shouldHandleSimpleChainEvenDepth() {
    // (a) - (b) - (c)
    graph.makeEdgeChain("a,b,c");
    Node a = graph.getNode("a");
    Node c = graph.getNode("c");
    assertPaths(new ExactDepthPathFinder(PathExpanders.allTypesAndDirections(), 2, Integer.MAX_VALUE, false).findAllPaths(a, c), "a,b,c");
    assertPaths(new ExactDepthPathFinder(PathExpanders.allTypesAndDirections(), 2, Integer.MAX_VALUE, false).findAllPaths(a, c), "a,b,c");
}
Also used : Node(org.neo4j.graphdb.Node) ExactDepthPathFinder(org.neo4j.graphalgo.impl.path.ExactDepthPathFinder) Test(org.junit.Test)

Example 3 with ExactDepthPathFinder

use of org.neo4j.graphalgo.impl.path.ExactDepthPathFinder in project neo4j by neo4j.

the class TestExactDepthPathFinder method shouldHandleNondirectedGraph.

@Test
public void shouldHandleNondirectedGraph() {
    //     (b) ----------------- (c)      length 3
    //   /                          \
    // (a) - (h) - (i) - (j) - (k) - (g)  length 5
    //   \                          /
    //     (d) - (e) ------------ (f)     length 4
    graph.makeEdgeChain("a,b,c,g");
    graph.makeEdgeChain("a,d,e,f,g");
    graph.makeEdgeChain("a,h,i,j,k,g");
    Node a = graph.getNode("a");
    Node g = graph.getNode("g");
    assertPaths(new ExactDepthPathFinder(PathExpanders.allTypesAndDirections(), 3, Integer.MAX_VALUE, false).findAllPaths(a, g), "a,b,c,g");
    assertPaths(new ExactDepthPathFinder(PathExpanders.allTypesAndDirections(), 4, Integer.MAX_VALUE, false).findAllPaths(a, g), "a,d,e,f,g");
    assertPaths(new ExactDepthPathFinder(PathExpanders.allTypesAndDirections(), 5, Integer.MAX_VALUE, false).findAllPaths(a, g), "a,h,i,j,k,g");
}
Also used : Node(org.neo4j.graphdb.Node) ExactDepthPathFinder(org.neo4j.graphalgo.impl.path.ExactDepthPathFinder) Test(org.junit.Test)

Example 4 with ExactDepthPathFinder

use of org.neo4j.graphalgo.impl.path.ExactDepthPathFinder in project neo4j by neo4j.

the class TestExactDepthPathFinder method shouldHandleNeighbouringNodes.

@Test
public void shouldHandleNeighbouringNodes() {
    // (a) - (b)
    graph.makeEdgeChain("a,b");
    Node a = graph.getNode("a");
    Node b = graph.getNode("b");
    ExactDepthPathFinder pathFinder = new ExactDepthPathFinder(PathExpanders.allTypesAndDirections(), 1, Integer.MAX_VALUE, false);
    Iterable<Path> allPaths = pathFinder.findAllPaths(a, b);
    assertPaths(new ExactDepthPathFinder(PathExpanders.allTypesAndDirections(), 1, Integer.MAX_VALUE, false).findAllPaths(a, b), "a,b");
    assertPaths(new ExactDepthPathFinder(PathExpanders.allTypesAndDirections(), 1, Integer.MAX_VALUE, false).findAllPaths(a, b), "a,b");
}
Also used : Path(org.neo4j.graphdb.Path) Node(org.neo4j.graphdb.Node) ExactDepthPathFinder(org.neo4j.graphalgo.impl.path.ExactDepthPathFinder) Test(org.junit.Test)

Example 5 with ExactDepthPathFinder

use of org.neo4j.graphalgo.impl.path.ExactDepthPathFinder in project neo4j by neo4j.

the class TestExactDepthPathFinder method shouldHandleNeighbouringNodesMultiplePaths.

@Test
public void shouldHandleNeighbouringNodesMultiplePaths() {
    // (a) = (b)
    //  |
    // (c)
    graph.makeEdgeChain("a,b");
    graph.makeEdgeChain("a,b");
    graph.makeEdgeChain("a,c");
    Node a = graph.getNode("a");
    Node b = graph.getNode("b");
    ExactDepthPathFinder pathFinder = new ExactDepthPathFinder(PathExpanders.allTypesAndDirections(), 1, Integer.MAX_VALUE, false);
    Iterable<Path> allPaths = pathFinder.findAllPaths(a, b);
    assertPaths(new ExactDepthPathFinder(PathExpanders.allTypesAndDirections(), 1, Integer.MAX_VALUE, false).findAllPaths(a, b), "a,b", "a,b");
    assertPaths(new ExactDepthPathFinder(PathExpanders.allTypesAndDirections(), 1, Integer.MAX_VALUE, false).findAllPaths(a, b), "a,b", "a,b");
}
Also used : Path(org.neo4j.graphdb.Path) Node(org.neo4j.graphdb.Node) ExactDepthPathFinder(org.neo4j.graphalgo.impl.path.ExactDepthPathFinder) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)8 ExactDepthPathFinder (org.neo4j.graphalgo.impl.path.ExactDepthPathFinder)8 Node (org.neo4j.graphdb.Node)8 Path (org.neo4j.graphdb.Path)3