2016-06-10 69 views
0

我想在Neo4j中使用ShortestPath函數。neo4j shortestPath reduce函數返回null

該路由將通過具有LinkLength值的不同節點。對於2個節點之間的最短LinkLength,應該最小化「減少」部分中的值。

問題: Neo4j可以找到一條路徑作爲最短路徑的解決方案。令人驚訝的是,Neo4j表示reduce函數的值爲null。什麼是錯誤?

MATCH p = (n1:Node)-[:Connects*]->(n2:Node) 
WHERE n1.myid = 'M32 J3' AND n2.myid = 'M32 J1' 
RETURN p AS shortestPath, 
reduce(distance=0.0, n in nodes(p) | case n.LinkLength when NOT NULL then 
distance+toFloat(n.LinkLength) end) 
LIMIT 1; 

回答

0

您的case聲明沒有其他部分。不是100%確定,但我想在這種情況下,您將返回null作爲累加器值 - null + 1 == null

到TAKLE,正確的方法是先篩選出空值節點和事後申請reduce

MATCH p = (n1:Node)-[:Connects*]->(n2:Node) 
WHERE n1.myid = 'M32 J3' AND n2.myid = 'M32 J1' 
RETURN p AS shortestPath, 
reduce(distance=0.0, n in [x in nodes(p) WHERE n.LinkLength IS NOT NULL] | 
    distance+toFloat(n.LinkLength)) 
LIMIT 1; 

而且我猜你基本上要計算最短路徑加權。你的陳述只是獲得了找到的第一條路徑的重量。要有效地加權最短路徑,請看https://neo4j-contrib.github.io/neo4j-apoc-procedures/#_graph_algorithms_work_in_progress。 (記住:apoc需要Neo4j> = 3.0)。

+0

謝謝Stefan。 apoc可以在Windows機器上使用嗎?謝謝。 –

+0

在Windows 10計算機中,我下載了可執行jar文件apoc-1.0.0.jar並將該文件放入plugins文件夾。 然後我執行命令: CALL apoc.help(「apoc」),但是出現如下的錯誤機器:「沒有爲此數據庫實例註冊名爲apoc.help的過程。正確拼寫過程名稱,並且該過程已正確部署。「 –