use of org.neo4j.graphalgo.BasicEvaluationContext in project neo4j by neo4j.
the class TestAllPaths method testTripleRelationshipGraph.
@Test
void testTripleRelationshipGraph() {
/* Layout
* ___
* (a)---(b)===(c)---(d)
*/
try (Transaction transaction = graphDb.beginTx()) {
graph.makeEdge(transaction, "a", "b");
graph.makeEdge(transaction, "b", "c");
graph.makeEdge(transaction, "b", "c");
graph.makeEdge(transaction, "b", "c");
graph.makeEdge(transaction, "c", "d");
var context = new BasicEvaluationContext(transaction, graphDb);
PathFinder<Path> finder = instantiatePathFinder(context, 10);
Iterable<Path> paths = finder.findAllPaths(graph.getNode(transaction, "a"), graph.getNode(transaction, "d"));
assertPaths(paths, "a,b,c,d", "a,b,c,d", "a,b,c,d", "a,b,c,b,c,d", "a,b,c,b,c,d", "a,b,c,b,c,d", "a,b,c,b,c,d", "a,b,c,b,c,d", "a,b,c,b,c,d");
transaction.commit();
}
}
use of org.neo4j.graphalgo.BasicEvaluationContext in project neo4j by neo4j.
the class TestAllPaths method testCircularGraph.
@Test
void testCircularGraph() {
/* Layout
*
* (a)---(b)===(c)---(e)
* \ /
* (d)
*/
try (Transaction transaction = graphDb.beginTx()) {
graph.makeEdge(transaction, "a", "b");
graph.makeEdge(transaction, "b", "c");
graph.makeEdge(transaction, "b", "c");
graph.makeEdge(transaction, "b", "d");
graph.makeEdge(transaction, "c", "d");
graph.makeEdge(transaction, "c", "e");
var context = new BasicEvaluationContext(transaction, graphDb);
PathFinder<Path> finder = instantiatePathFinder(context, 10);
Iterable<Path> paths = finder.findAllPaths(graph.getNode(transaction, "a"), graph.getNode(transaction, "e"));
assertPaths(paths, "a,b,c,e", "a,b,c,e", "a,b,d,c,e", "a,b,c,d,b,c,e", "a,b,c,d,b,c,e", "a,b,c,b,d,c,e", "a,b,c,b,d,c,e", "a,b,d,c,b,c,e", "a,b,d,c,b,c,e");
transaction.commit();
}
}
use of org.neo4j.graphalgo.BasicEvaluationContext in project neo4j by neo4j.
the class TestExactDepthPathFinder method shouldHandleDirectionalGraph.
@Test
void shouldHandleDirectionalGraph() {
// (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, forDirection(Direction.OUTGOING), 3, Integer.MAX_VALUE, false).findAllPaths(a, g), "a,b,c,g");
assertPaths(new ExactDepthPathFinder(context, forDirection(Direction.OUTGOING), 4, Integer.MAX_VALUE, false).findAllPaths(a, g), "a,d,e,f,g");
assertPaths(new ExactDepthPathFinder(context, forDirection(Direction.OUTGOING), 5, Integer.MAX_VALUE, false).findAllPaths(a, g), "a,h,i,j,k,g");
transaction.commit();
}
}
use of org.neo4j.graphalgo.BasicEvaluationContext in project neo4j by neo4j.
the class TestExactDepthPathFinder method testExactDepthPathsReturnsNoLoops.
@Test
void testExactDepthPathsReturnsNoLoops() {
//
try (Transaction transaction = graphDb.beginTx()) {
graph.makeEdgeChain(transaction, "a,b,c,d,b,c,e");
Node a = graph.getNode(transaction, "a");
Node e = graph.getNode(transaction, "e");
var context = new BasicEvaluationContext(transaction, graphDb);
assertPaths(pathsWithLength(context, PathExpanders.forType(MyRelTypes.R1), 3).findAllPaths(a, e), "a,b,c,e", "a,b,c,e");
assertPaths(pathsWithLength(context, PathExpanders.forType(MyRelTypes.R1), 4).findAllPaths(a, e), "a,b,d,c,e");
assertPaths(pathsWithLength(context, PathExpanders.forType(MyRelTypes.R1), 6).findAllPaths(a, e));
transaction.commit();
}
}
use of org.neo4j.graphalgo.BasicEvaluationContext in project neo4j by neo4j.
the class TestExactDepthPathFinder method testAll.
@Test
void testAll() {
try (Transaction transaction = graphDb.beginTx()) {
createGraph(transaction);
var context = new BasicEvaluationContext(transaction, graphDb);
PathFinder<Path> finder = newFinder(context);
assertPaths(finder.findAllPaths(graph.getNode(transaction, "SOURCE"), graph.getNode(transaction, "TARGET")), "SOURCE,z,9,0,TARGET", "SOURCE,SUPER,r,SPIDER,TARGET");
transaction.commit();
}
}
Aggregations