TExcelTAD
Home › Optimization › Optimization Problems

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

minimizef0(x)subject tofi(x)≤0,i=1,…,mhj(x)=0,j=1,…,p\begin{aligned} \text{minimize} \quad & f_0(\mathbf{x}) \\ \text{subject to} \quad & f_i(\mathbf{x}) \le 0, \quad i = 1, \dots, m \\ & h_j(\mathbf{x}) = 0, \quad j = 1, \dots, p \end{aligned}

Any problem can be brought into it:

You have Write it as
maximize g(x)g(\mathbf{x}) minimize −g(x)-g(\mathbf{x})
g(x)≥bg(\mathbf{x}) \ge b b−g(x)≤0b - g(\mathbf{x}) \le 0
a≤xk≤ba \le x_k \le b two constraints a−xk≤0a - x_k \le 0 and xk−b≤0x_k - b \le 0
g(x)=bg(\mathbf{x}) = b g(x)−b=0g(\mathbf{x}) - b = 0

The optimal value is p∗=inf⁡{f0(x):x feasible}p^* = \inf\{f_0(\mathbf{x}) : \mathbf{x} \text{ feasible}\}. It is +∞+\infty if no point is feasible (the problem is infeasible) and −∞-\infty if the objective can be made as small as you like (unbounded below).

Local and global optima

A feasible x∗\mathbf{x}^* is a global minimum if f0(x∗)≤f0(x)f_0(\mathbf{x}^*) \le f_0(\mathbf{x}) for every feasible x\mathbf{x}, and a local minimum if this holds for feasible x\mathbf{x} in some ball around x∗\mathbf{x}^*. Most algorithms only promise local minima. Convex problems are special because every local minimum is global (see Convex Functions).

python · try it yourself
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 f0f_0, fif_i and hjh_j puts a problem into a class, and each class has its own algorithms:

Class Objective and constraints Typical method Lessons
Unconstrained smooth differentiable f0f_0, 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 f0,fif_0, f_i, affine hjh_j interior point, proximal parts 1, 3, 6
Integer / mixed-integer some variables in Z\mathbb{Z} 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 x≥0x \ge 0" 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:

python · try it yourself
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 (x=Tz\mathbf{x} = T\mathbf{z}), apply an increasing function to the objective (minimizing ∥Ax−b∥\lVert A\mathbf{x} - \mathbf{b} \rVert and ∥Ax−b∥2\lVert A\mathbf{x} - \mathbf{b} \rVert^2 give the same x\mathbf{x}), add slack variables (fi(x)≤0f_i(\mathbf{x}) \le 0 becomes fi(x)+si=0f_i(\mathbf{x}) + s_i = 0, si≥0s_i \ge 0), and move the objective into a constraint (epigraph form: minimize tt subject to f0(x)≤tf_0(\mathbf{x}) \le t).

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 2x+y2x + y subject to x+y≥1x + y \ge 1, 0≤x≤30 \le x \le 3" in standard form.

Answer

Minimize −2x−y-2x - y subject to 1−x−y≤01 - x - y \le 0, −x≤0-x \le 0, x−3≤0x - 3 \le 0.

Solution

Flip the sign of the objective, move every right-hand side to the left so each constraint reads "≤0\le 0", and split the double inequality into two constraints.

Exercise 2: Infeasible, unbounded or fine?

Classify: (a) minimize xx subject to x≥2x \ge 2; (b) minimize xx subject to x≤2x \le 2; (c) minimize xx subject to x≥2x \ge 2 and x≤1x \le 1.

Answer

(a) optimal, p∗=2p^* = 2; (b) unbounded, p∗=−∞p^* = -\infty; (c) infeasible, p∗=+∞p^* = +\infty.

Solution

In (a) the smallest feasible xx is 2. In (b) xx can go to −∞-\infty. In (c) no number is at least 2 and at most 1.

Exercise 3: Count the minima (code)

How many local minima does f(x)=sin⁡(3x)+0.1x2f(x) = \sin(3x) + 0.1x^2 have on [−6,6][-6, 6], and which is global? Use the first example.

Answer

Six local minima; the global one is near x=−0.5x = -0.5.

Solution

The output lists the interior grid points lower than both neighbours. The 0.1x20.1x^2 term lifts the outer valleys, so the one closest to 0, where sin⁡(3x)=−1\sin(3x) = -1 at x=−π/6≈−0.52x = -\pi/6 \approx -0.52, wins.

Test yourself

In standard form, a constraint g(x)≥bg(\mathbf{x}) \ge b is written as…

  1. g(x)−b≤0g(\mathbf{x}) - b \le 0
  2. b−g(x)≤0b - g(\mathbf{x}) \le 0
  3. g(x)+b=0g(\mathbf{x}) + b = 0
  4. −g(x)≥−b-g(\mathbf{x}) \ge -b

The optimal value of an infeasible minimization problem is, by convention…

  1. 00
  2. −∞-\infty
  3. +∞+\infty
  4. undefined

Minimizing ∥Ax−b∥\lVert A\mathbf{x} - \mathbf{b} \rVert and ∥Ax−b∥2\lVert A\mathbf{x} - \mathbf{b} \rVert^2…

  1. give the same minimizer
  2. give different minimizers
  3. only the second has a minimizer
  4. only the first is convex