Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
05-27-2021 12:50 AM
Hello There,
I would like to take into account the network diameter for being able to filter all the networks by network diameter size. Is that doable ?
Thanks in advance !
Solved! Go to Solution.
05-27-2021 01:16 AM
Hello @1113
Do you want to calculate the diameter of the graph? It corresponds to the longest of the shortest paths. Be aware that the calculation can be very long. You can add filters for nodes and relationships if you want the query to be faster.
MATCH (n)
WITH collect(n) AS nodes
UNWIND nodes AS a
UNWIND nodes AS b
WITH a, b
WHERE id(a) < id(b)
MATCH path=shortestPath((a)-[*]-(b))
RETURN length(path) AS diameter
ORDER BY diameter
DESC LIMIT 1
Regards,
Cobra
05-27-2021 01:16 AM
Hello @1113
Do you want to calculate the diameter of the graph? It corresponds to the longest of the shortest paths. Be aware that the calculation can be very long. You can add filters for nodes and relationships if you want the query to be faster.
MATCH (n)
WITH collect(n) AS nodes
UNWIND nodes AS a
UNWIND nodes AS b
WITH a, b
WHERE id(a) < id(b)
MATCH path=shortestPath((a)-[*]-(b))
RETURN length(path) AS diameter
ORDER BY diameter
DESC LIMIT 1
Regards,
Cobra
05-27-2021 03:05 AM
Thank you, The graph I would like to analyse is around 700k nodes. The command is running. I will keep you posted. 🙂
05-27-2021 03:09 AM
Do you want to analyse all nodes and relationships or only some labels and types?
All the sessions of the conference are now available online