neo4j finding all paths that meets a certain criteria

后端 未结 1 1541
误落风尘
误落风尘 2020-12-20 00:45

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-

相关标签:
1条回答
  • 2020-12-20 01:03

    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. 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.
    0 讨论(0)
提交回复
热议问题