cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Network Diameter

1113
Node Clone

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 !

1 ACCEPTED SOLUTION

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

View solution in original post

3 REPLIES 3

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

1113
Node Clone

Thank you, The graph I would like to analyse is around 700k nodes. The command is running. I will keep you posted. 🙂

Do you want to analyse all nodes and relationships or only some labels and types?