Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/heroku/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Neo4j Cypher公交车路线选择_Neo4j_Cypher - Fatal编程技术网

Neo4j Cypher公交车路线选择

Neo4j Cypher公交车路线选择,neo4j,cypher,Neo4j,Cypher,我是Cypher的新手,我想知道Neo4j Cypher是否可能出现以下情况: 当我想查询从1号站到4号站应该乘坐哪些公交车时,输出应该是(包括最少的换乘次数): 1号站->1号线->3号站->3号线->4号站 1号站->2号线->3号站->3号线->4号站 但并非所有可能的组合: 1号站->1号线->2号站->1号线->3号站->3号线->4号站 1号站->1号线->2号站->2号线->3号站->3号线->4号站 1号站->2号线->2号站->1号线->3号站->3号线->4号站 1号站->

我是Cypher的新手,我想知道Neo4j Cypher是否可能出现以下情况:

当我想查询从1号站到4号站应该乘坐哪些公交车时,输出应该是(包括最少的换乘次数):

  • 1号站->1号线->3号站->3号线->4号站
  • 1号站->2号线->3号站->3号线->4号站
  • 但并非所有可能的组合:

  • 1号站->1号线->2号站->1号线->3号站->3号线->4号站
  • 1号站->1号线->2号站->2号线->3号站->3号线->4号站
  • 1号站->2号线->2号站->1号线->3号站->3号线->4号站
  • 1号站->2号线->2号站->2号线->3号站->3号线->4号站

  • 谢谢

    如果没有条件表达式(CASE/WHEN现在在2.0中),这是很困难的。这是我在几分钟的尝试中得到的最接近的结果。您必须从结果关系集合中拉出开始节点

    start st1=node:node_auto_index(name="station1"), st4=node:node_auto_index(name="station4") 
    match p=st1-[r*]->st4 
    with reduce(acc=[], route in rels(p): 
      case 
        when length(acc) > 0 and last(extract(a in acc: a.name)) = route.name then acc 
        else acc + route 
      end) as reducedRoutes 
    return reducedRoutes, length(reducedRoutes) as len 
    order by len;
    

    谢谢您的努力!你帮了我很多!在互联网上似乎很难得到这个答案。这是一个有效的解决方案,但当涉及到一个像这样的大型图形时,它确实需要一个匹配的上限,[*r1..10]或一些好的数字。