Model
As an object-oriented language, PYOMO organizes the optimization problem into a single object of type ConcreteModel. It contains all the other components as Python attributes. The model is declared in the following way:Decision Variables
The variables component is the “unknown part” of the model. The solver aims to assign values that constitute the best possible solution. Following is a description of the possible arguments for variable declaration in PYOMO. In many optimization problems, the variables are indexed. The index set is provided as the first argument to the PYOMO var object.Constraints
Constraints enrich the descriptive power of optimization problems. Different scenarios, rules, regulations, and variable relations may be phrased as conditions on decision variables that must be satisfied. In PYOMO, specify the constraints using equality or inequality expressions. There are several ways to integrate them inside the existing PYOMO model:- Using the
exprargument:
- Using a rule argument and a separate Python function:
- Using a Python constraint decorator:
Objective Function
The objective function encodes the essence of the best solution. It is a function of the decision variables, which return a real value that the optimization solver tries to minimize or maximize. It is incorporated into the PYOMO model similarly to the constraints: with anexpr argument, with a rule argument, or with a decorator.
An additional declaration argument is sense, which is set to minimize or maximize.
Importing
You can import all PYOMO components from thepyomo.environ sub-package:
Complete Example
graph may be either an instance of the
networkx.Graph class or the adjacency matrix in the form of List[List[int]].