calculating the shortest path between all possible points