Skip to content

Latest commit

 

History

History
65 lines (53 loc) · 4.56 KB

README.md

File metadata and controls

65 lines (53 loc) · 4.56 KB

A Simple Framework For Solving Optimization Problems in Python Tweet

The framework is shown using a simple production planning example. The optimization model is written in pulp and the use of 5 different solvers is shown: CBC (default), Gurobi, CPLEX, XPRESS, and GLPK. For reference, the optimization model is also written and solved with gurobipy, docplex, and xpress.

Modules

All the modules that start with execute can be run as the main module. The optimization problem is modeled using pulp, gurobipy, docplex, and xpress packages. The codes are written for two different approaches: 1) scripting and 2) a more modular and object-oriented approach.

Scripting

You can start your journey of learning pulp, gurobipy, docplex or xpress using execute_pulp.py, execute_grb.py, execute_docplex.py, and execute_xpress.py scripts, respectively. There is documentation in each of these modules to learn different ways of defining variables and constraints.

Object-Oriented Approach

execute_oo.py is the starting module of this approach. Depending on what you like to learn, check optimization_model_pulp.py, optimization_model.grb.py, optimization_model_docplex.py or optimization_model_xpress.py. Due to similarities between these modules and what was described in the execute_pulp.py, execute_grb.py, execute_docplex.py and execute_xpress.py, some of the documentation are omitted. The default values in parameters.py are set to run the model in pulp which is also what you should expect by running execute_oo.py. If you wish execute_oo.py to run the model with CPLEX, Gurobi, or XPRESS, the least you should do is to change the value of module to 'cplex', 'gurobi', or 'xpress', respectively, in the parameters.py.

Regardless of the approach, we use the functionalities defined in helper.py, process_data.py, and parameters.py modules.

Note that compared to the standalone execute_*.py modules, the optimization_model_*.py modules have more details in their optimize function that show handling of various parameters. Moreover, optimization_model_docplex.py shows how to solve the model, using the local installation of CPLEX or with DOcplexcloud.

Production Planning Example

We are responsible for scheduling the monthly production plan of a product for a year. Here are the assumptions:

  • The demand of the product, unit production cost, and production capacity in each month are known and can be found here.
  • Inventory holding cost occurs at the end of each month.
  • Holding cost is $8 per unit per month.
  • There are 500 units of inventory available at the beginning of the first month. Unit holding cost and initial inventory are stored here.
  • No shortage is allowed.

The data for this example are stored in both csv and excel formats and you can use either by specifying your choice in the parameters.py. The output results are shown in the output folder.

Problem Formulation

Parameters:
h : unit holding cost
p : production capacity per month
I0 : initial_inventory
ct : unit production cost in month t
dt : demand of month t

Variables:
Xt : Amount produced in month t
It : Inventory at the end of period t

Model

Extra

You can check this blog that gives some backstory about the framework and more details about different modules.