use of org.neo4j.graphalgo.PathFinder in project neo4j by neo4j.
the class DijkstraTest method canContinueGettingPathsByDiminishingCost.
@Test
public void canContinueGettingPathsByDiminishingCost() throws Exception {
/*
* NODE (NAME/INDEX)
*
* (A)-*2->(B)-*3->(C)-*1->(D)
* | \ ^ ^
* | ----*5-----/ |
* \ |
* ---------*6-----------
*/
Node nodeA = graph.makeNode("A");
graph.makeNode("B");
graph.makeNode("C");
Node nodeD = graph.makeNode("D");
// Path "1"
graph.makeEdge("A", "B", "length", 2d);
graph.makeEdge("B", "C", "length", 3L);
// = 6
graph.makeEdge("C", "D", "length", (byte) 1);
// Path "2"
// = 7
graph.makeEdge("B", "D", "length", (short) 5);
// Path "3"
// = 6
graph.makeEdge("A", "D", "length", (float) 6);
PathFinder finder = factory.dijkstra(PathExpanders.allTypesAndDirections());
assertPaths(finder.findAllPaths(nodeA, nodeD), "A,B,C,D", "A,D");
}
use of org.neo4j.graphalgo.PathFinder in project neo4j by neo4j.
the class DatabaseActions method findPaths.
@SuppressWarnings({ "rawtypes", "unchecked" })
public ListRepresentation findPaths(long startId, long endId, Map<String, Object> map) {
final FindParams findParams = new FindParams(startId, endId, map).invoke();
PathFinder finder = findParams.getFinder();
Node startNode = findParams.getStartNode();
Node endNode = findParams.getEndNode();
Iterable paths = finder.findAllPaths(startNode, endNode);
IterableWrapper<PathRepresentation, Path> pathRepresentations = new IterableWrapper<PathRepresentation, Path>(paths) {
@Override
protected PathRepresentation underlyingObjectToObject(Path path) {
return findParams.pathRepresentationOf(path);
}
};
return new ListRepresentation(RepresentationType.PATH, pathRepresentations);
}
Aggregations