use of org.neo4j.graphdb.Path in project neo4j by neo4j.
the class TestAllSimplePaths 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");
PathFinder<Path> finder = instantiatePathFinder(new BasicEvaluationContext(transaction, graphDb), 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");
transaction.commit();
}
}
use of org.neo4j.graphdb.Path in project neo4j by neo4j.
the class TestBidirectionalTraversal method mirroredTraversalReversesInitialState.
@Test
void mirroredTraversalReversesInitialState() {
/*
* (a)-->(b)-->(c)-->(d)
*/
createGraph("a TO b", "b TO c", "c TO d");
try (Transaction transaction = getGraphDb().beginTx()) {
BranchCollisionPolicy collisionPolicy = (evaluator, pathPredicate) -> new StandardBranchCollisionDetector(null, null) {
@Override
protected boolean includePath(Path path, TraversalBranch startPath, TraversalBranch endPath) {
assertEquals(0, startPath.state());
assertEquals(10, endPath.state());
return true;
}
};
Iterables.count(transaction.bidirectionalTraversalDescription().mirroredSides(transaction.traversalDescription().uniqueness(NODE_PATH).expand(PathExpanders.forType(to), new InitialBranchState.State<>(0, 10))).collisionPolicy(collisionPolicy).traverse(getNodeWithName(transaction, "a"), getNodeWithName(transaction, "d")));
}
}
use of org.neo4j.graphdb.Path in project neo4j by neo4j.
the class Neo4jAlgoTestCase method assertPaths.
private static void assertPaths(Iterable<? extends Path> paths, List<String> pathDefs) {
List<String> unexpectedDefs = new ArrayList<>();
try (ResourceIterator<? extends Path> iterator = Iterators.asResourceIterator(paths.iterator())) {
while (iterator.hasNext()) {
Path path = iterator.next();
String pathDef = getPathDef(path);
int index = pathDefs.indexOf(pathDef);
if (index != -1) {
pathDefs.remove(index);
} else {
unexpectedDefs.add(getPathDef(path));
}
}
}
assertTrue(unexpectedDefs.isEmpty(), "These unexpected paths were found: " + unexpectedDefs + ". In addition these expected paths weren't found:" + pathDefs);
assertTrue(pathDefs.isEmpty(), "These were expected, but not found: " + pathDefs);
}
use of org.neo4j.graphdb.Path in project neo4j by neo4j.
the class TestTopFetchingWeightedPathIterator method shouldHandleMultipleShortest.
@Test
void shouldHandleMultipleShortest() {
try (Transaction transaction = graphDb.beginTx()) {
Path a = graph.makePathWithRelProperty(transaction, length, "a1-1-a2");
Path b = graph.makePathWithRelProperty(transaction, length, "b1-0-b2-1-b3-0-b4");
List<Path> list = new ArrayList<>();
list.add(a);
list.add(b);
topFetcher = new TopFetchingWeightedPathIterator(list.iterator(), evaluator, DEFAULT_EPSILON);
List<Path> result = new ArrayList<>();
while (topFetcher.hasNext()) {
result.add(topFetcher.next());
}
assertPathsWithPaths(result, a, b);
transaction.commit();
}
}
use of org.neo4j.graphdb.Path in project neo4j by neo4j.
the class TestPath method reverseNodes.
@Test
void reverseNodes() {
try (Transaction transaction = getGraphDb().beginTx()) {
a = transaction.getNodeById(a.getId());
Traverser traverse = transaction.traversalDescription().evaluator(atDepth(0)).traverse(a);
Path path = getFirstPath(traverse);
assertContains(path.reverseNodes(), a);
Traverser traverse2 = transaction.traversalDescription().evaluator(atDepth(4)).traverse(a);
Path path2 = getFirstPath(traverse2);
assertContainsInOrder(path2.reverseNodes(), e, d, c, b, a);
}
}
Aggregations