- 计算路径标识符值
- 您需要沿路径获取节点数组 - NODES
- 遍历每个节点 - UNWIND或FOREACH
- 设置或标签或属性 - 现在您不能将变量的值用作标签,这意味着写入属性 - SET
MATCH (a:Job {Jobname:...}),(b:Job {Jobname:...}) WITH a, b,
a.Jobname + '-' + b.Jobname AS pathID
CALL apoc.algo.dijkstra(a,b,'runafter>','Duration') YIELD path, weight
FOREACH (n IN NODES(path)|
SET n.pathID = pathID,
n.pathWeight = weight
)
RETURN path,weight
由于您使用 apoc,因此您可以设置标签:
MATCH (a:Job {Jobname:...}),(b:Job {Jobname:...}) WITH a, b,
'inCalculatedPath' + '-' + a.Jobname + '-' + b.Jobname AS pathID
CALL apoc.algo.dijkstra(a,b,'runafter>','Duration') YIELD path, weight
CALL apoc.create.addLabels( NODES(path), ['inCalculatedPath', pathID])
RETURN path,weight
另一种方法是添加类似Calculated path
节点的东西:
MATCH (a:Job {Jobname:...}),(b:Job {Jobname:...}) WITH a, b
CALL apoc.algo.dijkstra(a,b,'runafter>','Duration') YIELD path, weight
CREATE (P:CalculatedPath)
SET P.weight = weight,
P.start = ID(a),
P.end = ID(b),
P.pathNodes = REDUCE(ids=[], n IN NODES(path)| ids + ID(n)),
P.pathRels = REDUCE(ids=[], r IN RELS(path) | ids + ID(r))
FOREACH (n IN NODES(path)|
MERGE (n)-[:inPath]->(P)
)
RETURN path, weight
并返回路径:
MATCH (a:Job {Jobname:...}),(b:Job {Jobname:...}) WITH a, b
MATCH (path:CalculatedPath {start: ID(A), end: ID(b)})
RETURN path, path.weight AS weight