
52
|
第
4
章
Immingham [Immingham → 0, Colchester → 3, Hoek van Holland → 3]
Ipswich [Colchester → 1, Hoek van Holland → 2, Immingham → 4]
London [Colchester → 1, Immingham → 2, Hoek van Holland → 4]
Rotterdam [Hoek van Holland → 1, Immingham → 3, Colchester → 4]
Utrecht [Immingham → 2, Hoek van Holland → 3, Colchester → 5]
distances
列中每个地点旁边的数字表示从源节点到目的地所需穿越的城市之间的关系
(道路)数量。在本例中,
Colchester
是目的地之一,从它出发要穿越
0
个节点,但是从
Immingham
和
Hoek van Holland
出发就要经过
3
跳。在规划旅行路线时,利用这些信息有
助于我们在目的地尽情畅游。
4.5.4
使用
Neo4j
实现所有点对最短路径算法
Neo4j
提供了所有点对最短路径算法的并行实现,将返回每对节点之间的距离。
该程序的第
1
个参数用于计算最短加权路径的性质。如果将其设为
null
,那么算法将计算
所有节点对之间的无权最短路径。
查询实现如下:
CALL algo.allShortestPaths.stream(null)
YIELD sourceNodeId, ...