简体   繁体   English

计算2个节点之间的所有关系

[英]Compute all the relationships between 2 nodes

I am trying to calculate all the relationships between 2 nodes: 我正在尝试计算2个节点之间的所有关系:

For me the shortestpath , allshortestpaths and apoc.algo.dijkstra work perfectly. 对我而言, 最短路径所有 最短 路径apoc.algo.dijkstra都可以正常工作。 But these don't fetch all relationships between 2 nodes. 但是这些不能获取2个节点之间的所有关系。

This is my query which works very fast: 这是我的查询,它的运行速度非常快:

MATCH (s:Stop)--(st:Stoptime), (e:Stop)--(et:Stoptime)    
WHERE s.name IN [ 'Schlump', 'U Schlump'] 
    AND e.name IN ['Hauptbahnhof Süd', 'HBF/Steintorwall' , 'Hamburg Hbf']
        AND st.arrival_time < et.departure_time 

MATCH p = allshortestpaths((st)-[r:PRECEDES*]->(et))
RETURN p

But when I remove the allshortestpaths and see all relationships, it takes forever. 但是,当我删除所有最短路径并看到所有关系时,它将永远存在。

I tried breaking the query into multiple queries as displayed below but it is also taking a lot of time. 我尝试将查询分为多个查询,如下所示,但是这也花费了很多时间。

MATCH (s:Stop)--(st:Stoptime), (e:Stop)--(et:Stoptime)    

MATCH p1 = (st)-[r1*..4]-(st2:Stoptime),
 p2 = (st2:Stoptime)-[r2*..4]-(st3:Stoptime),
 p3 = (st4:Stoptime)-[r3*..4]-(st5:Stoptime),
 p4 = (st5:Stoptime)-[r4*..4]-(et:Stoptime)
 WHERE s.name IN [ 'Schlump', 'U Schlump'] 
    AND e.name IN ['Hauptbahnhof Süd', 'HBF/Steintorwall' , 'Hamburg Hbf']
 AND all(x1 in nodes(p1) WHERE (x1:Stoptime)) 
 AND all(x2 in nodes(p2) WHERE (x2:Stoptime)) 
  AND all(x3 in nodes(p3) WHERE (x3:Stoptime)) 
   AND all(x4 in nodes(p4) WHERE (x4:Stoptime)) 
RETURN r1, r2, r3, r4

What should I do? 我该怎么办? How can I find all relationships between certain nodes? 如何找到某些节点之间的所有关系?

It depends on the graph structure if it is feasible to return all paths between two nodes. 返回两个节点之间的所有路径是否可行取决于图形结构。

If you have circular structure or a dense graph, there will be very large number of paths between two nodes. 如果您具有圆形结构或密集图,则两个节点之间的路径将非常多。 See this question for more insights: Find all paths between two graph nodes 有关更多信息,请参见此问题: 查找两个图节点之间的所有路径

A graph of a public transport system will be very dense I assume. 我认为公共交通系统的图表非常密集。 Thus, returning all paths between two stations does not work because of graph theory (not because of unoptimized queries). 因此,由于图论(而不是由于未优化的查询),返回两个工作站之间的所有路径都不起作用。

You have to figure out why exactly you need all paths and if you can formulate that query differently or with some constraints (eg maximim length). 您必须弄清楚为什么确实需要所有路径,以及是否可以用不同的方式或有一些约束(例如最大长度)来表示该查询。 Also, your graph struture might not be suitable to answer your question if you acutally need all paths. 同样,如果您确实需要所有路径,那么您的图形结构可能不适合回答您的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM