use of org.neo4j.graphdb.Path in project graphdb by neo4j-attic.
the class ExactDepthPathFinder method toPath.
private Path toPath(Path[] found, Node start) {
Path startPath = found[0];
Path endPath = found[1];
if (!startPath.startNode().equals(start)) {
Path tmpPath = startPath;
startPath = endPath;
endPath = tmpPath;
}
return toBuilder(startPath).build(toBuilder(endPath));
}
use of org.neo4j.graphdb.Path in project graphdb by neo4j-attic.
the class ExperimentalAStar method findAllPaths.
public Iterable<WeightedPath> findAllPaths(Node start, final Node end) {
Predicate<Path> filter = new Predicate<Path>() {
public boolean accept(Path position) {
return position.endNode().equals(end);
}
};
final Traverser traverser = traversalDescription.order(new SelectorFactory(end)).filter(filter).traverse(start);
return new Iterable<WeightedPath>() {
public Iterator<WeightedPath> iterator() {
return new StopAfterWeightIterator(traverser.iterator(), costEvaluator);
}
};
}
use of org.neo4j.graphdb.Path in project graphdb by neo4j-attic.
the class PathFindingExamplesTest method shortestPathExample.
@Test
public void shortestPathExample() {
// START SNIPPET: shortestPathUsage
Node startNode = graphDb.createNode();
Node middleNode1 = graphDb.createNode();
Node middleNode2 = graphDb.createNode();
Node middleNode3 = graphDb.createNode();
Node endNode = graphDb.createNode();
createRelationshipsBetween(startNode, middleNode1, endNode);
createRelationshipsBetween(startNode, middleNode2, middleNode3, endNode);
// Will find the shortest path between startNode and endNode via
// "MY_TYPE" relationships (in OUTGOING direction), like f.ex:
//
// (startNode)-->(middleNode1)-->(endNode)
//
PathFinder<Path> finder = GraphAlgoFactory.shortestPath(Traversal.expanderForTypes(ExampleTypes.MY_TYPE, Direction.OUTGOING), 15);
Iterable<Path> paths = finder.findAllPaths(startNode, endNode);
// END SNIPPET: shortestPathUsage
Path path = paths.iterator().next();
assertEquals(2, path.length());
assertEquals(startNode, path.startNode());
assertEquals(endNode, path.endNode());
Iterator<Node> iterator = path.nodes().iterator();
iterator.next();
assertEquals(middleNode1, iterator.next());
}
use of org.neo4j.graphdb.Path in project graphdb by neo4j-attic.
the class TestMultiPruneEvaluators method makeSurePruneIsntCalledForStartNode.
@Test
public void makeSurePruneIsntCalledForStartNode() {
final boolean[] calledForStartPosition = new boolean[1];
PruneEvaluator evaluator = new PruneEvaluator() {
public boolean pruneAfter(Path position) {
if (position.length() == 0) {
calledForStartPosition[0] = true;
}
return false;
}
};
IteratorUtil.lastOrNull(Traversal.description().prune(evaluator).traverse(referenceNode()));
assertFalse(calledForStartPosition[0]);
}
use of org.neo4j.graphdb.Path in project graphdb by neo4j-attic.
the class TestMultiRelTypesAndDirections method testCIsReturnedOnDepthTwo.
private void testCIsReturnedOnDepthTwo(TraversalDescription description) {
description = description.relationships(ONE, Direction.OUTGOING);
int i = 0;
for (Path position : description.traverse(referenceNode())) {
assertEquals(i++, position.length());
}
}
Aggregations