Transportation problems deal with efficiently allocating resources from supply to demand node given a cost function. Using linear optimization, these problems can be solved using computational methods via python and the module PuLP.
In the proposed model, there exists two supply nodes-- each with their own respective production quantities and labor costs-- who must ship to five markets of different distances and retail prices. The goal of the model can be either a) cost-minimization or b) profit-maximization.
Complete code and formal write-up can be found @Github
Firstly, the producer and consumer nodes are given supply and demand quantities. These are posed as a dictionary in Python, as the dictionary data-structure makes it easier, opposed to an array, to call data later on. Notice that in addition to the cites, a node warehouse is created as both a demand and supply node. The economic rational behind this is that any extra supply is not simply lost, but instead stored until the next period at a cost. Conversely, if demand is greater than total production, product can be shipped from the warehouse to satisfy demand. In addition to the labor cost and shipping cost at the warehouse, the goods stored incur some set depreciation rate.
Next, we create a numpy array to house the distances Dij and the cost per mile along each route.
Here is where the magic happens: we setup a linear system of equations which can be solved (read: optimized) via PuLP. By defining the cost function:
Pulp then interprets the above and forms a separate .lp file which handles all the backend work. Simply put a print(value(prob.objective)) at the end and voila! There is your optimal route configuration.