Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
06-18-2021 07:49 AM
hello, I have created a little traveling line for the bus like following
I want to get the shortest time path between "start" and "fin" with the function reduce, I hope to calculate the sum of running time(temps), and when it changes the bus, we add the time of Changement(att),temps and att are parameters in relationships.
the following is the code I want to realize
match (a:station {name:"start"}),(b:station{name:"fin"}),
p=((a)-[*]->(b))
with p,
reduce(s=0,r in relationships(p) #and ln=type(relationship(p))# (I know it's incorrect| case type(r) when ln then s+r.temps else s+r.temps+r.att and ln=type(r) end)AS temps
return p, temps order by temps asc limit 1
Is it possible to add another variable like ln in function reduce to realize it or is there another solution?
Thank you
Solved! Go to Solution.
06-18-2021 08:00 AM
Hello @zhiyizhou1995 and welcome to the Neo4j community
You can try to to use a list as accumulator: reduce(s=[0, 0]...)
and then to add s[0] + 1
or s[1] + 1
.
Regards,
Cobra
06-18-2021 08:00 AM
Hello @zhiyizhou1995 and welcome to the Neo4j community
You can try to to use a list as accumulator: reduce(s=[0, 0]...)
and then to add s[0] + 1
or s[1] + 1
.
Regards,
Cobra
06-18-2021 08:16 AM
thank you! You mean s[0], s[1] here represent different variables? it can also be a string?
06-18-2021 08:26 AM
Take a list l = [0, 0]
, l[0]
will be the first element and l[1]
will be the second element so you can add integer to the first or the second element, you can also use a list of strings I guess if you want to merge strings like l = ['', '']
.
All the sessions of the conference are now available online