use of org.neo4j.graphalgo.BasicEvaluationContext in project neo4j by neo4j.
the class TestExactDepthPathFinder method testExactDepthFinder.
@Test
void testExactDepthFinder() {
//
try (Transaction transaction = graphDb.beginTx()) {
graph.makeEdgeChain(transaction, "a,c,g,k");
graph.makeEdgeChain(transaction, "a,b,d,j,k");
graph.makeEdgeChain(transaction, "b,e,f,h,i,j");
graph.makeEdgeChain(transaction, "d,h");
PathExpander<Object> expander = PathExpanders.forTypeAndDirection(MyRelTypes.R1, Direction.OUTGOING);
Node a = graph.getNode(transaction, "a");
Node k = graph.getNode(transaction, "k");
var context = new BasicEvaluationContext(transaction, graphDb);
assertPaths(pathsWithLength(context, expander, 3).findAllPaths(a, k), "a,c,g,k");
assertPaths(pathsWithLength(context, expander, 4).findAllPaths(a, k), "a,b,d,j,k");
assertPaths(pathsWithLength(context, expander, 5).findAllPaths(a, k));
assertPaths(pathsWithLength(context, expander, 6).findAllPaths(a, k), "a,b,d,h,i,j,k");
assertPaths(pathsWithLength(context, expander, 7).findAllPaths(a, k), "a,b,e,f,h,i,j,k");
assertPaths(pathsWithLength(context, expander, 8).findAllPaths(a, k));
transaction.commit();
}
}
use of org.neo4j.graphalgo.BasicEvaluationContext in project neo4j by neo4j.
the class TestExactDepthPathFinder method shouldHandleSimpleChainEvenDepth.
@Test
void shouldHandleSimpleChainEvenDepth() {
// (a) - (b) - (c)
try (Transaction transaction = graphDb.beginTx()) {
graph.makeEdgeChain(transaction, "a,b,c");
Node a = graph.getNode(transaction, "a");
Node c = graph.getNode(transaction, "c");
var context = new BasicEvaluationContext(transaction, graphDb);
assertPaths(new ExactDepthPathFinder(context, allTypesAndDirections(), 2, Integer.MAX_VALUE, false).findAllPaths(a, c), "a,b,c");
assertPaths(new ExactDepthPathFinder(context, allTypesAndDirections(), 2, Integer.MAX_VALUE, false).findAllPaths(a, c), "a,b,c");
transaction.commit();
}
}
use of org.neo4j.graphalgo.BasicEvaluationContext in project neo4j by neo4j.
the class TestShortestPath method testAnotherSimpleGraph.
@Test
void testAnotherSimpleGraph() {
// (n)---(p)---(q)
try (Transaction transaction = graphDb.beginTx()) {
graph.makeEdge(transaction, "s", "m");
graph.makeEdge(transaction, "m", "o");
graph.makeEdge(transaction, "s", "n");
graph.makeEdge(transaction, "n", "p");
graph.makeEdge(transaction, "p", "q");
graph.makeEdge(transaction, "q", "t");
graph.makeEdge(transaction, "n", "o");
graph.makeEdge(transaction, "o", "t");
var context = new BasicEvaluationContext(transaction, graphDb);
testShortestPathFinder(context, finder -> {
final Iterable<Path> paths = finder.findAllPaths(graph.getNode(transaction, "s"), graph.getNode(transaction, "t"));
assertPaths(paths, "s,m,o,t", "s,n,o,t");
}, forTypeAndDirection(R1, BOTH), 6);
transaction.commit();
}
}
use of org.neo4j.graphalgo.BasicEvaluationContext in project neo4j by neo4j.
the class TestShortestPath method shouldFindShortestPathWhenOneSideFindsLongerPathFirst.
@Test
void shouldFindShortestPathWhenOneSideFindsLongerPathFirst() {
/*
The order in which nodes are created matters when reproducing the original problem
*/
try (Transaction transaction = graphDb.beginTx()) {
graph.makeEdge(transaction, "start", "c");
graph.makeEdge(transaction, "start", "a");
graph.makeEdge(transaction, "b", "end");
graph.makeEdge(transaction, "d", "end");
graph.makeEdge(transaction, "c", "e");
graph.makeEdge(transaction, "f", "end");
graph.makeEdge(transaction, "c", "b");
graph.makeEdge(transaction, "e", "end");
graph.makeEdge(transaction, "a", "end");
final Node start = graph.getNode(transaction, "start");
final Node end = graph.getNode(transaction, "end");
var context = new BasicEvaluationContext(transaction, graphDb);
assertThat(new ShortestPath(context, 2, allTypesAndDirections(), 42, EmptyMemoryTracker.INSTANCE).findSinglePath(start, end).length()).isEqualTo(2);
assertThat(new ShortestPath(context, 3, allTypesAndDirections(), 42, EmptyMemoryTracker.INSTANCE).findSinglePath(start, end).length()).isEqualTo(2);
transaction.commit();
}
}
use of org.neo4j.graphalgo.BasicEvaluationContext in project neo4j by neo4j.
the class TestShortestPath method unfortunateRelationshipOrderingInTriangle.
@Test
void unfortunateRelationshipOrderingInTriangle() {
/*
* (b)
* ^ \
* / v
* (a)---->(c)
*
* Relationships are created in such a way that they are iterated in the worst order,
* i.e. (S) a-->b, (E) c<--b, (S) a-->c
*/
try (Transaction transaction = graphDb.beginTx()) {
graph.makeEdgeChain(transaction, "a,b,c");
graph.makeEdgeChain(transaction, "a,c");
final Node a = graph.getNode(transaction, "a");
final Node c = graph.getNode(transaction, "c");
var context = new BasicEvaluationContext(transaction, graphDb);
testShortestPathFinder(context, finder -> assertPathDef(finder.findSinglePath(a, c), "a", "c"), forTypeAndDirection(R1, OUTGOING), 2);
testShortestPathFinder(context, finder -> assertPathDef(finder.findSinglePath(c, a), "c", "a"), forTypeAndDirection(R1, INCOMING), 2);
transaction.commit();
}
}
Aggregations