.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. UDP和TCP浅析

    UDP协议全称是用户数据报协议,在网络中它与TCP协议一样用于处理数据包,是一种无连接的协议. 在选择使用协议的时候,选择UDP必须要谨慎.在网络质量令人十分不满意的环境下,UDP协议数据包丢失会比较 ...

  2. 【面试】Redis

    1.如果在setnx之后执行expire之前进程意外crash或者要重启维护了,那会怎么样? set指令有非常复杂的参数,这个应该是可以同时setnx和expire合成一条指令来用的! 2.使用过Re ...

  3. 关于PHP内部类的一些总结学习

    前言: 这篇文章主要对一些可以进行反序列化的php内置类的分析总结(膜lemon师傅之前的总结),当然不是所有的php内置类在存在反序列化漏洞时都能够直接利用,有些类不一定能够进行反序列化,php中使 ...

  4. uni-app 尺寸单位

    uni-app 支持的通用 css 单位包括 px.rpx px 即屏幕像素 rpx 即响应式px,一种根据屏幕宽度自适应的动态单位.以750宽的屏幕为基准,750rpx恰好为屏幕宽度.屏幕变宽,rp ...

  5. LeetCode 6. Z字形变换(ZigZag Conversion)

    题目描述 将字符串 "PAYPALISHIRING" 以Z字形排列成给定的行数: P A H N A P L S I I G Y I R 之后从左往右,逐行读取字符:"P ...

  6. 尚学堂requireJs课程---3、私有和公有属性和方法

    尚学堂requireJs课程---3.私有和公有属性和方法 一.总结 一句话总结: 在 [模块] 的基础上,在return对象里面的方法和属性就是公有的(因为外部可以访问),不在的就是私有的 < ...

  7. 模拟LinkedList

    Linkedlist是一个集合容器,具有增删改查基本功能,本例中模拟增删查,对于修改,只需要将原节点处的val更新为新值即可,增加和删除在链表中速度是比较快的,查找,修改慢,因为要从头或者从尾开始遍历 ...

  8. kindeditor 引用js架包问题

    最近在搞kindeditor(富文本编辑器),遇到了很多插件修改无效的问题,仔细研究了一下才发现,别有洞天. 下面来介绍一下引用的js架包.具体有什么用. <!-- kindeditor.js ...

  9. java逆向工程-mybatis-generator

    题记:在快速开发的项目中有使用到,这样可以避免冗余工作 声明:参考于https://www.cnblogs.com/smileberry/p/4145872.html 环境:必须先安装maven环境, ...

  10. WCF的CommunicationObjectFaultedException异常问题

    前天刚刚重装了系统,装上了Win7,结果在调试的时候,WCF服务Open报错了! 具体错误信息如下: System.ServiceModel.CommunicationObjectFaultedExc ...