2. Linear constrained optimization#
In this chapter, we’ll cover how to apply scipy.optimize.linprog
to linear constrained optimization problems. As a reminder, linear constrained optimization considers:
with:
, the linear objective function , the design variables , the linear inequality constraints , the linear inequality constraints and , the low er and upper bounds of the design variable
Because all functions are linear, this problem can be rewritten as:
with:
, the design variables , the coefficients of the linear objective function , the inequality constraint matrix of inequality constraints , the inequality constraint vector of inequality constraints , the equality constraint matrix of equality constraints , the equality constraint vector of equality constraints and , the lower and upper bounds of the design variable
Method#
For linear programs, we can use the function scipy.optimize.linprog
. In contrast to scipy.optimize.minimize
, this function is limited to linear functions. The documentation of this function is available here: https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.linprog.html [The SciPy community, 2024]. In this course we’ll cover only the relevant parts.
Again, we won’t use all options, but a minimum requirement for our problem is the command scipy.optimize.linprog(c, A_ub, b_ub, A_eq, b_eq, bounds, ...)
with:
c
, a onedimensional numpy array with the coefficients of the linear objective function .A_ub
, a twodimensional numpy array with the coefficient of the linear inequality constraints matrix .b_ub
, a onedimensional numpy array with the upper bound of the linear inequality constraint vector .A_eq
, a twodimensional numpy array with the coefficient of the linear equality constraints matrix .b_eq
, a onedimensional numpy array with value of the linear equality constraint vector .Bounds
: A sequence of(min, max)
pairs for each element in , defining the minimum and maximum values of that decision variable. UseNone
to indicate that there is no bound.
The function scipy.optimize.linprog
outputs an object scipy.optimize.OptimizeResult
similar as scipy.optimize.minimize
explained for unconstrained optimization.