How can I find the shortest path between two subgraphs of a larger graph?

Posted by Pops on Programmers See other posts from Programmers or by Pops
Published on 2014-08-23T19:51:35Z Indexed on 2014/08/23 22:33 UTC
Read the original article Hit count: 342

Filed under:
|

I'm working with a weighted, undirected multigraph (loops not permitted; most node connections have multiplicity 1; a few node connections have multiplicity 2). I need to find the shortest path between two subgraphs of this graph that do not overlap with each other. There are no other restrictions on which nodes should be used as start/end points.

Edges can be selectively removed from the graph at certain times (as explained in my previous question) so it's possible that for two given subgraphs, there might not be any way to connect them.

I'm pretty sure I've heard of an algorithm for this before, but I can't remember what it's called, and my Google searches for strings like "shortest path between subgraphs" haven't helped. Can someone suggest a more efficient way to do this than comparing shortest paths between all nodes in one subgraph with all nodes in the other subgraph? Or at least tell me the name of the algorithm so I can look it up myself?

For example, if I have the graph below, the nodes circled in red might be one subgraph and the nodes circled in blue might be another. The edges would all have positive integer weights, although they're not shown in the image. I'd want to find whatever path has the shortest total cost as long as it starts at a red node and ends at a blue node. I believe this means the specific node positions and edge weights cannot be ignored.

enter image description here

(This is just an example graph I grabbed off Wikimedia and drew on, not my actual problem.)

© Programmers or respective owner

Related posts about algorithms

Related posts about graph