使用节点属性过滤器查找 2 个节点之间的最短路径 [英] Find shortest path between 2 nodes using a node property filter

查看:20
本文介绍了使用节点属性过滤器查找 2 个节点之间的最短路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个图形数据库,它由节点(公交车站)组成,具有名为is_in_operation"的属性,如果公交车站正常运行,该属性设置为true";否则设置为假".

I have a graph database that consists of nodes (bus stations) with a property called "is_in_operation" which is set to "true" if the bus station is operational; otherwise it is set to "false".

如果公共汽车在两个站之间行驶,则在两个节点之间建立了关系.

There is a relationship created between two nodes if a bus travels between the two stations.

我想找到路径中所有节点都可运行的两个节点之间停靠点数最短的路径.

I would like to find the path with the shortest number of stops between two nodes where all nodes in the path are operational.

数据库中有一个例子,其中在 2 个指定节点之间有 2 条路径.对于两条路径中的所有节点,is_in_operation"属性都设置为true".当我运行以下查询时,我得到了正确的答案

There is an example in the database where there are 2 paths between 2 specified nodes. The "is_in_operation" property is set to ‘true’ for all nodes in both paths. When I run the following query, I get the correct answer

START d=node(1), e=node(5) 
MATCH p = shortestPath( d-[*..15]->e ) where all (x in nodes(p) where x.is_in_operation='true')
RETURN p;

当我将最短路径中的一个中间节点的is_in_operation"属性设置为false"并重新运行查询时,我希望它返回另一条路径.但是,我根本没有得到任何答复.

When I set the ‘is_in_operation’ property to ‘false’ for one of the intermediate nodes in the shortest path and rerun the query, I expect it to return the other path. However, I get no answer at all.

查询不正确吗?如果是这样,我应该如何指定查询?

Is the query incorrect? If so, how should I specify the query?

推荐答案

问题是 shortestPath 不能考虑 where 子句,所以你匹配最短路径,然后用你的 where 过滤掉它.

The problem is that shortestPath can't take into account the where clause, so you're matching the shortest path, and then filtering it out with your where.

这个怎么样——它可能不如 shortestPath 有效,但它应该返回一个结果,如果存在的话:

How about this one--it might not be as efficient as shortestPath, but it should return a result, if one exists:

START d=node(1), e=node(5) 
MATCH p = d-[*..15]->e
where all (x in nodes(p) where x.is_in_operation='true')
RETURN p
order by len(p)
limit 1;

这篇关于使用节点属性过滤器查找 2 个节点之间的最短路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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