Simplex is the first systematically method for solving linear program via a sequence of Gaussian eliminations. It was invented by George Dantzig in 1947 [1]. Algebraically, it converts the linear program from one slack form into to an equivalent one whose objective value does not decrease and possibly increase. It keeps going until the optimal is reached. Geometrically, it is a greedy search strategy that moves from a vertex of the feasible region to another one, with the objective value at the new vertex as least as good as or possibly improved over the previous one. It is an exponential algorithm, although most of time it does a lot better. In this blog we walk through a simple example to illustrate this.

In this case we are operating a factory with two products. Both product have 1 unit of profit. Making the products needs to use two kind of machine. Product one uses 1 hour of machine one and product two uses 2 hours of machine one. Further, product one uses 2 hours of machine two and product two uses 1 hour of machine two. Both machines operate at most 6 hours each day. We want to maximize our profit:

max⁡x1+x2s.t.x1+2x2≤62x1+x2≤6x1,x2≥0 \begin{aligned} &\max & x_1 + x_2 \\ &s.t. & x_1 + 2x_2 \le 6 \\ & & 2x_1 + x_2 \le 6 \\ & & x_1, x_2 \ge 0 \end{aligned}

It can be represented concisely in matrix form:

max⁡cTxs.t.Ax≤bx≥0 \begin{aligned} &\max & c^T x \\ &s.t. & A x \le b \\ & & x \ge 0 \end{aligned}

where

A=[1221],b=[66],c=[11],x=[x1x2], \begin{aligned} A = \left[ \begin{matrix} 1 & 2 \\ 2 & 1 \end{matrix} \right], \quad b = \left[ \begin{matrix} 6 \\ 6 \end{matrix} \right], \quad c = \left[ \begin{matrix} 1 \\ 1 \end{matrix} \right], \quad x = \left[ \begin{matrix} x_1 \\ x_2 \end{matrix} \right], \end{aligned}

We call the set of points that satisfy the constraints of the optimization problem the feasible region

P={x:Ax≤b,x≥0} P = \{x : Ax \le b, x \ge 0\}

It is obvious that the optimal is obtained at (2,2)(2, 2), which gives the objective value 44. It is a vertex of the feasible region.

Slack Form

In general, it might not be obvious what the optimal point is. But if the elements of bb are non-negative, the origin is a feasible point, from which we can begin our search. To make the search easier, we are going to introduce an additional number of variables, the slack variables s1,s2s_1, s_2 and zz that correspond to the constraints and objective value.

z=x1+x2s1=6−x1−2x2s2=6−2x1−x2 \begin{aligned} z = & & x_1 &+x_2 \\ s_1 = &6 & -x_1 &-2x_2 \\ s_2 = &6 & -2x_1 &-x_2 \\ \end{aligned}

rewrite the optimization into slack form:

max⁡x1+x2=zs.t.x1+2x2+s1=62x1+x2+s2=6x1,x2,s1,s2≥0 \begin{aligned} &\max & x_1 &+x_2 & & &= z\\ &s.t. & x_1 &+2x_2 &+s_1 & &= 6 \\ & & 2x_1 &+x_2 & &+s_2 &= 6 \\ & & x_1, &x_2, &s_1 &,s_2 &\ge 0 \end{aligned}

They are called slacks variables because they correspond how much slack you have in the inequalities in the original problem. For this slack form, we also call s1s_1 and s2s_2 basic variables, and the original variables non-basic variables.

Now the feasible region FF is considered as the intersection of the two subspaces

F={x:Ax=b}∩{x≥0} F = \{x : Ax = b \} \cap \{ x \ge 0 \}

We can represent the LP in slack form even more concisely in a table:

1210∣62101∣61100∣0 \begin{aligned} 1 && 2 && 1 && 0 && \mid 6 \\ 2 && 1 && 0 && 1 && \mid 6 \\ \hline 1 && 1 && 0 && 0 && \mid 0 \\ \end{aligned}

where the last column denotes the objective function. This example has a trivial starting point : (0,0,6,6)(0, 0, 6, 6). It is called a basic solution in which all non-basic variables are set to zero. It can be read from the tabular form: the identity matrix correspond to basic variables, and (s1,s2)=b(s_1, s_2) = b.

Pivoting

Look at the original LP:

max⁡x1+x2=zs.t.x1+2x2+s1=62x1+x2+s2=6x1,x2,s1,s2≥0 \begin{aligned} &\max & x_1 &+x_2 & & &= z\\ &s.t. & x_1 &+2x_2 &+s_1 & &= 6 \\ & & 2x_1 &+x_2 & &+s_2 &= 6 \\ & & x_1, &x_2, &s_1 &,s_2 &\ge 0 \end{aligned}

As we would like to maximize the objective, we would like to increase the value of x1x_1 or x2x_2 as much as possible. Suppose we just increase one variable at a time. For example, we can increase variable x1x_1 and keep the value of x2x_2 to be 00.

How much can we increase x1x_1? After increasing x1x_1, we need to maintain the inequality constraints:

x1+s1=62x1+s2=6 x_1 + s_1 = 6 \\ 2 x_1 + s_2 = 6

The values of s1s_1 and s2s_2 decrease as x1x_1 increases. By they can be drop below 00. The maximum possible increases of x1x_1 is bounded by 6/2=36 / 2 = 3. If we set x1=3x_1 = 3, s1=6−x1=3s_1 = 6 - x_1 = 3 and s2=6−2x1=0s_2 = 6 - 2x_1 = 0.

Note that x1x_1 increases from 00 to 33 and s2s_2 decreases from 66 to 00. This process is called pivoting.

How do we perform pivoting in the tabular form? By the replacement we have just performed -- normalizing the second row, and using it to eliminate all other elements in the first column.

Recall the original table:

1210∣62101∣61100∣0 \begin{aligned} 1 && 2 && 1 && 0 && \mid 6 \\ 2 && 1 && 0 && 1 && \mid 6 \\ \hline 1 && 1 && 0 && 0 && \mid 0 \\ \end{aligned}

We divide the second row by a factor of 2 to normalize it, and subtract the first and third row by the second row

03/21−1/2∣311/201/2∣301/20−1/2∣−3 \begin{aligned} 0 && 3/2 && 1 && -1/2 && \mid 3 \\ 1 && 1/2 && 0 && 1/2 && \mid 3 \\ \hline 0 && 1/2 && 0 && -1/2 && \mid -3 \\ \end{aligned}

Observe the first two rows of the tabular form:

03/21−1/2∣311/201/2∣3 \begin{aligned} 0 && 3/2 && 1 && -1/2 && \mid 3 \\ 1 && 1/2 && 0 && 1/2 && \mid 3 \\ \end{aligned}

If we set x2=0x_2 = 0 and s2=0s_2 = 0, the constraints they implies becomes

s1=3x1=3 s_1 = 3 \\ x_1 = 3

Again the unity columns correspond to non-zero elements and we can read the solution from the tabular form.

Correctness of Pivoting

Before we continue our search on the tabular form, we need to show that pivoting is correct in the sense that, after pivoting, the tabular form represents the same optimization.

In particular, we need to guarantee that the feasible regions are the same and the objective function are equivalent defined on the feasible regions.

We focus on the extended matrix that represents the constraints:

Aˉ=[A,b]=[1210∣62101∣6] \bar A = [A, b] = \left[\begin{aligned} 1 && 2 && 1 && 0 && \mid 6 \\ 2 && 1 && 0 && 1 && \mid 6 \\ \end{aligned}\right]

FACT 1. Doing a row replacement on Aˉ\bar A does not change FF, where row replacement is defined as

Aˉ[i:]←Aˉ[i:]+k⋅Aˉ[j:] \bar A[i: ] \leftarrow \bar A[i: ] + k \cdot \bar A[j: ]

i.e., adding kk times the jj-th row to the ii-th row, for i≠j,k∈Ri \neq j, k \in R.

To see this, denote FF and F′F' the sets before and after the replacement respectively. F=F′F = F' implies that each point xx belonging to FF belongs to F′F', and vice-versa. Specifically, the row replacement corresponds to left multiplying Aˉ\bar A by a matrix

E(i,j),k≐[11...k1...1] \begin{aligned} E_{(i,j), k} \doteq \left[ \begin{matrix} 1 & \\ & 1 \\ & & \quad... \\ & & k & 1 \\ & & & & ... \\ & & & & & 1 \end{matrix} \right] \end{aligned}

which is a diagonal matrix with an additional kk in the (i,j)(i, j) position. It is invertible with inverse matrix

E(i,j),−k≐[11...−k1...1] \begin{aligned} E_{(i,j), -k} \doteq \left[ \begin{matrix} 1 & \\ & 1 \\ & & \quad... \\ & & -k & 1 \\ & & & & ... \\ & & & & & 1 \end{matrix} \right] \end{aligned}

The previous claim becomes {x:E(i,j),kAx=E(i,j),kb}={x:Ax=b}\{ x : E_{(i, j), k} A x = E_{(i, j), k} b \} = \{ x : A x = b \}.

But wait. Why do we subtract the last row from the second one? Fact 1 has justified the replacement operation on Aˉ\bar A, but not on the objective coefficients cc (the last row in the tabular form). To illustrate the meaning of the operation, recall that

x1+x2+0⋅s1+0⋅s2=z x_1 + x_2 + 0 \cdot s_1 + 0 \cdot s_2 = z

Hence zz is the value of the objective function. After normalizing the second row, it becomes

x1+1/2x2+0s1+1/2s2=3 x_1 + 1 / 2 x_2 + 0 s_1 + 1/2 s_2 = 3 \\

The constraint holds for any feasible point of the linear programming. Therefore,

z−3=(x1+x2+0s1+0s2)−(x1+1/2x2+0s1+1/2s2)=0x1+1/2x2+0s1−1/2s2⇔z=0x1+1/2x2+0s1−1/2s2+3 \begin{aligned} z - 3 &= (x_1 + x_2 + 0 s_1 + 0 s_2) - (x_1 + 1 / 2 x_2 + 0 s_1 + 1/2 s_2) \\ &= 0x_1 + 1/2x_2 + 0s_1 - 1/2 s_2 \\ &\Leftrightarrow \\ z &= 0x_1 + 1/2x_2 + 0s_1 - 1/2 s_2 + 3 \end{aligned}

The last −3-3 in the table is the inverse constant in the objective functions after the replacement of variable.

To improve the current solution further, we note that the coefficient of x2x_2 is positive. We can increase the value of x2x_2. The maximum increase is given by min⁡{3/(1/2),3/(3/2)}=2\min \{ 3 / (1 / 2), 3 / (3/ 2) \} = 2, determined by the first row:

03/21−1/2∣311/201/2∣301/20−1/2∣−3 \begin{aligned} 0 && 3/2 && 1 && -1/2 && \mid 3 \\ 1 && 1/2 && 0 && 1/2 && \mid 3 \\ \hline 0 && 1/2 && 0 && -1/2 && \mid -3 \\ \end{aligned}

To make the change explicitly, we perform elimination by the first row

012/3−1/3∣210−1/32/3∣200−1/3−1/3∣−4 \begin{aligned} 0 && 1 && 2/3 && -1/3 && \mid 2 \\ 1 && 0 && -1/3 && 2/3 && \mid 2 \\ \hline 0 && 0 && -1/3 && -1/3 && \mid -4 \\ \end{aligned}

which give solution x=(2,2,0,0)x = (2, 2, 0, 0) and objective value 44. It is indeed optimal solution for the problem, as all coefficients of the optimization are non-positive.

Optimality Condition and Strong Duality

We investigate the result deeper by viewing the initial tabular form in abbreviation as

[AI∣bcT0∣0] \left[ \begin{matrix} A \quad I \mid b \\ c^T \quad 0 \mid 0 \end{matrix} \right]

The series of mm Gaussian elimination can be interpreted as left multiplying a matrix:

[R0−yT1]≐Em...E3E2E1 \begin{aligned} \left[ \begin{matrix} & R & 0 \\ & -y^T & 1 \\ \end{matrix} \right] \doteq E_m...E_3 E_2 E_1 \end{aligned}

where each EjE_j ( 1≤j≤m1 \le j \le m) matrix is invertible and represents a Gaussian elimination, i.e., if we left multiple a matrix by EjE_j, it is equivalent to perform Gaussian elimination on the matrix. The matrix product Em...E3E2E1E_m...E_3 E_2 E_1 has the form

[R0−yT1] \begin{aligned} \left[ \begin{matrix} & R & 0 \\ & -y^T & 1 \\ \end{matrix} \right] \end{aligned}

because we never use the last row to eliminate the other rows.

Now:

[R0−yT1][AI∣bcT0∣0]=[RAR∣Rb−yTA+cT−yT∣−yTb] \begin{aligned} \left[ \begin{matrix} & R & 0 \\ & -y^T & 1 \\ \end{matrix} \right] \left[ \begin{matrix} & A & I \mid b \\ & c^T & 0 \mid 0 \end{matrix} \right] = \left[ \begin{matrix} & RA & R & \mid & Rb \\ & -y^TA+c^T & -y^T &\mid & -y^T b \end{matrix} \right] \end{aligned}

In our example,

1210∣62101∣61100∣0⇒...⇒012/3−1/3∣210−1/32/3∣200−1/3−1/3∣−4 \begin{aligned} 1 && 2 && 1 && 0 && \mid 6 \\ 2 && 1 && 0 && 1 && \mid 6 \\ \hline 1 && 1 && 0 && 0 && \mid 0 \\ \end{aligned} \Rightarrow ... \Rightarrow \begin{aligned} 0 && 1 && 2/3 && -1/3 && \mid 2 \\ 1 && 0 && -1/3 && 2/3 && \mid 2 \\ \hline 0 && 0 && -1/3 && -1/3 && \mid -4 \\ \end{aligned}

we have

R=[2/3−1/3−1/32/3]yT=[−1/3,−1/3] R = \begin{aligned} \left[ \begin{matrix} 2 / 3 & -1 / 3 \\ -1 / 3 & 2 /3 \end{matrix} \right] \end{aligned} \qquad y^T = [ -1 / 3, -1 / 3]

The optimality condition of simplex algorithm implies that

−yTA+cT≤0yT≤0yTb=cTx \begin{aligned} -y^T A + c^T &\le 0 \\ y^T &\le 0 \\ y^T b &= c^T x \end{aligned}

This is the optimal solution for the dual program of the primal:

min⁡ bTy,s.t.,ATy≥c,yT≥0 \min \ b^T y, \qquad s.t., A^T y \ge c, \quad y^T \ge 0

If simplex algorithm stops, it implies strong duality holds:

  • The optimal value of the primal program equals to the optimal one of the dual program, assuming that both values exist and are bounded.
Geometric Interpretation

In the beginning we claim that the simplex algorithm move from one vertex to another. We prove it rigorously in this section. First we need a few definitions:

Vertex

A vertex is a point v∈Fv \in F, such that ∄v1,v2∈F,v1≠v2\nexists v_1, v_2 \in F, v_1 \neq v_2 and λ∈(0,1)\lambda \in (0, 1), s.t., v=λv1+(1−λ)v2v = \lambda v_1 + (1 - \lambda) v_2.

In other words, vv is a vertex of FF if it is not contained in a line segment of PP.

Theorem. If LP has an optimal solution, then it has an optimal solution that is a vertex of its feasible set.

Proof. Denote vv the optimal solution of the LP with maximum number of zero components. If vv is not a vertex, then ∃v1,v2≠v,v1,v2∈F\exists v_1, v_2 \neq v, v_1, v_2 \in F and λ>0\lambda > 0, such that λv1+(1−λ)v2=v\lambda v_1 + (1 - \lambda) v_2 = v.

As vv is optimal, we have cTv≥cTv1c^T v \ge c^T v_1 and cTv≥cTv2c^T v \ge c^T v_2. By λv1+(1−λ)v2=v\lambda v_1 + (1 - \lambda) v_2 = v, it concludes that cTv=cTv1=cTv2c_T v = c^T v_1 = c^T v_2.

Define I={i:v[i]>0}I = \{ i : v[i] > 0 \}. As v1≥0,v2≥0v_1 \ge 0, v_2 \ge 0 and λv1+(1−λ)v2=v\lambda v_1 + (1 - \lambda) v_2 = v so that for i≠Ii \neq I, v1[i]=v2[i]=v[i]=0v_1[i] = v_2[i] = v[i] = 0.

But AIv1[I]=AIv2[I]=bA_I v_1[I] = A_I v_2[I] = b. Let x=ϵ(v1−v2)+vx = \epsilon (v_1 - v_2) + v.

  1. xx is feasible, for small enough ϵ\epsilon.
  2. xx is optimal, since cTx=ϵcT(v1−v2)+cTv=cTvc^T x= \epsilon c^T (v_1 - v_2) + c^T v = c^T v.
  3. xi=0x_i = 0 for i∉Ii \notin I.

We can find some ϵ\epsilon (either positive or false) to make xi=0x_i = 0 for some i∈Ii \in I. Now xx contains more zeros than vv, a contradiction. □\square

Basic Solution

A solution xx of Ax=bAx = b is called a basic solution if {Ai:xi≠0}\{A_i : x_i \neq 0 \} (columns in AA that correspond to non-zero components in xx ) are linearly independent.

Basic Feasible Solution

A basic solution xx is called basic feasible solution if x≥0x \ge 0, i.e., x∈{x:Ax=b}∩{x≥0}x \in \{ x : Ax = b\} \cap \{ x \ge 0 \}.

With respect to the feasible region of LP in slack form, the vertices have have following property:

Lemma:. A point v∈F={x:Ax=b}∩{x:x≥0}v \in F = \{x : Ax = b\} \cap \{ x: x \ge 0\} is a vertex of FF if and only if it is a basic feasible solution. Here A∈Rm×n,x∈Rn,b∈RmA \in R^{m \times n}, x \in R^n, b \in R^{m} and rank(A)=mrank(A) = m (otherwise some row constraints of the Ax=bAx = b are redundant).

Proof: Denote SS the set of indices of positive components in vv and ASA_S the set of

Only if: If ASA_S does not have full column rank, then ∃u∈R∣S∣\exists u \in R^{|S|}, such that ASu=0A_S u = 0. Then for small enough ϵ∈R,ϵ>0\epsilon \in R, \epsilon > 0, both v+ϵuv + \epsilon u and v−ϵuv - \epsilon u are feasible point in FF. Now v=0.5(v+ϵu)+0.5(v−ϵu)v = 0.5(v + \epsilon u) + 0.5(v - \epsilon u), a contradiction.

If: As columns of ASA_S are linearly independent, the only solution of to ASxS=0A_S x_S = 0 is given by xS=0x_S = 0. Hence, vSv_S is now the unique solution to ASvS=bA_S v_S = b. If vv is not a vertex, ∃v1,v2,λ\exists v_1, v_2, \lambda, such that v=λv1+(1−λ)v2v = \lambda v_1 + (1 - \lambda) v_2. But in this case we must have v1=v2=vv_1 = v_2 = v, as (v1)S=(v2)S=vS(v_1)_S = (v_2)_S = v_S and (v1)Sˉ=(v2)Sˉ=vSˉ=0(v_1)_{\bar S} = (v_2)_{\bar S} = v_{\bar S} = 0. A contradiction.

■\blacksquare.

Corollary: The simplex algorithm moves from vertex to vertex.

Proof: The positive components in the solution correspond to the columns in the identity matrix in the tabular form of simplex, which are linearly independent.

Correctness of Simplex (TO FINISH)

Though not shown in the example, there are two issue associated with simplex algorithm.

  1. How do we find an initial solution? If there are negative component in bb, then x=0∧s=bx = 0 \wedge s = b is not a feasible solution.
  2. How do we guarantee that simplex terminates?

In the previous example, at each step we choose to increase the variable with largest coefficient. In some rare cases, this results in a loop of the algorithm.

One method for avoiding looping is called Bland's rule:

  1. If there is a positive coefficient in the objective function, choose the one with largest coefficient.
  2. If there are multiple rows with tight constraints, choose the one with largest coefficient.

Theorem. Blands' rule guarantees that the algorithm stops.

Proof. Suppose that on the contrary, the algorithm loops. Denote B1,B2,...,BkB_1, B_2, ..., B_k the set of basis in the loop. In each base, there is entering variable and one leaving variable. Every variable that leaves the base must enter another base later. We called these variable fickle variables. Denote xtx_t the fickle variable with the largest index.

  1. DD the dictionary that xtx_t leaves the base, and xex_e the variable that enters the base.
  2. D′D' the dictionary that xtx_t enters the base again.
D=IAN∣b0cN∣α⇒...⇒D′=RRAN∣RbyTyTAN+cN∣yTb+α D = \begin{aligned} I && A_N && \mid b \\ \hline 0 && c_N && \mid \alpha \\ \end{aligned} \Rightarrow ... \Rightarrow D' = \begin{aligned} R && R A_N && \mid R b \\ \hline y^T && y^T A_N + c_N && \mid y^T b + \alpha \\ \end{aligned}

We have

ce′=ce+yTAN[:,e] c_e' = c_e + y^T A_N[:, e]
  1. xex_e is the entering variable in DD, therefore ce>0c_e > 0.
  2. xtx_t is the entering variable in D′D', and e<te < t, by the definition of xtx_t, we have xe′≤0x_e' \le 0.
  3. Hence, yTAN[:,e]=ce′−ce<0y^T A_N[:, e] = c_e' - c_e < 0.
  4. ∃i,s.t.,yiAi,e<0\exists i, s.t., y_i A_{i, e} < 0. Then yi≠0y_i \neq 0, and xix_i is fickle. By definition, i<ti < t. But xix_i is not entering D′D', we know that yi<0y_i < 0.
  5. Ai,e>0A_{i, e} > 0. But since xix_i is fickle, we have bi=0b_i = 0. In this case, xix_i is chosen in preference to xtx_t. A contradiction.

Reference

[1]. Dantzig, George B. "Origins of the simplex method." A history of scientific computing. 1990. 141-151.