Given a weighted directed graph G = (V, E) , a source vertex s , a destination vertex t and a subset v’, how to finds the shortest non-loop path from s to vertex t in the graph? The vertexs in the subset must be included in the path.
This is a variant of Traveling Salesman Problem (TSP).
You can transform your problem to an exact instance of TSP, by running all-to-all shortest path in the graph (Floyd Warshall Algorithm), and then create a new graph:
G'={V' U {s,t}, E'}
V' - the "must go through" subset
E' = { (s,v), (v,t), (u,v) | u,v in V'} (In words: all edges between two nodes in the new graphs)
Now, finding the miminal path that goes through all nodes (TSP) in G'
, is also the minimal path that meets the criteria (after expending each path between two pairs back).
Unfortunately, TSP is NP-Complete problem (there is no known polynomial time algorithm to solve it, and most believe one doesn't even exist), and unless your set of "must go through nodes" V'
is relatively small (and you can afford exponential time running time of the algorithm), you will need to settle on a "good enough" algorithm, which might not be optimal.
Sidenote regarding "no loops" - note it might be infeasible, for example:
---------
| |
v |
s -> a -> b -> c
|
|
t
In this example, the only path to meet the criteria is s->a->b->c->t