我目前正在使用内置的dijkstra使用条件进行Neo4J路径查找(见下文)。
CYPHER
PROFILE MATCH path = shortestpath((s:Node {UID: 73946372})-[Road*]->(e:Node {UID: 2383529534}))
WHERE ALL(x in relationships(path) WHERE x.LG_6 > 0 || x.C60 > 100)
WITH path, reduce(s = 0, r IN relationships(path) | s + r.Length) AS dist
RETURN path LIMIT 1
但是,我想知道是否可以对APOC进行同样的操作,并具有x.LG_6> 2000 AND x.C60> 0这样的条件。下面的密码是我目前使用的密码,但它们没有条件。
APOC A *
PROFILE MATCH (s:Node {UID: 73946372}),(e:Node {UID: 2383529534})
CALL apoc.algo.aStar(s, e, 'Road', 'Length','Latitude','Longitude') YIELD path, weight
RETURN path, weight LIMIT 1
APOC Dijkstra
PROFILE MATCH (s:Node {UID: 73946372}),(e:Node {UID: 2383529534})
CALL apoc.algo.dijkstra(s, e, 'Road', 'Length') YIELD path AS path, weight AS weight
RETURN path, weight LIMIT 1
答案 0 :(得分:2)
Cypher函数shortestPath
并不使用关系权重属性来计算最短路径-它仅使用路径的长度(即路径中的关系数)。
因此,第一个查询返回的dist
会产生误导,因为shortestPath
函数不是用来确定path
结果的。这也是为什么您的第一个查询结果可能与确实使用weight属性的另一个算法的结果不匹配的原因。
stream
变体返回结果路径中每个节点的本机ID,以及直到路径中该点的总权重。当前,此插件仅受neo4j 3.5.14及更低版本支持。例如:
MATCH (s:Node {UID: 73946372}), (e:Node {UID: 2383529534})
CALL algo.shortestPath.astar.stream(s, e, null, 'Latitude', 'Longitude', {
nodeQuery: 'MATCH (p:Node) RETURN id(p) as id',
relationshipQuery: 'MATCH (a:Node)-[x:Road]->(b:Node) WHERE x.LG_6 > 0 || x.C60 > 100 RETURN id(a) AS source, id(b) AS target, x.Length AS weight',
graph: 'cypher'
}) YIELD nodeId, cost
RETURN nodeId,cost
MATCH (s:Node {UID: 73946372}), (e:Node {UID: 2383529534})
CALL algo.shortestPath.stream(s, e, null, {
nodeQuery: 'MATCH (p:Node) RETURN id(p) as id',
relationshipQuery: 'MATCH (a:Node)-[x:Road]->(b:Node) WHERE x.LG_6 > 0 || x.C60 > 100 RETURN id(a) AS source, id(b) AS target, x.Length AS weight',
graph: 'cypher'
}) YIELD nodeId, cost
RETURN nodeId, cost