I have a graph like below.
And below code is used to create the above graph.
MERGE (a:Bus:GenBus{type:'GenBus',gencapacity:630,name:'NCTPS', bus_no:1, available_generation:630,status:'Not Connected'})
MERGE (b:Bus:GenBus{type:'GenBus',gencapacity:450,name:'ETPS', bus_no:2, available_generation:450,status:'Not Connected'})
MERGE (c:Bus:LoadBus{type:'LoadBus',load:285,name:'TONDAIYARPET', bus_no:3,status:'Not Connected'})
MERGE (d:Bus:LoadBus{type:'LoadBus',load:502,name:'MYLAPORE', bus_no:4,status:'Not Connected'})
MERGE (e:Bus:LoadBus{type:'LoadBus',load:275,name:'KTR', bus_no:5,status:'Not Connected'})
MERGE (f:Bus:LoadBus{type:'LoadBus',load:47,name:'KOYEMBEDU', bus_no:6,status:'Not Connected'})
MERGE (g:Bus:LoadBus{type:'LoadBus',load:27,name:'MOSUR', bus_no:7,status:'Not Connected'})
MERGE (h:Bus:LoadBus{type:'LoadBus',load:8,name:'SULURPET', bus_no:8,status:'Not Connected'})
MERGE (i:Bus:LoadBus{type:'LoadBus',load:336,name:'GUMIDIPONDI', bus_no:9,status:'Not Connected'})
MERGE (j:Bus:LoadBus{type:'LoadBus',load:17,name:'SRIPERAMBATHUR', bus_no:10,status:'Not Connected'})
MERGE (k:Bus:LoadBus{type:'LoadBus',load:260,name:'THARAMANI', bus_no:11,status:'Not Connected'})
MERGE (l:Bus:LoadBus{type:'LoadBus',load:73,name:'KADAPERI', bus_no:12,status:'Not Connected'})
MERGE (m:Bus:LoadBus{type:'LoadBus',load:50,name:'ARNI', bus_no:13,status:'Not Connected'})
MERGE (n:Bus:GenBus{type:'GenBus',gencapacity:440,name:'MTPS', bus_no:14, available_generation:440,status:'Not Connected'})
MERGE (o:Bus:LoadBus{type:'LoadBus',load:78,name:'SGPET', bus_no:15,status:'Not Connected'})
MERGE (p:Bus:LoadBus{type:'LoadBus',load:243,name:'SPKOIL', bus_no:16,status:'Not Connected'})
MERGE (q:Bus:LoadBus{type:'LoadBus',load:17,name:'TYLM', bus_no:17,status:'Not Connected'})
MERGE (r:Bus:GenBus{type:'GenBus',gencapacity:220,name:'NEYVELI', bus_no:18, available_generation:220,status:'Not Connected'})
MERGE (s:Bus:GenBus{type:'GenBus',gencapacity:440,name:'MAPS', bus_no:19, available_generation:440,status:'Not Connected'})
MERGE (a)-[:TRANSMISSION_LINE{line_no:1,length:18,available_cap:1000,status:'Not Connected'}]->(b)
MERGE (a)-[:TRANSMISSION_LINE{line_no:2,length:9,available_cap:1000,status:'Not Connected'}]->(c)
MERGE (a)-[:TRANSMISSION_LINE{line_no:3,length:7,available_cap:1000,status:'Not Connected'}]->(e)
MERGE (a)-[:TRANSMISSION_LINE{line_no:4,length:95,available_cap:1000,status:'Not Connected'}]->(g)
MERGE (a)-[:TRANSMISSION_LINE{line_no:5,length:39,available_cap:1000,status:'Not Connected'}]->(i)
MERGE (a)-[:TRANSMISSION_LINE{line_no:6,length:43,available_cap:1000,status:'Not Connected'}]->(j)
MERGE (b)-[:TRANSMISSION_LINE{line_no:7,length:10,available_cap:1000,status:'Not Connected'}]->(c)
MERGE (b)-[:TRANSMISSION_LINE{line_no:8,length:22,available_cap:1000,status:'Not Connected'}]->(e)
MERGE (b)-[:TRANSMISSION_LINE{line_no:9,length:104,available_cap:1000,status:'Not Connected'}]->(g)
MERGE (c)-[:TRANSMISSION_LINE{line_no:10,length:9,available_cap:1000,status:'Not Connected'}]->(d)
MERGE (e)-[:TRANSMISSION_LINE{line_no:11,length:8,available_cap:1000,status:'Not Connected'}]->(f)
MERGE (e)-[:TRANSMISSION_LINE{line_no:12,length:39,available_cap:1000,status:'Not Connected'}]->(j)
MERGE (f)-[:TRANSMISSION_LINE{line_no:13,length:32,available_cap:1000,status:'Not Connected'}]->(j)
MERGE (g)-[:TRANSMISSION_LINE{line_no:14,length:49,available_cap:1000,status:'Not Connected'}]->(j)
MERGE (g)-[:TRANSMISSION_LINE{line_no:15,length:55,available_cap:1000,status:'Not Connected'}]->(q)
MERGE (h)-[:TRANSMISSION_LINE{line_no:16,length:39,available_cap:1000,status:'Not Connected'}]->(i)
MERGE (i)-[:TRANSMISSION_LINE{line_no:17,length:82,available_cap:1000,status:'Not Connected'}]->(j)
MERGE (j)-[:TRANSMISSION_LINE{line_no:18,length:50,available_cap:1000,status:'Not Connected'}]->(k)
MERGE (j)-[:TRANSMISSION_LINE{line_no:19,length:24,available_cap:1000,status:'Not Connected'}]->(l)
MERGE (j)-[:TRANSMISSION_LINE{line_no:20,length:103,available_cap:1000,status:'Not Connected'}]->(m)
MERGE (j)-[:TRANSMISSION_LINE{line_no:21,length:47,available_cap:1000,status:'Not Connected'}]->(p)
MERGE (m)-[:TRANSMISSION_LINE{line_no:22,length:97,available_cap:1000,status:'Not Connected'}]->(o)
MERGE (m)-[:TRANSMISSION_LINE{line_no:23,length:45,available_cap:1000,status:'Not Connected'}]->(q)
MERGE (m)-[:TRANSMISSION_LINE{line_no:24,length:128,available_cap:1000,status:'Not Connected'}]->(s)
MERGE (n)-[:TRANSMISSION_LINE{line_no:25,length:133,available_cap:1000,status:'Not Connected'}]->(o)
MERGE (o)-[:TRANSMISSION_LINE{line_no:26,length:140,available_cap:1000,status:'Not Connected'}]->(q)
MERGE (p)-[:TRANSMISSION_LINE{line_no:27,length:91,available_cap:1000,status:'Not Connected'}]->(q)
MERGE (q)-[:TRANSMISSION_LINE{line_no:28,length:183,available_cap:1000,status:'Not Connected'}]->(r)
I want to find shortest path between GenBus
nodes to LoadBus
nodes based on TRANSMISSION_LINE
property length
.
I want to extract the TRANSMISSION_LINE
s of that shortest path and set their property status:Connected
and update available_cap = available_cap - load
. Here load is load
of the LoadBus
MATCH (s:GenBus{bus_no:14}), (l:LoadBus{bus_no:16})
CALL algo.shortestPath.stream(s, l, "length")
YIELD nodeId,cost
with collect(nodeId) as q ,l
MATCH path = (a)-[r:TRANSMISSION_LINE]-(b)
where id(a)in q and id(b) in q
return path
Note: I have unchecked the connect result nodes option in settings
If i run the above code, it gives output as below.
Here the shortest path is 14 ->15 -> 17 -> 16 . So, it's ok.
But for the case of shortest path between GenBus1 to LoadBus17 , it become problem.
Below is the code. I just changed the numbers in above code.
MATCH (s:Bus{bus_no:1 }), (l:Bus{bus_no: 17})
CALL algo.shortestPath.stream(s, l, "length")
YIELD nodeId,cost
with collect(nodeId) as q ,l
MATCH path = (a)-[r:TRANSMISSION_LINE]-(b)
where id(a)in q and id(b) in q
return path
Output:
In this case the shortest path is 1 -> 10 -> 7 -> 17. But It is showing extra relationship between node1 and node17.
How to get the correct output?
I mean it should not show that extra relationship.
I am very new to neo4j.