假设这种拓扑结构:
create
(mbp {name: "MacBookPro"}),
(fb {name:"FritzBox"}),
(eue {name: "1u1"}),
(inet {name:"Internet"}),
(mnh {name:"Mannheim"}),
(hdb {name:"Heidelberg"}),
(stg {name: "Stuttgart"}),
(lnd {name:"Lindt"}),
(ylo {name:"Ylo"}),
(qvin {name:"Qvin"}),
(mbp) -[:LNK {bw:100}]->(fb),
(fb)-[:LNK {bw:32}]->(eue),
(eue)-[:LNK {bw:10000}]->(inet),
(inet)-[:LNK {bw:10000}]->(mnh),
(mnh)-[:LNK {bw:10000}]->(hdb),
(hdb)-[:LNK {bw:1000}]->(lnd), // Route option 1
(mnh)-[:LNK {bw:10000}]->(stg),
(stg)-[:LNK {bw:10000}]->(lnd), // Route option 2
(lnd)-[:LNK {bw:1000}]->(ylo),
(lnd)-[:LNK {bw:1000}]->(qvin),
(ylo)-[:LNK {bw:1000}]->(qvin)
我可以使用此查询获取“MacBookPro”和“Ylo”之间的最大带宽路径:
match (s {name:"MacBookPro"}),
(t {name:"Ylo"}),
p=allShortestPaths(s-[*]-t)
return
p as path,
reduce( mini=100000,
r in relationships(p) |
case when mini < r.bw then mini else r.bw end)
as maximal_bandwidth
order by maximal_bandwidth desc
limit 1;
如何在该路径的所有节点上创建新关系(例如SESSION_RTP
)?
根据Snowburnts的建议,我想出了这个部分解决方案:
match (s {name:"MacBookPro"}),
(t {name:"Ylo"}),
p=allShortestPaths(s-[*]-t)
with
p as path,
reduce( mini=100000,
r in relationships(p) |
case when mini < r.bw then mini else r.bw end)
as maximal_bandwidth
order by maximal_bandwidth desc limit 1
foreach( r in relationships(path)| set r.session = 1 )
其次是:
match (a)-[r:LNK {session : 1}]->(b) create (a)-[:SESSION_RTP{id:1}]->(b)
是否可以在一个声明中压缩它?
答案 0 :(得分:0)
阅读评论后
我知道只有bw最小的路径才能将节点与名为SESSION_RIP
的关系连接起来。
尝试以下
match (s {name:"MacBookPro"}),
(t {name:"Ylo"}),
p=allShortestPaths(s-[*]-t)
with
p as path,
reduce( mini=100000,
r in relationships(p) |
case when mini < r.bw then mini else r.bw end)
as maximal_bandwidth
order by maximal_bandwidth desc limit 1
with relationships(p) as rels
foreach (t in rels |
foreach (a in [startNode(t)]|
foreach (b in [endNode(t)]|
CREATE a-[:SESSION_RTP]->b
)))