## Constrained optimization

| categories: optimization | tags:

Suppose we seek to minimize the function $$f(x,y)=x+y$$ subject to the constraint that $$x^2 + y^2 = 1$$. The function we seek to maximize is an unbounded plane, while the constraint is a unit circle. We could setup a Lagrange multiplier approach to solving this problem, but we will use a constrained optimization approach instead.

from scipy.optimize import fmin_slsqp

def objective(X):
x, y = X
return x + y

def eqc(X):
'equality constraint'
x, y = X
return x**2 + y**2 - 1.0

X0 = [-1, -1]
X = fmin_slsqp(objective, X0, eqcons=[eqc])
print X

Optimization terminated successfully.    (Exit mode 0)
Current function value: -1.41421356237
Iterations: 5
Function evaluations: 20