I have a graph data structure that has some source points (the red ones) and some destination points (the blue ones). I want to find the shortest path from every source point to its nearest destination point, or to its nearest source point that is already connected to a destination point by a shortest path.
I can find the shortest path from multiple sources to multiple destinations, but the problem is in the bold part above.
The output of the algorithm should be a list of shortest paths that satisfy the above criteria, plus that the sum of all paths length is minimum.
The sequence of the algorithm should be something like this:
- Start by a source point, and find the shortest path to its nearest destination point.
- Take another source point, and find the shortest path to either the nearest destination point or to the source point that has been connected in step 1.
- Repeat step 2 until all source points are connected.
How can I do that? What is the name of this type of algorithm that can solve this problem?
