Optimization Problems
Before choosing an algorithm you must write the problem down precisely. The way you write it decides which methods apply, how fast they run and whether the answer they return is guaranteed to be the best one.
Standard form
Boyd and Vandenberghe's standard form is
Any problem can be brought into it:
| You have | Write it as |
|---|---|
| maximize | minimize |
| two constraints and | |
The optimal value is . It is if no point is feasible (the problem is infeasible) and if the objective can be made as small as you like (unbounded below).
Local and global optima
A feasible is a global minimum if for every feasible , and a local minimum if this holds for feasible in some ball around . Most algorithms only promise local minima. Convex problems are special because every local minimum is global (see Convex Functions).
import numpy as np
f = lambda x: np.sin(3 * x) + 0.1 * x**2 # many local minima
xs = np.linspace(-6, 6, 120001)
fx = f(xs)
is_local = (fx[1:-1] < fx[:-2]) & (fx[1:-1] < fx[2:])
local_x = xs[1:-1][is_local]
print("local minima at x =", np.round(local_x, 3))
print("global minimum at x =", round(float(xs[np.argmin(fx)]), 3), " f =", round(float(fx.min()), 4))local minima at x = [-4.608 -2.561 -0.512 1.537 3.585 5.631]
global minimum at x = -0.512 f = -0.9732
A taxonomy of problems
The structure of , and puts a problem into a class, and each class has its own algorithms:
| Class | Objective and constraints | Typical method | Lessons |
|---|---|---|---|
| Unconstrained smooth | differentiable , no constraints | gradient, Newton, BFGS | part 2 |
| Linear program (LP) | linear objective, linear constraints | simplex, interior point | part 4 |
| Quadratic program (QP) | convex quadratic objective, linear constraints | active set, interior point | part 5 |
| Convex | convex , affine | interior point, proximal | parts 1, 3, 6 |
| Integer / mixed-integer | some variables in | branch and bound | part 8 |
| Black box | no gradients, maybe noisy | Nelder-Mead, annealing | part 9 |
Recognizing the class is half the work. "Least squares with " is a QP; "minimize the largest of several linear functions" is an LP after a trick (Modelling with Linear Programs).
Infeasible and unbounded in practice
Solvers report these cases instead of a solution, and your code should check the status:
from scipy.optimize import linprog
# infeasible: x >= 3 and x <= 1
r1 = linprog(c=[1], A_ub=[[-1], [1]], b_ub=[-3, 1], bounds=[(None, None)])
# unbounded: minimize -x with only x >= 0
r2 = linprog(c=[-1], bounds=[(0, None)])
print("status", r1.status, "-", r1.message.split(".")[0])
print("status", r2.status, "-", r2.message.split(".")[0])status 2 - The problem is infeasible
status 3 - The problem is unbounded
Equivalent problems
Two problems are equivalent if a solution of one gives a solution of the other easily. Useful transformations: change variables (), apply an increasing function to the objective (minimizing and give the same ), add slack variables ( becomes , ), and move the objective into a constraint (epigraph form: minimize subject to ).
In software
- Modelling languages (CVXPY, Pyomo, JuMP, PuLP, OR-Tools) let you write a problem close to the math and then convert it to the standard form a solver expects.
- Every solver returns a status code (optimal, infeasible, unbounded, iteration limit). Production code must branch on it, never assume success.
Exercises
Exercise 1: Standard form
Write "maximize subject to , " in standard form.
Answer
Minimize subject to , , .
Solution
Flip the sign of the objective, move every right-hand side to the left so each constraint reads "", and split the double inequality into two constraints.
Exercise 2: Infeasible, unbounded or fine?
Classify: (a) minimize subject to ; (b) minimize subject to ; (c) minimize subject to and .
Answer
(a) optimal, ; (b) unbounded, ; (c) infeasible, .
Solution
In (a) the smallest feasible is 2. In (b) can go to . In (c) no number is at least 2 and at most 1.
Exercise 3: Count the minima (code)
How many local minima does have on , and which is global? Use the first example.
Answer
Six local minima; the global one is near .
Solution
The output lists the interior grid points lower than both neighbours. The term lifts the outer valleys, so the one closest to 0, where at , wins.
Test yourself
In standard form, a constraint is written as…
The optimal value of an infeasible minimization problem is, by convention…
- undefined
Minimizing and …
- give the same minimizer
- give different minimizers
- only the second has a minimizer
- only the first is convex