Automatic calculation of neighbors