.big{font-size:larger}
.small{font-size:smaller}
.underline{text-decoration:underline}
.overline{text-decoration:overline}
.line-through{text-decoration:line-through}
.aqua{color:#00bfbf}
.aqua-background{background-color:#00fafa}
.black{color:#000}
.black-background{background-color:#000}
.blue{color:#0000bf}
.blue-background{background-color:#0000fa}
.fuchsia{color:#bf00bf}
.fuchsia-background{background-color:#fa00fa}
.gray{color:#606060}
.gray-background{background-color:#7d7d7d}
.green{color:#006000}
.green-background{background-color:#007d00}
.lime{color:#00bf00}
.lime-background{background-color:#00fa00}
.maroon{color:#600000}
.maroon-background{background-color:#7d0000}
.navy{color:#000060}
.navy-background{background-color:#00007d}
.olive{color:#606000}
.olive-background{background-color:#7d7d00}
.purple{color:#600060}
.purple-background{background-color:#7d007d}
.red{color:#bf0000}
.red-background{background-color:#fa0000}
.silver{color:#909090}
.silver-background{background-color:#bcbcbc}
.teal{color:#006060}
.teal-background{background-color:#007d7d}
.white{color:#bfbfbf}
.white-background{background-color:#fafafa}
.yellow{color:#bfbf00}
.yellow-background{background-color:#fafa00}

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/

All shortest paths between a set of nodes的更多相关文章

  1. Codeforces 1005 F - Berland and the Shortest Paths

    F - Berland and the Shortest Paths 思路: bfs+dfs 首先,bfs找出1到其他点的最短路径大小dis[i] 然后对于2...n中的每个节点u,找到它所能改变的所 ...

  2. Shortest Paths

    最短路径 APIs 带权有向图中的最短路径,这节讨论从源点(s)到图中其它点的最短路径(single source). Weighted Directed Edge API 需要新的数据类型来表示带权 ...

  3. Codeforces Round #496 (Div. 3) F - Berland and the Shortest Paths

    F - Berland and the Shortest Paths 思路:还是很好想的,处理出来最短路径图,然后搜k个就好啦. #include<bits/stdc++.h> #defi ...

  4. 【例题收藏】◇例题·II◇ Berland and the Shortest Paths

    ◇例题·II◇ Berland and the Shortest Paths 题目来源:Codeforce 1005F +传送门+ ◆ 简单题意 给定一个n个点.m条边的无向图.保证图是连通的,且m≥ ...

  5. CSU 1506 Double Shortest Paths

    1506: Double Shortest Paths Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 49  Solved: 5 Description ...

  6. CF Gym 102028G Shortest Paths on Random Forests

    CF Gym 102028G Shortest Paths on Random Forests 抄题解×1 蒯板子真jir舒服. 构造生成函数,\(F(n)\)表示\(n\)个点的森林数量(本题都用E ...

  7. [Codeforces 1005F]Berland and the Shortest Paths(最短路树+dfs)

    [Codeforces 1005F]Berland and the Shortest Paths(最短路树+dfs) 题面 题意:给你一个无向图,1为起点,求生成树让起点到其他个点的距离最小,距离最小 ...

  8. UVA 12821 Double Shortest Paths

    Double Shortest PathsAlice and Bob are walking in an ancient maze with a lot of caves and one-way pa ...

  9. Codeforces Round #Pi (Div. 2) 567E President and Roads ( dfs and similar, graphs, hashing, shortest paths )

    图给得很良心,一个s到t的有向图,权值至少为1,求出最短路,如果是一定经过的边,输出"YES",如果可以通过修改权值,保证一定经过这条边,输出"CAN",并且输 ...

随机推荐

  1. 简单的SSRF的学习

    自己眼中的SSRF 成因 服务端允许了 可以向其他服务器请求获取一些数据 通过各种协议 http https file等(外网服务器所在的内网进行端口的扫描指纹的识别等) 一SSRF配合redis未授 ...

  2. 05.用两个栈实现队列 Java

    题目描述 用两个栈来实现一个队列,完成队列的Push和Pop操作. 队列中的元素为int类型. 思路 进栈: 直接进stack1 出栈: 若stack2不为空,则出栈. 否则,当stack1不为空时, ...

  3. mini dc(选做)

    一.任务详情 提交测试截图和码云练习项目链接,实现Linux下dc的功能,计算后缀表达式的值 二.源代码 1.MyDC类 import java.util.StringTokenizer; impor ...

  4. 阿里云服务器yum源更新问题

    阿里云官网也给出了yum卸载重装以及修改源为阿里云内网的文档.步骤这里就不说了,可点击下面的链接进行参考 https://help.aliyun.com/knowledge_detail/670864 ...

  5. 求平面上N点最远两点和最近两点距离

    最近两点,二分法 最远两点,凸包+找对踵点

  6. javascript循环语句

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  7. php怎样获取当前页面文件名

    因开发需要,常需要获取当前php文件的文件名.php获取当前文件名方法很简单,程序代码如下: <?php function php_self(){ $php_self=substr($_SERV ...

  8. C#调用SQL中存储过程并用DataGridView显示执行结果

    //连接数据库 SqlConnection con = new SqlConnection("server=服务器名称;database=数据库名称;user id=登录名;pwd=登录密码 ...

  9. JavaScript DOM 编程艺术(第二版) 初读学习笔记

    这本书留给我的印象就是结构.表现和行为层的分离,以及书后面部分一直在强调的最佳实践原则:平稳退化,逐步增强,向后兼容以及性能考虑. 要注意这不是一本JavaScript入门书籍~ 2.1 准备工作 用 ...

  10. docker 的安装和镜像

    一.docker的 安装 : 第一种: yum -y install docker systemctl start docker.service systemctl status docker 第二种 ...