create new relationships along path

Assuming this 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 this query to get the maximum bandwidth path between "MacBookPro" and "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;

How can I create new relationships (e.g. SESSION_RTP) along all nodes of that path?

Following Snowburnts suggestion, I came up with this partial solution:

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 )

Followed by:

match (a)-[r:LNK {session : 1}]->(b) create (a)-[:SESSION_RTP{id:1}]->(b)

Is it possible to compress this in a single statement?

Answers


After reading comment

I understood that only the path with minimum bw should have nodes connected with relation called SESSION_RIP.

Try below

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
  )))

Need Your Help

Sql appropriate syntax

php mysql

does the following piece of code face sql injection problems? IF so why and what could be changed to prevent it?

Rendering very big 2D Map

java lwjgl

I want to create a 2D Game with Java and LWJGL. It is a retro styled RPG game. So there is a really big map(about 1000x1000 or bigger). I want to do it with tiles but I don't know how to save it/ho...