Path: blob/main/notebooks/04/03-gasoline-distribution.ipynb
663 views
4.3 Gasoline distribution
This notebook presents a transportation model to optimally allocate the delivery of a commodity from multiple sources to multiple destinations. The model invites a discussion of the pitfalls in optimizing a global objective for customers who may have an uneven share of the resulting benefits, then through model refinement arrives at a group cost-sharing plan to delivery costs.
Preamble: Install Pyomo and a solver
The following cell sets and verifies a global SOLVER for the notebook. If run on Google Colab, the cell installs Pyomo and the HiGHS solver, while, if run elsewhere, it assumes Pyomo and HiGHS have been previously installed. It then sets to use HiGHS as solver via the appsi module and a test is performed to verify that it is available. The solver interface is stored in a global object SOLVER for later use.
Didactically, this notebook presents techniques for Pyomo modeling and reporting including:
pyo.ExpressiondecoratorAccessing the duals (i.e., shadow prices)
Methods for reporting the solution and duals.
Pyomo
.display()method for Pyomo objectsManually formatted reports
Pandas
Graphviz for display of results as a directed graph.
Problem: Distributing gasoline to franchise operators
YaYa Gas-n-Grub is the franchisor and operator of a network of regional convenience stores that sell gasoline and convenience items in the United States. Each store is individually owned by a YaYa Gas-n-Grub franchisee who pays fees to the franchisor for services. Gasoline is delivered by truck from regional distribution terminals by the current supplier. Each truck delivers 8,000 gallons at a fixed charge of $700 per delivery or $0.0875 per gallon. Franchise owners are eager to reduce delivery costs to boost profits.
YaYa Gas-n-Grub decides to accept proposals from other distribution terminals, "A" and "B", to supply the franchise operators. Rather than a fixed fee per delivery, they proposed pricing based on location. But they already have existing customers, "A" and "B" can only provide a limited amount of gasoline to new customers totaling 100,000 and 80,000 gallons respectively. The only difference between the new suppliers and the current supplier is the delivery charge.
The following chart shows the pricing of gasoline delivery in cents/gallon.
| Franchisee | Demand | Current Supplier 500,000 | Terminal A 100,000 | Terminal B 80,000 |
|---|---|---|---|---|
| Alice | 30,000 | 8.75 | 8.3 | 10.2 |
| Badri | 40,000 | 8.75 | 8.1 | 12.0 |
| Cara | 50,000 | 8.75 | 8.3 | - |
| Dan | 80,000 | 8.75 | 9.3 | 8.0 |
| Emma | 30,000 | 8.75 | 10.1 | 10.0 |
| Fujita | 45,000 | 8.75 | 9.8 | 10.0 |
| Grace | 80,000 | 8.75 | - | 8.0 |
| Helen | 18,000 | 8.75 | 7.5 | 10.0 |
| TOTAL | 313,000 |
The operator of YaYa Gas-n-Grub wants to allocate gasoline delivery in such a way that the costs to franchise owners are minimized.
Model 1: Minimize total delivery cost
The first optimization model aims to minimize the total cost of delivery to all franchise owners.
We introduce the decision variables , where subscript refers to the destination of the delivery and subscript to the source. The value of is the volume of gasoline shipped to destination from source .
Given the cost rate for delivering one unit of gasoline from to , the objective is to minimize the total cost of transporting gasoline from the sources to the destinations subject to meeting the demand requirements, , at all destinations, and satisfying the supply constraints, , at all sources.
In mathematical terms, we can write the full problem as
Data Entry
The data is stored into Pandas DataFrame and Series objects. Note the use of a large rates to avoid assigning shipments to destination-source pairs not allowed by the problem statement.
The following Pyomo model is an implementation of the mathematical optimization model described above. The sets and indices have been designated with more descriptive symbols readability and maintenance.
Model 2: Minimize cost rate for franchise owners
Minimizing total costs provides no guarantee that individual franchise owners will benefit equally, or in fact benefit at all, from minimizing total costs. In this example neither Emma or Fujita would save any money on delivery costs, and the majority of savings goes to just one of the franchisees. Without a better distribution of the benefits there may be little enthusiasm among the franchisees to adopt change. This observation motivates an attempt at a second model. In this case the objective is minimizing a common rate for the cost of gasoline distribution subject to meeting the demand and supply constraints, , at all sources.
The mathematical formulation of this different problem is as follows:
The following Pyomo model implements this formulation.
Model 3: Minimize total cost for a cost-sharing plan
The prior two models demonstrated some practical difficulties in realizing the benefits of a cost optimization plan. Model 1 will likely fail in a franchiser/franchisee arrangement because the realized savings would be for the benefit of a few.
Model 2 was an attempt to remedy the problem by solving for an allocation of deliveries that would lower the cost rate that would be paid by each franchisee directly to the gasoline distributors. Perhaps surprisingly, the resulting solution offered no savings to any franchisee. Inspecting the data shows the source of the problem is that two franchisees, Emma and Fujita, simply have no lower cost alternative than the current supplier. Therefore, finding a distribution plan with direct payments to the distributors that lowers everyone's cost is an impossible task.
We now consider a third model that addresses this problem with a plan to share the cost savings among the franchisees. In this plan, the franchiser would collect delivery fees from the franchisees to pay the gasoline distributors. The optimization objective returns to the problem to minimizing total delivery costs, but then adds a constraint that defines a common cost rate to charge all franchisees. By offering a benefit to all parties, the franchiser offers incentive for group participation in contracting for gasoline distribution services.
In mathematical terms, the problem can be formulated as follows:
Comparing model results
The following charts demonstrate the difference in outcomes for Model 1 and Model 3 (Model 2 was left out as entirely inadequate). The group cost-sharing arrangement produces the same group savings, but distributes the benefits in a manner likely to be more acceptable to the majority of participants.
Appendix: Reporting solutions
Pyomo models can produce considerable amounts of data that must be summarized and presented for analysis and decision making. In this application, for example, the individual franchise owners receive differing amounts of savings which is certain to result in considerable discussion and possibly negotiation with the franchiser.
The following cells demonstrate techniques for extracting and displaying information generated by a Pyomo model.
Pyomo .display() method
Pyomo provides a default .display() method for most Pyomo objects. The default display is often sufficient for model reporting requirements, particularly when initially developing a new application.
Manually formatted reports
Following solution, the value associated with Pyomo objects are returned by calling the object as a function. The following cell demonstrates the construction of a custom report using Python f-strings and Pyomo methods.
Pandas
The Python Pandas library provides a highly flexible framework for data science applications. The next cell demonstrates the translation of Pyomo object values to Pandas DataFrames
Graphviz
The graphviz utility is a collection of tools for visually graphs and directed graphs.