I am trying to calculate the average distance between any two nodes in an $r$-dimensional mesh.
This is a $3$-dimensional mesh with $n=3$
To choose any two points in the mesh there are $\left(n^r \left(n^r - 1\right)\right)/2$ ways of doing this.
So if we choose 2 points in the mesh $p\lbrace 1, 2, ..., r \rbrace$ and $q\lbrace 1, 2, ..., r \rbrace$ The distance is calculated as the Manhattan Distance
$\sum_{i=1}^{r} \left| {q_i - p_i} \right|$
Now i have to find the total distance between all nodes and divide that by the the number of ways of choosing two nodes (given above).
I know how to do this by looking at this 3-dimensional case which should work on the r-dimensional case also but i am having trouble expressing it in some sort of sum notation.
Here is how i think i can get the total distance between all nodes, i hope this is clear.
In this 3-d mesh let's assume the nodes are labelled $\left( 1, 1, 1 \right)$ to $\left( 3, 3, 3\right)$. Lets start at $\left( 1, 1, 1 \right)$ and sum up the distance between this node and all other nodes. Then we move to $\left( 1, 1, 2 \right)$ and sum up the distances between this node and all other nodes except for $\left( 1, 1, 1 \right)$ because we have already counted the distance between $\left( 1, 1, 1 \right)$ and $\left( 1, 1, 2 \right)$. Then we move onto $\left( 1, 1, 3 \right)$ and sum up all except for $\left( 1, 1, 1 \right)$ and $\left( 1, 1, 2 \right)$. We continue this until we permute through in order $\left( 1, 1, 1 \right)$, $\left( 1, 1, 2 \right)$, $\left( 1, 1, 3 \right)$, $\left( 1, 2, 1 \right)$, $\left( 1, 2, 2 \right)$, ect... Does that make sense?
That should give me the total distance without counting anything twice. Then i divide that by the number of ways of choosing 2 nodes and i will have the average distance. Does this sound correct to you? Any help would be appreciated.