1. Home
  2. Optimization

Optimization · pivoting

Lemke Algorithm for the Linear Complementarity Problem: Step by Step Example

Eigenfield editorial team ·

Plaster polytope cut by an acrylic plane with a green thread tracing a path along its edges (AI-generated image)
AI-generated image

The Lemke algorithm is a pivoting method for the linear complementarity problem, usually abbreviated LCP. Given a square matrix M and a vector q, the task is to find vectors w and z with w = Mz + q, w ≥ 0, z ≥ 0, and wi·zi = 0 for every index i. The method runs on a tableau like the simplex method, but it carries one extra column and chooses the entering variable by a different rule.

This page states the problem, lists the algorithm one pivot at a time, and then carries out a complete step by step example on a two-variable problem so that every tableau can be checked with pencil and paper. The last sections cover the situations in which the method ends without a solution.

The linear complementarity problem

Complementarity means that for each index i at least one of wi and zi is zero. A solution therefore has at most n positive entries among its 2n variables, and the nonzero ones are never a pair. If q ≥ 0 the problem is solved at once by z = 0 and w = q. Everything interesting happens when some entry of q is negative.

The format looks narrow, yet several common problems reduce to it. A convex quadratic program, minimize ½xᵀQx + cᵀx subject to Ax ≥ b and x ≥ 0, has Karush-Kuhn-Tucker conditions that are exactly an LCP. Put z = (x, λ), where λ holds the multipliers of the constraints Ax ≥ b. Then M = [[Q, −Aᵀ], [A, 0]] and q = (c, −b). A linear program is the special case Q = 0. Equilibrium problems in bimatrix games and some contact problems in mechanics also reduce to this form.

The Lemke algorithm, one pivot at a time

Write the system as w − Mz − d·z0 = q. The new variable z0 is artificial, and d is a covering vector with positive entries; a vector of ones is the usual choice. The procedure has six steps.

  1. If q ≥ 0, stop with z = 0.
  2. Otherwise let z0 enter the basis. The row that leaves is the one with the most negative qi/di, which makes every basic variable non-negative after the pivot.
  3. Note which variable just left the basis. Its complement, the other member of the pair (wi or zi), enters next.
  4. Run the ratio test on the entering column: among rows with a positive entry, the smallest right-hand side divided by that entry decides the leaving variable.
  5. If z0 leaves, stop. The remaining basic variables form a solution, and every nonbasic variable is zero.
  6. If the entering column has no positive entry, stop on a ray. Otherwise return to step 3.

The rule is easier to trust once you see what it preserves. After the first pivot the basis holds z0 plus one variable from each complementary pair except a single pair, whose two members are both nonbasic. Choosing the complement of the variable that just left fills that gap, and the departing variable opens a new one. The basis stays almost complementary at every step, so the sequence traces a path along edges of a polyhedron. Without degeneracy no basis repeats, which is why the path ends.

A step by step example

Take M = [[2, 1], [1, 2]] and q = (−5, −6), with d = (1, 1). This is the optimality system of the quadratic program minimize x₁² + x₁x₂ + x₂² − 5x₁ − 6x₂ over x ≥ 0, so the answer can be cross-checked by setting the gradient to zero. The initial tableau has columns w1, w2, z1, z2, z0 and the right-hand side:

basis   w1    w2    z1    z2    z0  |  rhs
w1       1     0    -2    -1    -1  |   -5
w2       0     1    -1    -2    -1  |   -6

Both entries of q are negative, so the algorithm starts. The most negative ratio is −6, in the w2 row. Let z0 enter and w2 leave. Multiply that row by −1, then add it to the first row:

basis   w1    w2    z1    z2    z0  |  rhs
w1       1    -1    -1     1     0  |    1
z0       0    -1     1     2     1  |    6

The variable w2 just left, so its complement z2 enters. The column of z2 has positive entries 1 and 2, giving ratios 1/1 = 1 and 6/2 = 3. The minimum is 1, so w1 leaves. After pivoting on the first row, the second row becomes row₂ − 2·row₁:

basis   w1    w2    z1    z2    z0  |  rhs
z2       1    -1    -1     1     0  |    1
z0      -2     1     3     0     1  |    4

Now w1 has left, so z1 enters. Its column holds −1 and 3. Only the 3 is positive, with ratio 4/3, which makes z0 leave. Divide the second row by 3, then add the new row to the first row:

basis   w1    w2    z1    z2    z0  |  rhs
z2     1/3  -2/3     0     1   1/3  |  7/3
z1    -2/3   1/3     1     0   1/3  |  4/3

The artificial variable z0 has left the basis, so the algorithm stops after three pivots. Reading the right-hand side gives z1 = 4/3 and z2 = 7/3, and both w values are nonbasic, hence zero. Check: Mz + q = (2·4/3 + 7/3 − 5, 4/3 + 2·7/3 − 6) = (0, 0), so w = 0 and complementarity holds. Zero gradient of the quadratic program at the same point confirms the result.

When the algorithm ends without a solution

Ray termination is the signal that no positive entry exists in the entering column. The smallest case is M = [−1] and q = [−1]. The row reads w + z − z0 = −1, so z0 enters and w leaves, giving z0 = 1 + w + z. The complement z then enters, but its column holds −1 and nothing can leave. The LCP itself has no solution: w = −z − 1 is negative for every z ≥ 0.

What the ray means in general depends on M. If M is copositive-plus, a class that contains every positive semidefinite matrix, the method either finds a solution or proves that none exists. That covers the convex quadratic programs above. For other matrices a ray proves nothing, and a solution may exist that this path never reaches. If M is a P-matrix, meaning every principal minor is positive, a unique solution exists for every q and the method finds it.

Degenerate data bring a second hazard, ties in the ratio test. Ties can send the path in circles. A lexicographic tie-breaking rule prevents cycling, and implementations also compare with a tolerance instead of testing exact zeros.

Practical notes for linear complementarity problems

Writing the tableau by hand is a teaching device. A serious implementation keeps a factorization of the current basis matrix and solves for the entering column, in the way revised simplex codes do; the page on LU factorization covers that building block. For linear programs themselves the ordinary simplex method is the better tool, as the lp_solve tutorial shows with a model that can be solved and verified by hand. Terms such as basis and pivot are collected in the glossary.

The method scales poorly. Dense tableaux work for tens of variables, and for large sparse quadratic programs interior-point or active-set codes are the standard choice. Lemke’s method earns its place where M is not symmetric, so there is no objective to minimize, only a complementarity system to satisfy.

Related methods are collected in the optimization section.

Questions about the Lemke algorithm

What is the Lemke algorithm used for?

It solves linear complementarity problems: find w = Mz + q with w and z non-negative and wizi = 0. Convex quadratic programs, linear programs and bimatrix game equilibria all convert to that form.

Why is an extra variable z0 needed?

Without it the starting basis, w = q, is infeasible whenever q has a negative entry. Adding z0 times a covering vector and pivoting it in gives a feasible almost complementary basis to start from.

How does Lemke’s method differ from the simplex method?

Both pivot on a tableau, but simplex chooses the entering column to improve an objective. Lemke has no objective. It always enters the complement of the variable that just left, and it stops when the artificial variable leaves.

What does ray termination mean?

The entering column has no positive entry, so the path runs off to infinity. For a copositive-plus matrix M this proves that the LCP has no solution. For other matrices the result is inconclusive.

Can the algorithm cycle?

Yes, with degenerate data, when two rows tie in the ratio test. A lexicographic rule for breaking ties removes the risk.

Which covering vector should I pick?

A vector of ones works in most textbook cases. Any positive vector is valid, and different choices lead to different paths that may end at different solutions when several exist.

Back to top