Neo4j中加权有向图的最短路径

ctehm74n  于 11个月前  发布在  其他
关注(0)|答案(1)|浏览(149)

我在Neo4j中使用OpenStreetMap和OpenData创建了一个城市Map。我想找到从一个地址到另一个地址的最短路径。问题是,当我使用函数apoc.algo.aStarConfig时,我得到的路径没有考虑关系的方向。

MATCH (a:Address)-[:NEAREST_INTERSECTION]->(source:Intersection)
WHERE a.full_address CONTAINS "410 E 5TH AVE SAN MATEO, CA"
MATCH (poi:Address)-[:NEAREST_INTERSECTION]->(dest:Intersection) 
WHERE poi.full_address CONTAINS "39 GRAND BLVD SAN MATEO, CA"
CALL apoc.algo.aStarConfig(source, dest, "ROAD_SEGMENT", 
  {pointPropName: "location", weight: "length"}) 
YIELD weight, path
RETURN *

字符串
Result of the query

所以我的问题是,是否有可能找到从一条路径到另一条路径的最短路径,而不考虑上游的相对论?

0h4hbjxa

0h4hbjxa1#

如果你只想找到关系在一个方向上的路径,例如出站,你可以在入站的关系类型前加上<,或者在出站的关系类型后加上>
要只跟踪出站ROAD_SEGMENT关系,您的查询将变为:

MATCH (a:Address)-[:NEAREST_INTERSECTION]->(source:Intersection)
WHERE a.full_address CONTAINS "410 E 5TH AVE SAN MATEO, CA"
MATCH (poi:Address)-[:NEAREST_INTERSECTION]->(dest:Intersection) 
WHERE poi.full_address CONTAINS "39 GRAND BLVD SAN MATEO, CA"
CALL apoc.algo.aStarConfig(source, dest, "ROAD_SEGMENT>", 
  {pointPropName: "location", weight: "length"}) 
YIELD weight, path
RETURN *

字符串

相关问题