Search in sources :

Example 46 with BasicEvaluationContext

use of org.neo4j.graphalgo.BasicEvaluationContext in project neo4j by neo4j.

the class TestExactDepthPathFinder method shouldHandleSimpleChainOddDepth.

@Test
void shouldHandleSimpleChainOddDepth() {
    // (a) - (b) - (c) - (d)
    try (Transaction transaction = graphDb.beginTx()) {
        graph.makeEdgeChain(transaction, "a,b,c,d");
        Node a = graph.getNode(transaction, "a");
        Node d = graph.getNode(transaction, "d");
        var context = new BasicEvaluationContext(transaction, graphDb);
        assertPaths(new ExactDepthPathFinder(context, allTypesAndDirections(), 3, Integer.MAX_VALUE, false).findAllPaths(a, d), "a,b,c,d");
        assertPaths(new ExactDepthPathFinder(context, allTypesAndDirections(), 3, Integer.MAX_VALUE, false).findAllPaths(a, d), "a,b,c,d");
        transaction.commit();
    }
}
Also used : BasicEvaluationContext(org.neo4j.graphalgo.BasicEvaluationContext) Transaction(org.neo4j.graphdb.Transaction) Node(org.neo4j.graphdb.Node) ExactDepthPathFinder(org.neo4j.graphalgo.impl.path.ExactDepthPathFinder) Test(org.junit.jupiter.api.Test)

Example 47 with BasicEvaluationContext

use of org.neo4j.graphalgo.BasicEvaluationContext in project neo4j by neo4j.

the class TestExactDepthPathFinder method testSingle.

@Test
void testSingle() {
    try (Transaction transaction = graphDb.beginTx()) {
        final Set<String> possiblePaths = new HashSet<>();
        possiblePaths.add("SOURCE,z,9,0,TARGET");
        possiblePaths.add("SOURCE,SUPER,r,SPIDER,TARGET");
        createGraph(transaction);
        var context = new BasicEvaluationContext(transaction, graphDb);
        PathFinder<Path> finder = newFinder(context);
        Path path = finder.findSinglePath(graph.getNode(transaction, "SOURCE"), graph.getNode(transaction, "TARGET"));
        assertNotNull(path);
        assertThat(getPathDef(path)).isIn(possiblePaths);
        assertTrue(possiblePaths.contains(getPathDef(path)));
        transaction.commit();
    }
}
Also used : Path(org.neo4j.graphdb.Path) BasicEvaluationContext(org.neo4j.graphalgo.BasicEvaluationContext) Transaction(org.neo4j.graphdb.Transaction) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Example 48 with BasicEvaluationContext

use of org.neo4j.graphalgo.BasicEvaluationContext in project neo4j by neo4j.

the class TestExactDepthPathFinder method shouldHandleNeighbouringNodesWhenNotAlone.

@Test
void shouldHandleNeighbouringNodesWhenNotAlone() {
    // (c)
    try (Transaction transaction = graphDb.beginTx()) {
        graph.makeEdge(transaction, "a", "b");
        graph.makeEdge(transaction, "a", "c");
        Node a = graph.getNode(transaction, "a");
        Node b = graph.getNode(transaction, "b");
        var context = new BasicEvaluationContext(transaction, graphDb);
        ExactDepthPathFinder pathFinder = new ExactDepthPathFinder(context, allTypesAndDirections(), 1, Integer.MAX_VALUE, false);
        Iterable<Path> allPaths = pathFinder.findAllPaths(a, b);
        assertPaths(new ExactDepthPathFinder(context, allTypesAndDirections(), 1, Integer.MAX_VALUE, false).findAllPaths(a, b), "a,b");
        assertPaths(new ExactDepthPathFinder(context, allTypesAndDirections(), 1, Integer.MAX_VALUE, false).findAllPaths(a, b), "a,b");
        transaction.commit();
    }
}
Also used : Path(org.neo4j.graphdb.Path) BasicEvaluationContext(org.neo4j.graphalgo.BasicEvaluationContext) Transaction(org.neo4j.graphdb.Transaction) Node(org.neo4j.graphdb.Node) ExactDepthPathFinder(org.neo4j.graphalgo.impl.path.ExactDepthPathFinder) Test(org.junit.jupiter.api.Test)

Example 49 with BasicEvaluationContext

use of org.neo4j.graphalgo.BasicEvaluationContext in project neo4j by neo4j.

the class TestExactDepthPathFinder method shouldHandleNeighbouringNodesMultiplePaths.

@Test
void shouldHandleNeighbouringNodesMultiplePaths() {
    // (c)
    try (Transaction transaction = graphDb.beginTx()) {
        graph.makeEdgeChain(transaction, "a,b");
        graph.makeEdgeChain(transaction, "a,b");
        graph.makeEdgeChain(transaction, "a,c");
        Node a = graph.getNode(transaction, "a");
        Node b = graph.getNode(transaction, "b");
        var context = new BasicEvaluationContext(transaction, graphDb);
        ExactDepthPathFinder pathFinder = new ExactDepthPathFinder(context, allTypesAndDirections(), 1, Integer.MAX_VALUE, false);
        Iterable<Path> allPaths = pathFinder.findAllPaths(a, b);
        assertPaths(new ExactDepthPathFinder(context, allTypesAndDirections(), 1, Integer.MAX_VALUE, false).findAllPaths(a, b), "a,b", "a,b");
        assertPaths(new ExactDepthPathFinder(context, allTypesAndDirections(), 1, Integer.MAX_VALUE, false).findAllPaths(a, b), "a,b", "a,b");
        transaction.commit();
    }
}
Also used : Path(org.neo4j.graphdb.Path) BasicEvaluationContext(org.neo4j.graphalgo.BasicEvaluationContext) Transaction(org.neo4j.graphdb.Transaction) Node(org.neo4j.graphdb.Node) ExactDepthPathFinder(org.neo4j.graphalgo.impl.path.ExactDepthPathFinder) Test(org.junit.jupiter.api.Test)

Example 50 with BasicEvaluationContext

use of org.neo4j.graphalgo.BasicEvaluationContext in project neo4j by neo4j.

the class TestExactDepthPathFinder method shouldHandleNondirectedGraph.

@Test
void shouldHandleNondirectedGraph() {
    // (d) - (e) ------------ (f)     length 4
    try (Transaction transaction = graphDb.beginTx()) {
        graph.makeEdgeChain(transaction, "a,b,c,g");
        graph.makeEdgeChain(transaction, "a,d,e,f,g");
        graph.makeEdgeChain(transaction, "a,h,i,j,k,g");
        Node a = graph.getNode(transaction, "a");
        Node g = graph.getNode(transaction, "g");
        var context = new BasicEvaluationContext(transaction, graphDb);
        assertPaths(new ExactDepthPathFinder(context, allTypesAndDirections(), 3, Integer.MAX_VALUE, false).findAllPaths(a, g), "a,b,c,g");
        assertPaths(new ExactDepthPathFinder(context, allTypesAndDirections(), 4, Integer.MAX_VALUE, false).findAllPaths(a, g), "a,d,e,f,g");
        assertPaths(new ExactDepthPathFinder(context, allTypesAndDirections(), 5, Integer.MAX_VALUE, false).findAllPaths(a, g), "a,h,i,j,k,g");
        transaction.commit();
    }
}
Also used : BasicEvaluationContext(org.neo4j.graphalgo.BasicEvaluationContext) Transaction(org.neo4j.graphdb.Transaction) Node(org.neo4j.graphdb.Node) ExactDepthPathFinder(org.neo4j.graphalgo.impl.path.ExactDepthPathFinder) Test(org.junit.jupiter.api.Test)

Aggregations

BasicEvaluationContext (org.neo4j.graphalgo.BasicEvaluationContext)52 Transaction (org.neo4j.graphdb.Transaction)52 Node (org.neo4j.graphdb.Node)40 Test (org.junit.jupiter.api.Test)33 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)20 MethodSource (org.junit.jupiter.params.provider.MethodSource)20 WeightedPath (org.neo4j.graphalgo.WeightedPath)20 Path (org.neo4j.graphdb.Path)18 ExactDepthPathFinder (org.neo4j.graphalgo.impl.path.ExactDepthPathFinder)8 Relationship (org.neo4j.graphdb.Relationship)8 HashSet (java.util.HashSet)5 PathExpander (org.neo4j.graphdb.PathExpander)5 GraphAlgoFactory.shortestPath (org.neo4j.graphalgo.GraphAlgoFactory.shortestPath)4 Neo4jAlgoTestCase (common.Neo4jAlgoTestCase)3 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)3 EvaluationContext (org.neo4j.graphalgo.EvaluationContext)3 PathFinder (org.neo4j.graphalgo.PathFinder)3 OUTGOING (org.neo4j.graphdb.Direction.OUTGOING)3 Label (org.neo4j.graphdb.Label)3 PathExpanders.allTypesAndDirections (org.neo4j.graphdb.PathExpanders.allTypesAndDirections)3