Exploring Pyomo for Optimization Problem
Introduction
First install pyomo:
conda install -c conda-forge pyomo
conda install -c conda-forge pyomo.extras
Then install solver which needed to compute solutions to the optimization models developed using Pyomo. Different open-source solvers do exist:
- glpk: “GNU Linear Programming Kit” is a software package written in highly portable C for the solution of mixed integer linear programming and related problems.
- ipopt:”Interior Point Optimizer” for large scale nonlinear optimization of continuous systems.
- cbc: “COIN-OR Branch and Cut” is a mixed integer linear programming solver written in C++. It generally solves the same problems as glpk, but can run multiple threads, and is often faster and more robust.
conda install -c conda-forge glpk
conda install -c conda-forge ipopt
conda install -c conda-forge coincbc
It is also possible to use CPLEX linear solver, as described in this tutorial
Modelling basics
Key concepts for modeliing problems
- Variables: Represent unknown or changing parts of a model
- Parameters: Symbolic representations for real-world data, which might vary for different problem instances or scenarios.
- Relations: Are equations, inequalities, or other mathematical relationships that define how different parts of a model are related to each other.
Pyomo s python libraries for describing optimization problems. This can be achieved through simple modeling process are:
- Create model and declare components
- Instantiate the model
- Apply solver
- Interrogate solver results
A typical Pyomo application involves the creation of at least two Pyomo objects from the following classes:
- ConcreteModel() A python object representing the optimization problem to be solved.
- SolverFactory() A python object representing the mathematical progamming software to be used for calculating a solution.
Pyomo model, is composed of additional set of classes used to specify a problem. These classes are
- Set: set data that is used to define a model instance
- Param: parameter data that is used to define a model instance
- Var:decision variables in a model
- Objective: expressions that are minimized or maximized in a model
- Constraint: constraint expressions that impose restrictions on variable values in a model
Consider the following problem:
\(\begin{align} \max_{x,y \geq 0} &\ 40\ x + 30\ y & \mbox{objective}\\ \mbox{subject to:}\qquad \\ x & \leq 40 & \mbox{demand constraint} \\ x + y & \leq 80 & \mbox{labor A constraint} \\ 2x + y & \leq 100 & \mbox{labor B constraint} \end{align}\) where $x$ and $y$ are the rates of production (in units per week) for two products.
References
- https://jckantor.github.io/ND-Pyomo-Cookbook/toc.html
- http://edge.rit.edu/content/P18751/public/Google%20drive%20backup/Pyomo%20-%20Optimization%20Modeling%20in%20Python%2C%20Second%20Edition.pdf
- https://www.ima.umn.edu/materials/2017-2018.2/W8.21-25.17/26326/3_PyomoFundamentals.pdf
- https://ndcbe.github.io/CBE60499/toc.html