Path: blob/main/notebooks/06/01-economic-order-quantity.ipynb
663 views
6.1 Economic Order Quantity
This notebook demonstrates the reformulation of hyperbolic constraints as SOCO with implementation with pyomo.kernel.conic.quadratic and also the direct modeling of the hyperbolic constraint with pyomo.kernel.conic.rotated_quadratic. The example is familiar to any MBA/business student, and has a significant range of applications including warehouse operations.
Usage notes
The notebook requires a solver that can handle a conic constraint. Pyomo provides a direct interface to the commercial solvers Gurobi and Mosek that include conic solvers. Other nonlinear solvers may solve this problems using more general techniques that are not specific to conic constraints.
For personal installations of Mosek or Gurobi (free licenses available for academic use), use
mosek_directorgurobi_direct.If you do not have access to the Gurobi or Mosek, you can use the
ipoptsolver. Note, however, thatipoptis a general purpose interior point solver, and does not have algorithms specific to conic problems.
The EOQ model
Classical formulation for a single item
The economic order quantity (EOQ) is a classical problem in inventory management attributed to Ford Harris (1915). This optimization model aims to identify the order quantity that minimizes the cost of maintaining a specific item in the inventory.
Let be the annual cost of holding an item including any financing charges, be the fixed cost of placing and receiving an order, and be the annual demand. If a quantity of the product is ordered, it costs to place the order, resulting in a per-item order cost of . Assuming that the demand is uniform in time, it will take years for the demand to completely deplete the inventory and, therefore, an average item will remain in the inventory for years, incurring a cost . To minimize the average per-item cost, we minimize the function
which, modulo multiplying by , is equivalent to minimizing the function
The economic order quantity (EOQ) is the value of that minimizes , i.e., the optimal solution of the following optimization problem
Given the rather simple domain, we can derive analytically the solution for the EOQ problem by setting the derivative of equal to zero and solving the resulting equation, obtaining
The following chart illustrates the nature of the problem and its analytical solution.
Reformulating EOQ as a linear objective with hyperbolic constraint
However, if the problem involved multiple products, an analytical solution would no longer be easily available. For this reason, we need to be able to solve the problem numerically, let us see how.
It can be easily checked that the objective is a convex function and therefore, the problem can be solved using any convex optimization solver. It is, however, a special type of convex problem which we shall show in the following reformulation.
The optimization objective is linearized with the use of a second decision variable . The optimization problem is now a linear objective in two decision variables with a hyperbolic constraint .
This constraint and the linear contours of the objective function are shown in the following diagrams. The solution of optimization problem occurs at a point where the constraint is tangent to contours of the objective function.
Reformulating the EOQ model with a linear objective and a second order cone constraint
In elementary geometry, a hyperbola can be constructed from the intersection of a linear plane with cone. For this application, the hyperbola described by the constraint invites the question of whether there is reformulation of EOQ that includes a cone constraint.
A Lorenz cone is defined by
where the components of are given by . The intersection of a plane aligned with the axis exactly describes a hyperbola. As described by Lobo, et al. (1998), the correspondence is given by
where the axis in the coordinates is tilted, displaced, and stretched compared to the coordinates shown in the diagram. The exact correspondence to the diagram is given by
The Python code below draws a hyperbola precisely as the intersection of a plane with Lorenz cone.
Let us know rewrite the nonlinear constraint of the EOQ problem. Using the same geometric idea as above and leveraging the non-negativity of both variables, the constraint can be reformulated using the following trick:
where we rely on the fact that . The final constraint is known as a second-order conic optimization constraint (SOCO constraint). The result is a reformulation of the EOQ problem as a second order conic optimization (SOCO).
Pyomo modeling with conic.quadratic
The SOCO formation given above needs to be reformulated one more time to use with the Pyomo conic.quadratic constraint. The first step is to introduce rotated coordinates and , and introduce a new variable with fixed value , to fit the Pyomo model for quadratic constraints,
This version of the model with variables could be implemented directly in Pyomo with conic.quadratic. However, the model can be further reduced to yield a simpler version of the model.
The EOQ model is now ready to implement with Pyomo and specifically using the Pyomo kernel library. The Pyomo kernel library provides an experimental modeling interface for advanced application development with Pyomo. In particular, the kernel library provides direct support for conic constraints with the Mosek or Gurobi commercial solvers (note that academic licenses are available at no cost).
The Pyomo interface to conic solvers includes six forms for conic constraints. The conic.quadratic constraint is expressed in the form
where the and terms are pyomo.kernel variables. Note the slightly different syntax of the Pyomo kernel commands.
The .as_domain() method simplifie the Pyomo model
pyomo.kernel provides additional support for conic solvers with the .as_domain() method that be applied to the conic solver interfaces. Adding .as_domain allows use of constants, linear expressions, or None in place of Pyomo variables. For this application, this means u does not have to be included as a Pyomo variable and constrained to a fixed value. The required value can simply be inserted directly into constraint specification as demonstrated below.
Pyomo Modeling with conic.rotated_quadratic
The need to rotate the natural coordinates of the EOQ problem to fit the programming interface to conic.quadratic is not a big stumbling block, but does raise the question of whether there is a more natural way to express hyperbolic or cone constraints in Pyomo.
pyomo.kernel.conic.rotated_quadratic expresses constraints in the form
This enables a direct a expression of the hyperbolic constraint by introducing an auxiliary variable with fixed value such that
The model to be implemented in Pyomo is now
which is demonstrated below. Note the improvement in accuracy of this calculation compared to the previous solutions. Also note the use of .as_domain() eliminates the need to specify a variable .
Extending the EOQ model multiple items with a shared resource
Solving for the EOQ for a single item using SOCO optimization is using a sledgehammer to swat a fly. However, the problem becomes more interesting for determining economic order quantities when the inventories for multiple items compete for a shared resource in a common warehouse. The shared resource could he financing available to hold inventory, space in a warehouse, or specialized facilities to hold a perishable
where is the annual holding cost for one unit of item , is the cost to place an order and receive delivery for item , and is the annual demand. The additional constraint models an allocation of of the shared resource, and is the total resource available.
Following the reformulation of the single item model, a variable , is introduced to linearize the objective
Following the discussion above regarding rotated quadratic constraints, auxiliary variables for is introduced
The following Pyomo model is a direct implementation of the multi-time EOQ formulation and applied to a hypothetical car parts store that maintains an inventory of tires.
Testing the model on larger problems
The following cell creates a random EOQ problem of size that can be used to test the model formulation and solver.
Bibliographic notes
The original formulation and solution of the economic order quantity problem is attributed to Ford Harris, but in a curious twist has been cited incorrectly since 1931. The correct citation is:
Harris, F. W. (1915). Operations and Cost (Factory Management Series). A. W. Shaw Company, Chap IV, pp.48-52. Chicago.
Harris later developed an extensive consulting business and the concept has become embedded in business practice for over 100 years. Harris's single item model was later extended to multiple items sharing a resource constraint. There may be earlier citations, but this model is generally attributed to Ziegler (1982):
Ziegler, H. (1982). Solving certain singly constrained convex optimization problems in production planning. Operations Research Letters, 1(6), 246-252. https://www.sciencedirect.com/science/article/abs/pii/016763778290030X
Bretthauer, K. M., & Shetty, B. (1995). The nonlinear resource allocation problem. Operations research, 43(4), 670-683. https://www.jstor.org/stable/171693?seq=1
Reformulation of the multi-item EOQ model as a conic optimization problem is attributed to Kuo and Mittleman (2004) using techniques described by Lobo, et al. (1998):
Kuo, Y. J., & Mittelmann, H. D. (2004). Interior point methods for second-order cone programming and OR applications. Computational Optimization and Applications, 28(3), 255-285. https://link.springer.com/content/pdf/10.1023/B:COAP.0000033964.95511.23.pdf
Lobo, M. S., Vandenberghe, L., Boyd, S., & Lebret, H. (1998). Applications of second-order cone programming. Linear algebra and its applications, 284(1-3), 193-228. https://web.stanford.edu/~boyd/papers/pdf/socp.pdf
The multi-item model has been used didactically many times since 2004. These are representative examples
Letchford, A. N., & Parkes, A. J. (2018). A guide to conic optimisation and its applications. RAIRO-Operations Research, 52(4-5), 1087-1106. http://www.cs.nott.ac.uk/~pszajp/pubs/conic-guide.pdf
El Ghaoui, Laurent (2018). Lecture notes on Optimization Models. https://inst.eecs.berkeley.edu/~ee127/fa19/Lectures/12_socp.pdf
Mosek Modeling Cookbook, section 3.3.5. https://docs.mosek.com/modeling-cookbook/cqo.html.
Appendix: Formulation with SOCO constraints
Pyomo's facility for directly handling hyperbolic constraints bypasses the need to formulate SOCO constraints for the multi-item model. For completeness, however, that development is included here.
As a short cut to reformulating the model with conic constraints, note that a "completion of square" gives the needed substitutions
The multi-item EOQ model is now written with conic constraints
Variables , , and are introduced t complete the reformulation for implementation with Pyomo/Mosek.