Shortest Path Problem
Interestingly, the problem of finding the shortest path through a directed weighed graph has a tight approximation in the form of an LP. Let’s consider a weighed graph
graph LR;
A["Origin"];
D["Destination"];
A-->|"10"|B1;
A-->|"8"|B2;
B1-->|"6"|C1;
B1-->|"2"|C2;
B2-->|"4"|C1;
B2-->|"5"|C2;
C1-->|"8"|D;
C2-->|"9"|D;
The weight of each edge can be regarded as a distance or any other abstract cost associated with traversing it.
Mathematical Model
Let’s assign decision variables to each edge of the graph.
graph LR;
A["Origin"];
D["Destination"];
A-->|"x₀"|B1;
A-->|"x₁"|B2;
B1-->|"x₂"|C1;
B1-->|"x₃"|C2;
B2-->|"x₄"|C1;
B2-->|"x₅"|C2;
C1-->|"x₆"|D;
C2-->|"x₇"|D;
If we select to traverse a specific edge which is associated with the cost , where are the weights of individual edges. Naturally we must also include the constraint to ensure that we traverse through the graph as well as constraints ensuring continuity in the graph’s vertices. One would expect that would have to be binary, but they can be in fact continuous variables.
The problem as a whole takes the form where
Undirected Graph Problem
If the graph is undirected we are solving the problem This problem can in-fact be reformulated into an LP by introducing a vector of additional decision variables , where if we traverse the given edge in the opposite direction