zoukankan      html  css  js  c++  java
  • All shortest paths between a set of nodes

    Consider a number of arbitrary nodes, A,B,C,D,E,F,…​..

    I wish to return all of the shortest paths between these nodes. The nodes may have many edges between them, but anticipate a maximum of 4. The graph is complex and non hierarchical (if this makes sense – any node may point to any other node). A typical node has the form: match (n:Entity { name: 'xyz' })

    How would I write the match expression to return the shortest paths between the above nodes, in no specific order?

    Solution

    1. Find the set of nodes using an indexed lookup operation
    2. Collect them into a list
    3. Unwind the list twice, once for every side of the path
    4. Remove inverse pairs by id comparison
    5. match and return the paths
    MATCH (n:Entity) where n.name IN [names]
    WITH collect(n) as nodes
    UNWIND nodes as n
    UNWIND nodes as m
    WITH * WHERE id(n) < id(m)
    MATCH path = allShortestPaths( (n)-[*..4]-(m) )
    RETURN path

    原文地址:https://neo4j.com/developer/kb/all-shortest-paths-between-set-of-nodes/

  • 相关阅读:
    QT实现软件重启
    Qt 延时
    gcc 创建库及使用
    verilog 奇数分频设计
    内核中的 likely() 与 unlikely()
    TFT LCD 参数详解
    手动安装m4, autoconf, automake, libtool
    [其他] 蒙特卡洛(Monte Carlo)模拟手把手教基于EXCEL与Crystal Ball的蒙特卡洛成本模拟过程实例:
    Origin9.1如何绘制风向玫瑰图(Binned Data)?
    Origin9.1如何使用原始数据(Raw Data)绘制风向玫瑰图
  • 原文地址:https://www.cnblogs.com/jpfss/p/11652218.html
Copyright © 2011-2022 走看看