PathFinding { @Procedure @Description("apoc.algo.dijkstra(startNode, endNode, 'KNOWS|<WORKS_WITH|IS_MANAGER_OF>', 'distance', defaultValue, numberOfWantedResults) YIELD path," + " weight - run dijkstra with relationship property name as cost function") public Stream<WeightedPathResult> dijkstra( @Name("startNode") Node startNode, @Name("endNode") Node endNode, @Name("relationshipTypesAndDirections") String relTypesAndDirs, @Name("weightPropertyName") String weightPropertyName, @Name(value = "defaultWeight", defaultValue = "NaN") double defaultWeight, @Name(value = "numberOfWantedPaths", defaultValue = "1") long numberOfWantedPaths) { PathFinder<WeightedPath> algo = GraphAlgoFactory.dijkstra( buildPathExpander(relTypesAndDirs), (relationship, direction) -> Util.toDouble(relationship.getProperty(weightPropertyName, defaultWeight)), (int)numberOfWantedPaths ); return WeightedPathResult.streamWeightedPathResult(startNode, endNode, algo); }  @Procedure @Description("apoc.algo.aStar(startNode, endNode, 'KNOWS|<WORKS_WITH|IS_MANAGER_OF>', 'distance','lat','lon') " + "YIELD path, weight - run A* with relationship property name as cost function") Stream<WeightedPathResult> aStar(
            @Name("startNode") Node startNode,
            @Name("endNode") Node endNode,
            @Name("relationshipTypesAndDirections") String relTypesAndDirs,
            @Name("weightPropertyName") String weightPropertyName,
            @Name("latPropertyName") String latPropertyName,
            @Name("lonPropertyName") String lonPropertyName); @Procedure @Description("apoc.algo.aStar(startNode, endNode, 'KNOWS|<WORKS_WITH|IS_MANAGER_OF>', {weight:'dist',default:10," + "x:'lon',y:'lat'}) YIELD path, weight - run A* with relationship property name as cost function") Stream<WeightedPathResult> aStarConfig(
            @Name("startNode") Node startNode,
            @Name("endNode") Node endNode,
            @Name("relationshipTypesAndDirections") String relTypesAndDirs,
            @Name("config") Map<String, Object> config); @Procedure @Description("apoc.algo.dijkstra(startNode, endNode, 'KNOWS|<WORKS_WITH|IS_MANAGER_OF>', 'distance', defaultValue, numberOfWantedResults) YIELD path," + " weight - run dijkstra with relationship property name as cost function") Stream<WeightedPathResult> dijkstra(
            @Name("startNode") Node startNode,
            @Name("endNode") Node endNode,
            @Name("relationshipTypesAndDirections") String relTypesAndDirs,
            @Name("weightPropertyName") String weightPropertyName,
            @Name(value = "defaultWeight", defaultValue = "NaN") double defaultWeight,
            @Name(value = "numberOfWantedPaths", defaultValue = "1") long numberOfWantedPaths); @Procedure @Description("apoc.algo.allSimplePaths(startNode, endNode, 'KNOWS|<WORKS_WITH|IS_MANAGER_OF>', 5) YIELD path, " + "weight - run allSimplePaths with relationships given and maxNodes") Stream<PathResult> allSimplePaths(
            @Name("startNode") Node startNode,
            @Name("endNode") Node endNode,
            @Name("relationshipTypesAndDirections") String relTypesAndDirs,
            @Name("maxNodes") long maxNodes); @Procedure(deprecatedBy = "apoc.algo.dijkstra") @Description("apoc.algo.dijkstraWithDefaultWeight(startNode, endNode, 'KNOWS|<WORKS_WITH|IS_MANAGER_OF>', " + "'distance', 10) YIELD path, weight - run dijkstra with relationship property name as cost function" + " and a default weight if the property does not exist") @Deprecated Stream<WeightedPathResult> dijkstraWithDefaultWeight(
            @Name("startNode") Node startNode,
            @Name("endNode") Node endNode,
            @Name("relationshipTypesAndDirections") String relTypesAndDirs,
            @Name("weightPropertyName") String weightPropertyName,
            @Name("defaultWeight") double defaultWeight); @Context
    public GraphDatabaseService db; @Context
    public Transaction tx; }
@Test public void testDijkstra() { db.executeTransactionally(SETUP_SIMPLE); testCall(db, "MATCH (from:Loc{name:'A'}), (to:Loc{name:'D'}) " + "CALL apoc.algo.dijkstra(from, to, 'ROAD>', 'd') yield path, weight " + "RETURN path, weight" , row -> { assertEquals(50.0, row.get("weight")) ; assertEquals(2, ((Path)(row.get("path"))).length()) ; } ); testCall(db, "MATCH (from:Loc{name:'A'}), (to:Loc{name:'D'}) " + "CALL apoc.algo.dijkstra(from, to, '', 'd') yield path, weight " + "RETURN path, weight" , row -> { assertEquals(5.0, row.get("weight")) ; assertEquals(1, ((Path)(row.get("path"))).length()) ; } ); }