TExcelTAD
Home › Linear Programming & Duality for Algorithms › Standard Form, Slack Form and Combinatorial LPs

Standard Form, Slack Form and Combinatorial LPs

Algorithms and theorems about linear programs are stated for one fixed shape, so the first skill is to bring any LP into that shape without changing its optimum. This lesson fixes the two forms used in the rest of the course, gives the conversion rules as a small program, and then looks at what LPs coming from graphs have in common: sparse matrices with entries 00 and ±1\pm 1, which is the reason so many of them have integral optima. The conversions were introduced briefly in Formulating Linear Programs; the continuous view of the same forms is in Linear Programs.

The two forms

An LP in standard form (inequality form) is

max⁡  cTxsubject toAx≤b,x≥0,\max \; c^T x \quad \text{subject to} \quad Ax \le b, \quad x \ge 0,

with A∈Rm×nA \in \mathbb{R}^{m \times n}, b∈Rmb \in \mathbb{R}^m, c∈Rnc \in \mathbb{R}^n. It is the natural form for duality: the dual is then min⁡{bTy:ATy≥c, y≥0}\min \{ b^T y : A^T y \ge c,\ y \ge 0 \}.

An LP in equational form (also called slack form, or "standard form" in some texts, which is a common source of confusion) is

max⁡  cTxsubject toAx=b,x≥0.\max \; c^T x \quad \text{subject to} \quad Ax = b, \quad x \ge 0 .

It is the natural form for the simplex method and for the algebra of vertices, because a vertex is then described by choosing which variables are zero. Going from inequality form to equational form adds one slack variable per row: aiTx≤bia_i^T x \le b_i becomes aiTx+si=bia_i^T x + s_i = b_i with si≥0s_i \ge 0. The new matrix is [A  I][A \; I], which has full row rank mm automatically, an assumption the simplex method needs.

Conversion rules

Every LP can be rewritten in either form. The rules change the number of variables and constraints by at most a factor of two, so the input size stays polynomial.

Given Replace by
min⁡cTx\min c^T x max⁡(−c)Tx\max (-c)^T x, then negate the optimal value
aTx≥βa^T x \ge \beta −aTx≤−β-a^T x \le -\beta
aTx=βa^T x = \beta aTx≤βa^T x \le \beta and −aTx≤−β-a^T x \le -\beta
xjx_j free xj=xj+−xj−x_j = x_j^+ - x_j^- with xj+,xj−≥0x_j^+, x_j^- \ge 0
xj≤ujx_j \le u_j an ordinary row xj≤ujx_j \le u_j
xj≥ℓjx_j \ge \ell_j with ℓj≠0\ell_j \ne 0 substitute xj=ℓj+xj′x_j = \ell_j + x_j' with xj′≥0x_j' \ge 0

The program applies the rules to a small LP with every kind of feature: a minimization, an equation, a ≥\ge row and a free variable. It prints the standard-form data and then solves the original and the converted LP with SciPy to show that the optima agree.

python · try it yourself
from scipy.optimize import linprog

# minimize 2 x1 - 3 x2 + x3
# s.t.  x1 +   x2 +   x3  = 4
#       x1 -   x2        >= -1
#              x2 - 2 x3 <= 5
#       x1 <= 3,  x1, x2 >= 0,  x3 free
lp = {"sense": "min", "c": [2, -3, 1],
      "rows": [([1, 1, 1], "=", 4), ([1, -1, 0], ">=", -1), ([0, 1, -2], "<=", 5), ([1, 0, 0], "<=", 3)],
      "free": [False, False, True]}

def to_standard(lp):
    # split every free variable into a plus and a minus part
    cols = []
    for j, free in enumerate(lp["free"]):
        cols.append((j, 1))
        if free:
            cols.append((j, -1))
    sign = -1 if lp["sense"] == "min" else 1
    c = [sign * lp["c"][j] * s for j, s in cols]
    A, b = [], []
    for a, op, rhs in lp["rows"]:
        row = [a[j] * s for j, s in cols]
        if op in ("<=", "="):
            A.append(row); b.append(rhs)
        if op in (">=", "="):
            A.append([-v for v in row]); b.append(-rhs)
    return c, A, b, sign

c, A, b, sign = to_standard(lp)
print("maximize", c)
for row, rhs in zip(A, b):
    print("  ", row, "<=", rhs)

bounds = [(None, None) if f else (0, None) for f in lp["free"]]
eq = [(a, r) for a, op, r in lp["rows"] if op == "="]
ub = [(a if op == "<=" else [-v for v in a], r if op == "<=" else -r) for a, op, r in lp["rows"] if op != "="]
orig = linprog(lp["c"], A_ub=[a for a, _ in ub], b_ub=[r for _, r in ub],
               A_eq=[a for a, _ in eq], b_eq=[r for _, r in eq], bounds=bounds, method="highs")
std = linprog([-v for v in c], A_ub=A, b_ub=b, bounds=[(0, None)] * len(c), method="highs")
print("original optimum:", round(float(orig.fun), 6), "at", [round(float(v), 6) for v in orig.x])
print("standard form optimum:", round(float(sign * -std.fun), 6), "(after undoing the sign flip)")
maximize [-2, 3, -1, 1]
   [1, 1, 1, -1] <= 4
   [-1, -1, -1, 1] <= -4
   [-1, 1, 0, 0] <= 1
   [0, 1, -2, 2] <= 5
   [1, 0, 0, 0] <= 3
original optimum: -6.0 at [2.0, 3.0, -1.0]
standard form optimum: -6.0 (after undoing the sign flip)

The free variable x3x_3 became two columns, the equation became two rows, and the ≥\ge row changed sign. The converted LP has 4 variables and 5 rows, and its optimum is the same.

Slack variables measure tightness

In equational form each slack variable has a meaning: si=bi−aiTxs_i = b_i - a_i^T x is how much room constraint ii has left. A constraint with si=0s_i = 0 is tight (or active) at xx. Tight constraints are what define vertices in the next lesson, and in the duality section they are exactly the constraints whose dual variables may be non-zero. For the workshop LP of Part I (max⁡3x+2y\max 3x + 2y subject to 2x+y≤102x + y \le 10, x+3y≤15x + 3y \le 15, x≤4x \le 4) the program prints the slacks at three points.

python · try it yourself
A = [(2, 1), (1, 3), (1, 0)]
b = [10, 15, 4]
names = ["cutting", "finishing", "varnish"]

for point in [(0, 0), (3, 4), (4, 2)]:
    slack = [bi - (a[0] * point[0] + a[1] * point[1]) for a, bi in zip(A, b)]
    tight = [nm for nm, s in zip(names, slack) if s == 0]
    tight += [v for v, coord in zip("xy", point) if coord == 0]       # x >= 0, y >= 0 can be tight too
    print(f"point {point}: slacks {slack}, tight: {', '.join(tight)}")
point (0, 0): slacks [10, 15, 4], tight: x, y
point (3, 4): slacks [0, 0, 1], tight: cutting, finishing
point (4, 2): slacks [0, 5, 0], tight: cutting, varnish

Each of the three points has exactly two tight constraints among the five (three rows and two sign constraints), and two tight constraints with linearly independent normals pin down a point of the plane: these points are vertices. The optimum (3,4)(3, 4) uses all the cutting and finishing time and leaves one unit of varnish capacity unused.

What combinatorial LPs look like

LPs that come from graphs and set systems share a recognisable structure. Variables are indexed by edges, vertices or sets; constraints are indexed by the other kind of object; the matrix is an incidence matrix with entries in {0,1}\{0, 1\} or {0,±1}\{0, \pm 1\}.

Problem Variables Constraints Matrix
bipartite matching xe≥0x_e \ge 0 per edge ∑e∋vxe≤1\sum_{e \ni v} x_e \le 1 per vertex vertex-edge incidence, two 1s per column
vertex cover xv≥0x_v \ge 0 per vertex xu+xv≥1x_u + x_v \ge 1 per edge its transpose
maximum ss-tt flow fe≥0f_e \ge 0 per arc capacity fe≤uef_e \le u_e; conservation per vertex node-arc incidence, a +1+1 and a −1-1 per column
set cover xS≥0x_S \ge 0 per set ∑S∋exS≥1\sum_{S \ni e} x_S \ge 1 per element element-set incidence
shortest path dvd_v per vertex dv−du≤wuvd_v - d_u \le w_{uv} per arc transpose of node-arc incidence

The program builds the vertex-edge incidence matrix of a 4-cycle and the node-arc incidence matrix of a small directed graph, which are the two matrices this course meets most often.

python · try it yourself
edges = [(0, 1), (1, 2), (2, 3), (3, 0)]            # the 4-cycle, undirected
inc = [[1 if v in e else 0 for e in edges] for v in range(4)]
print("vertex-edge incidence of C4 (rows = vertices, columns = edges)")
for v, row in enumerate(inc):
    print(f"  v{v}", row)

arcs = [("s", "a"), ("s", "b"), ("a", "b"), ("a", "t"), ("b", "t")]
nodes = ["s", "a", "b", "t"]
print("node-arc incidence (+1 = arc leaves, -1 = arc enters)")
for u in nodes:
    print(f"  {u} ", [1 if a[0] == u else -1 if a[1] == u else 0 for a in arcs])
print("column sums of the node-arc matrix:", [sum((1 if a[0] == u else -1 if a[1] == u else 0) for u in nodes) for a in arcs])
vertex-edge incidence of C4 (rows = vertices, columns = edges)
  v0 [1, 0, 0, 1]
  v1 [1, 1, 0, 0]
  v2 [0, 1, 1, 0]
  v3 [0, 0, 1, 1]
node-arc incidence (+1 = arc leaves, -1 = arc enters)
  s  [1, 1, 0, 0, 0]
  a  [-1, 0, 1, 1, 0]
  b  [0, -1, -1, 0, 1]
  t  [0, 0, 0, -1, -1]
column sums of the node-arc matrix: [0, 0, 0, 0, 0]

Every column of the node-arc matrix has exactly one +1+1 and one −1-1 (so it sums to zero): each arc leaves one node and enters another. That structure makes the matrix totally unimodular, so every vertex of a flow polytope with integer capacities is integral. The Integrality section proves this; until then, keep in mind that the structure of the matrix, not luck, is why flows and bipartite matchings come out integral.

Note: The number of constraints matters for algorithms but not for the forms. The subtour-elimination LP for the travelling salesman problem has a constraint for every subset of vertices, exponentially many. It cannot be written down, yet it can be solved in polynomial time with the ellipsoid method and a separation oracle (Separation Oracles).

Test yourself

How many variables does the standard form of an LP with 5 variables, 2 of them free, have?

  1. 5
  2. 7
  3. 10
  4. 3

Why does equational form [A  I](xs)=b[A \; I] \binom{x}{s} = b obtained from slack variables always have full row rank?

  1. Because AA is square
  2. Because it contains the m×mm \times m identity matrix as a submatrix
  3. Because b≥0b \ge 0
  4. It does not in general

A slack variable sis_i is zero at a point xx. What does that mean?

  1. Constraint ii is violated
  2. Constraint ii is tight (holds with equality) at xx
  3. The LP is unbounded
  4. xi=0x_i = 0

What do the columns of a directed graph's node-arc incidence matrix have in common?

  1. They are all zero
  2. Each has one +1+1 and one −1-1, so it sums to zero
  3. Each has two +1+1 entries
  4. They are linearly independent