neo4j查找符合特定条件的所有路径 [英] neo4j finding all paths that meets a certain criteria

查看:910
本文介绍了neo4j查找符合特定条件的所有路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为图建模以解决一些连接时间问题。因此,例如,我有以下图形

I am trying to model a graph to solve some connection time problem. So for example I have the following graph

    F1,F2     F3     F4

ST_B ---------> ST2 -----> ST3 ------> ST_E

ST_B--------->ST2----->ST3------>ST_E

   F5,F6      F7       F8

ST_B --------> ST4 ----> ST5 ------> ST_E

ST_B-------->ST4---->ST5------>ST_E

    F9

ST_B --------> ST_E

ST_B-------->ST_E

我将ST_B,ST2,ST3,ST4,ST5,ST_E建模为站(节点)。 F1-F9作为flt节点。每个flt节点都有一个出发时间和到达时间。和关系是连接。同样在这种情况下,我们假设F2的到达时间比F3的离开时间少30分钟,而F6的时间比F7少30分钟。 (表示连接无效),因此从ST_B到ST_E的有效路由应为F1-F3-F4,F5-F7-F8和F9。我尝试使用cypher解决此问题,但没有成功。 (可能是我建模错误)。

I model ST_B, ST2,ST3,ST4,ST5, ST_E as station (node). and F1-F9 as flt node. And each flt node has a departure time and arrival time. And the relationship is connect. Also in this case, let's assume F2 arrival time is 30mins less than F3 departure time, and F6 is 30mins less than F7. (means the connection is not valid) So the valid route from ST_B to ST_E should be F1-F3-F4, F5-F7-F8 and F9. I have try to use cypher to solve this problem without success. (may be I am modeling it wrong).

推荐答案

我为节点添加了标签,以区分航班和车站。所有航班F1-F9均标有:Flight,所有站ST_B,ST_E和ST_2-ST_5均标有:Station。

I have added labels for the nodes to distinguish flights and stations. All flights F1-F9 are labeled with :Flight, all stations ST_B, ST_E and ST_2-ST_5 are labeled with :Station.

Match path=stb:Station-[:Connect*]->ste:Station
Where stb.name='ST_B' and ste.name='ST_E'
With filter(x in nodes(path) where x:Flight ) as flts
Where all ( i in Range(0,length(flts)-2) Where flts[i].arrvTime < flts[i+1].dptrTime)
Return extract(flt in flts | flt.name)




  1. Match和 Where子句检索从ST_B到ST_E的所有路径;

  2. With子句检索路径上的所有飞行节点,并将它们传递到下一个 Where子句。

  3. 下一个哪里子句检查每个航班的到达时间和关联航班的离开时间,以仅返回有效的航班组合。

  4. 最后的回程子句返回形成有效航线的航班名称。

  1. The "Match" and "Where" clause retrieve all paths from ST_B to ST_E;
  2. The "With" clause retrieve all flight nodes on the paths and pass them to the next "Where" clause.
  3. The next "Where" clause checks the arrival time of each flight and the departure time of the connected flight to return only the valid flight combinations.
  4. The final "Return" clause returns the names of flights that form a valid route.

这篇关于neo4j查找符合特定条件的所有路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆