I have the following problem.
Given an array of 2*N elements, the first and second halves are x and y coordinates.
I want to calculate the smallest distance between those points.
As example:
sol = [0.37454012, 0.95071431, 0.73199394, 0.59865848, 0.15601864,
0.15599452, 0.05808361, 0.86617615, 0.60111501, 0.70807258]
The respective points are:
[(0.3745401188473625, 0.15599452033620265),
(0.9507143064099162, 0.05808361216819946),
(0.7319939418114051, 0.8661761457749352),
(0.5986584841970366, 0.6011150117432088),
(0.15601864044243652, 0.7080725777960455)]
The smallest distance is equal to 0.29670818834575136
Right now I solve with this code bellow:
import numpy as np
from scipy.spatial.distance import cdist
np.random.seed(42)
sol = np.random.rand(10)
x = sol[:len(sol)//2]
y = sol[len(sol)//2:]
points = list(zip(x,y))
m = cdist(points, points, 'euclidean')
m = m + np.where(np.eye(m.shape[0])>0,np.inf,0)
smallest = m.min()
Is there any faster way to do this? That's the objective function inside an heuristic and it is calculated thousands of times.