neo4j - create new relationships along path -
assuming topology:
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)
i can use query maximum bandwidth path between "macbookpro" , "ylo":
match (s {name:"macbookpro"}), (t {name:"ylo"}), p=allshortestpaths(s-[*]-t) return p path, reduce( mini=100000, r in relationships(p) | case when mini < r.bw mini else r.bw end) maximal_bandwidth order maximal_bandwidth desc limit 1;
how can create new relationships (e.g. session_rtp
) along nodes of path?
following snowburnts suggestion, came partial solution:
match (s {name:"macbookpro"}), (t {name:"ylo"}), p=allshortestpaths(s-[*]-t) p path, reduce( mini=100000, r in relationships(p) | case when mini < r.bw mini else r.bw end) maximal_bandwidth order maximal_bandwidth desc limit 1 foreach( r in relationships(path)| set r.session = 1 )
followed by:
match (a)-[r:lnk {session : 1}]->(b) create (a)-[:session_rtp{id:1}]->(b)
is possible compress in single statement?
after reading comment
i understood path minimum bw should have nodes connected relation called session_rip
.
try below
match (s {name:"macbookpro"}), (t {name:"ylo"}), p=allshortestpaths(s-[*]-t) p path, reduce( mini=100000, r in relationships(p) | case when mini < r.bw mini else r.bw end) maximal_bandwidth order maximal_bandwidth desc limit 1 relationships(p) rels foreach (t in rels | foreach (a in [startnode(t)]| foreach (b in [endnode(t)]| create a-[:session_rtp]->b )))
Comments
Post a Comment