密码查询最短路径 [英] Cypher query shortest path

查看:75
本文介绍了密码查询最短路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我以此方式构建一个图形:节点表示:busStops,关系表示连接公交车站的公交线路.

I build a graphe this way: the nodes represents: busStops, and the relationship represent the bus line linking bus stops each others.

关系类型对应于从一个节点到另一个节点两个节点所需的时间.

The relationship type correspond to the time needed to go from a node two another one.

当我查询图形(由于使用密码)以获取可能未链接的两个图形之间的最短路径时,结果是使用的关系数最小的图形.

When I'm querying the graph (thanks to cypher) to get the shortestPath between two which are maybe not linked, the result is the one where the number of relations used is the smallest.

我要更改它,以使最短路径对应于两个节点之间使用的所有关系类型(对应于时间)的相加最小的路径?

I would to change that in order that the shortest path corresponds to the path where the addition of all relationship types used between two nodes(which correspond to the time) is the smallest?

推荐答案

首先,您做错了.不要每次都使用唯一的关系类型.使用一种关系类型,然后在所有关系上放置一个时间"属性.

first, you are doing it wrong. don't use a unique relationship type for each time. use one relationship type and then put a property "time" on all relations.

秒,您可以使用以下密码公式来计算加法:

second, to calculate the addition you can use this cypher formula:

START from=node({busStopId1}), to=node({busStopId2})
MATCH p=from-[:LINE*]-to  //asterix * means any distance
RETURN p,reduce(total = 0, r in relationships(p): total + r.time) as tt
ORDER by tt asc;

这篇关于密码查询最短路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆