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 and , 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
with , , . It is the natural form for duality: the dual is then .
An LP in equational form (also called slack form, or "standard form" in some texts, which is a common source of confusion) is
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: becomes with . The new matrix is , which has full row rank 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 |
|---|---|
| , then negate the optimal value | |
| and | |
| free | with |
| an ordinary row | |
| with | substitute with |
The program applies the rules to a small LP with every kind of feature: a minimization, an equation, a 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.
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 became two columns, the equation became two rows, and the 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: is how much room constraint has left. A constraint with is tight (or active) at . 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 ( subject to , , ) the program prints the slacks at three points.
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 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 or .
| Problem | Variables | Constraints | Matrix |
|---|---|---|---|
| bipartite matching | per edge | per vertex | vertex-edge incidence, two 1s per column |
| vertex cover | per vertex | per edge | its transpose |
| maximum - flow | per arc | capacity ; conservation per vertex | node-arc incidence, a and a per column |
| set cover | per set | per element | element-set incidence |
| shortest path | per vertex | 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.
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 and one (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?
- 5
- 7
- 10
- 3
Why does equational form obtained from slack variables always have full row rank?
- Because is square
- Because it contains the identity matrix as a submatrix
- Because
- It does not in general
A slack variable is zero at a point . What does that mean?
- Constraint is violated
- Constraint is tight (holds with equality) at
- The LP is unbounded
What do the columns of a directed graph's node-arc incidence matrix have in common?
- They are all zero
- Each has one and one , so it sums to zero
- Each has two entries
- They are linearly independent