使用节点属性过滤器查找2个节点之间的最短路径 [英] Find shortest path between 2 nodes using a node property filter
问题描述
我有一个图形数据库,其中包含具有称为"is_in_operation"的属性的节点(公交车站),如果公交车站处于运行状态,则该属性设置为"true";否则将其设置为"false".
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屋!