This file shows how to solve the shortest path problem for the SEERVADA PARK prototype example from Hillier and Lieberman, Section 9.1.

We define the node set and the distance values on each arc of the network:

We will need the list of all arcs later. We could hand-code it, but it's easier to extract it from D as the list of key values.

The SEERVADA PARK road network as described in the example is an undirected network. However, in the linear programming formulation of the shortest path problem, we can only use directed arcs. Thus, for each arc in D which we listed above, we need to add an arc of the same distance with opposite orientation. To save us some writing, we add the backlinks with two lines of Python code:

After augmenting the distance directory, we also need to update the list of arcs.

Now we can set up the model and the decision variable x, the flow on the network:

For the shortest path problem, we assume an inflow of 1 at the source node O and an outflow of 1 at destination node T. At all other nodes, inflow equals outflow.

The objective is minimizing distance traveled.

Now we solve and look at the results:

So the shortest path is O-A-B-D-T with a distance of 13. As you will recognize immediately in this simple example, there is an alternative shortest path O-A-B-E-D-T; Pyomo does not report such alternative solutions.