In conclusion, I suggest starting the Dijkstra's algorithm from all points on your original rectangle at the same time as the modified stop condition. The algorithm keeps track of the current low special distance found so far during the search, and does not look for further points that are already farther than the current low special distance. Below is the pseudo code that uses a dictionary to store target point mappings => (best distance, starting point).
enqueue all points on source rectangle special distance = infinity while (queue not empty) { point = dequeue if (distance to point < best distance found to point AND distance to point < special distance) { best distance found to point = distance to point rect = rectangle of point if (all points found in rect) { special distance to this rect = max(distances found to this rect) if (special distance to this rect < special distance) { special distance = special distance to this rect } } } }
Motivation below:
You can run the Dijkstra algorithm to find all the points from each source point in the source rectangle before the set of target points. In fact, Dijkstra’s algorithm is the first width search in which you are just starting to search further from a point at the beginning of the queue if it matches the condition that it is the shortest path found for this point from the starting point.
If you used this condition, you will find the shortest path to all points. Then you can calculate the longest distance for each target rectangle and take the minimum of them - the “special distance” for this starting point (and then repeat for each point of the original rectangle and find the lowest special distance). However, this is too much work, since you will include many points in your search that are far from your starting point and which you do not need to consider.
What you can do is maintain the current low special distance detected during the start of the algorithm by determining when you found all the points for the rectangle and accordingly update the current low special distance (it starts with some big number like INT_MAX in C). Then you increase the condition in order to take the points forward, saying that their distance from the starting point should also be less than the current minimum special distance (it is clear if the current point is greater than the current low special distance, then you can’t better by considering the paths leading from him.)
If you are going to find special points for each rectangle, you may need to run the Floyd-Warshall algorithm , which will calculate the shortest distance between each pair of points.
source share