Let $n$ be a positive integer. Consider a set $S_n=([1,n]\cap\mathbb N)^3$ having $n^3$ points in the Euclidean space $\mathbb R^3$ arranged in a cubic lattice. Let $a_n$ be the size of a largest subset of $S_n$ such that for each pair of points in the subset there are no other pair of points in the subset having the same distance between them (i.e. all distances between points in the subset are unique).
Can you suggest an efficient way to compute $a_n$, or find a general formula for this sequence? Or, at least, find $a_n$ for a few small positive integers?
Update: Lower or upper bounds, or asymptotic behavior are welcome. Is the sequence $\{a_n\}$ strictly increasing?
Update: The corresponding OEIS sequence: $A275672$ (only terms $n=0..6$ are currently known).
For each $r \in [1, \ldots, 3 n^2]$ let $E_r$ be the set of unordered pairs $(p,q)$ of points in $S_n$ such that $\|p-q\|^2 = r$. We want a largest possible subset $X$ of $S_n$ such that $X$ contains at most one of each $E_r$. It can be considered as a quadratically constrained integer programming problem:
maximize $\sum_{p \in S_n} x_p$
subject to $\sum_{(p,q) \in S_r} x_p x_q \le 1$ for each $r$
all $x_p \in \{0,1\}$
Not that there are efficient methods to solve this, but CPLEX ought to be able to do this for small $n$.
EDIT: It appears that a careful integer linear programming model (with binary variables for both edges and vertices) works better. The results for small $n$ are
$$ \matrix{n & a_n\cr 1 & 1\cr 2 & 3\cr 3 & 4\cr 4 & 6\cr}$$ I have some faint hopes of getting $a_5$ (so far CPLEX has found a solution with $7$ vertices and an upper bound of $19.51$)
EDIT: CPLEX crashed before obtaining an optimal solution for $n=5$. An example to show $a_5 \ge 7$ is $$\pmatrix{ 3 & 4 & 2\cr 1 & 2 & 2\cr 4 & 4 & 2\cr 5 & 5 & 2\cr 5 & 1 & 4\cr 5 & 5 & 4\cr 2 & 1 & 5\cr}$$
EDIT:
For $n=6$, Jyrki's estimate shows $a_6 \le 9$, and (using tabu search) I was able to find an example to show $a_6 = 9$:
$$ \pmatrix{ 4 & 3 & 1\cr 1 & 5 & 4\cr 1 & 2 & 6\cr 6 & 1 & 1\cr 1 & 6 & 4\cr 2 & 5 & 3\cr 2 & 2 & 2\cr 6 & 2 & 6\cr 1 & 6 & 6\cr}$$
EDIT: I was able to find an example to show $a_7 \ge 10$: $$\pmatrix{ 1 & 7 & 7\cr 5 & 7 & 1\cr 7 & 2 & 2\cr 7 & 5 & 5\cr 1 & 2 & 2\cr 1 & 4 & 7\cr 2 & 7 & 7\cr 7 & 6 & 4\cr 1 & 7 & 5\cr 6 & 3 & 1\cr}$$
Still trying for $11$.