0

I am trying to add a maxDepth for Dijkstra's search. I've looked in the apoc procedures repo source code and found out that they pass the PathFinder alongside the startNode and enNode in WeightedPathResult.streamWeightedPathResult which calls the findAllPaths method of PathFinder interface to find all paths. I need to change the code in findAllPaths methods in order to break the search when path.length()>maxDepth.But the probleme is that i can't find this methode overrode in any files. here is a snippet of the apoc dijkstra procedure @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);
}

And here is the streamWeightedPathResult method

 public static Stream<WeightedPathResult> streamWeightedPathResult(Node startNode, Node endNode, PathFinder<WeightedPath> algo) {
    Iterable<WeightedPath> allPaths = algo.findAllPaths(startNode, endNode);
    return StreamSupport.stream(allPaths.spliterator(), false)
            .map(WeightedPathResult::new);
}}

They call the findAllPaths method from the PathFinder interface but it was not overrode so where can i do the changes on this method??

1 Answers1

1

The findAllPaths() method is implemented in the neo4j library, not in the APOC code.

As your code snippets show, that particular algo instance is returned by this overloaded version of org.neo4j.graphalgo.GraphAlgoFactory.dijkstra(), which returns an instance of org.neo4j.graphalgo.impl.path.Dijkstra, which implements the findAllPaths() method.

(The above links are all for version 3.4 of the neo4j library.)

cybersam
  • 63,203
  • 6
  • 53
  • 76
  • Thank you but where do you suggest that i add the maxDepth condition so that Dijkstra would break if it exceeds the max number of nodes traversed?? should i change in the traverser method? in the link you gave me? – KhribiHamza Apr 19 '18 at 22:54