我正在尝试为Dijkstra的搜索添加maxDepth。
我查看了apoc程序repo源代码,发现它们将PathFinder与startNode和enNode一起传递给WeightedPathResult.streamWeightedPathResult,后者调用PathFinder接口的findAllPaths方法来查找所有路径。
我需要更改findAllPaths方法中的代码,以便在path.length()> maxDepth时中断搜索。但问题是我无法在任何文件中找到此方法覆盖。
这是apoc dijkstra程序的片段
@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);
}
这是streamWeightedPathResult方法
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);
}}
他们从PathFinder接口调用findAllPaths方法,但它没有覆盖,所以我在哪里可以对此方法进行更改?
答案 0 :(得分:1)
findAllPaths()
方法在neo4j库中实现,而不是在APOC代码中实现。
正如您的代码段显示的那样,this overloaded version of org.neo4j.graphalgo.GraphAlgoFactory.dijkstra()
返回了特定的algo
实例,它返回org.neo4j.graphalgo.impl.path.Dijkstra的实例,该实例实现了findAllPaths()方法。
(以上链接全部用于neo4j库的3.4版本。)