working multidistance optimization