密码查询最短路径

编程入门 行业动态 更新时间:2024-10-25 00:33:44
本文介绍了密码查询最短路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我以此方式构建一个图形:节点表示: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;

更多推荐

密码查询最短路径

本文发布于:2023-11-29 23:24:49,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1647948.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:最短   路径   密码

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!