Optimize nearest neighbor.