TExcelTAD
Home › Linear Programming & Duality for Algorithms › Bipartite, Network and Interval Matrices

Bipartite, Network and Interval Matrices

Checking every square submatrix is no way to prove that a whole family of matrices is totally unimodular. This lesson gives the tool that does it, Ghouila-Houri's characterization by signed row sums, and uses it on the three families that produce most integral LPs in algorithm design: incidence matrices of bipartite graphs (matchings, covers, transportation), incidence matrices of directed graphs and the more general network matrices (flows, shortest paths), and interval matrices (scheduling on a line). Each family comes with the combinatorial problem whose LP it solves exactly.

Ghouila-Houri's characterization

Theorem (Ghouila-Houri, 1962). A matrix AA with entries in {0,±1}\{0, \pm 1\} is totally unimodular if and only if every subset RR of its rows can be split into two parts R+R^+ and R−R^- such that

∑i∈R+aij−∑i∈R−aij∈{−1,0,1}for every column j.\sum_{i \in R^+} a_{ij} - \sum_{i \in R^-} a_{ij} \in \{ -1, 0, 1 \} \quad \text{for every column } j .

Since AA is TU iff ATA^T is, the same holds with columns in place of rows. The "only if" direction is the harder one; for proving that families are TU, only the "if" direction is needed, and in each case below the split is easy to describe. (A proof is in Schrijver's Theory of Linear and Integer Programming, 1986, §19.)

Bipartite incidence matrices

Let GG be bipartite with sides LL and WW, and let AA be its vertex-edge incidence matrix (rows = vertices, columns = edges, each column has two 1s, one in an LL row and one in a WW row). For a subset RR of rows, put the LL-rows in R+R^+ and the WW-rows in R−R^-. Column e=uwe = uw then sums to [u∈R]−[w∈R]∈{−1,0,1}[u \in R] - [w \in R] \in \{ -1, 0, 1 \}. So AA is TU.

What it solves exactly, with integral data:

  • bipartite matching and maximum-weight matching, max⁡{wTx:Ax≤1, x≥0}\max \{ w^T x : Ax \le \mathbf{1},\ x \ge 0 \}, and perfect matching / the assignment problem with Ax=1Ax = \mathbf{1};
  • vertex cover in bipartite graphs (the dual), which gives König's theorem;
  • transportation problems: ∑jxij≤si\sum_j x_{ij} \le s_i (supplies), ∑ixij≥dj\sum_i x_{ij} \ge d_j (demands); with integer supplies and demands, an optimal integral shipment exists.

The same matrix for an odd cycle fails Ghouila-Houri on the full row set: going around the cycle, adjacent vertices must get opposite signs (their shared column has two 1s), which an odd cycle cannot do. The program tries every split for every row subset of two small incidence matrices and reports a subset with no valid split.

python · try it yourself
from itertools import combinations, product

def ghouila_houri(A):
    """Return a row subset with no valid +/- split, or None if every subset has one (A is then TU)."""
    m, n = len(A), len(A[0])
    for k in range(1, m + 1):
        for R in combinations(range(m), k):
            if not any(all(sum(s * A[i][j] for s, i in zip(signs, R)) in (-1, 0, 1) for j in range(n))
                       for signs in product((1, -1), repeat=k)):
                return R
    return None

def incidence(nv, edges):
    return [[1 if v in e else 0 for e in edges] for v in range(nv)]

K23 = incidence(5, [(0, 2), (0, 3), (0, 4), (1, 2), (1, 3), (1, 4)])   # complete bipartite K_{2,3}
C5 = incidence(5, [(0, 1), (1, 2), (2, 3), (3, 4), (4, 0)])
for name, A in [("K_{2,3}", K23), ("5-cycle", C5)]:
    bad = ghouila_houri(A)
    print(name, "-> every row subset splits: TU" if bad is None else f"-> rows {bad} cannot be split: not TU")
K_{2,3} -> every row subset splits: TU
5-cycle -> rows (0, 1, 2, 3, 4) cannot be split: not TU

Directed graphs and network matrices

The node-arc incidence matrix NN of a directed graph has a +1+1 (tail) and a −1-1 (head) in each column. Put all chosen rows in R+R^+: each column sums to 00 (both ends chosen), ±1\pm 1 (one end chosen) or 00 (none). So NN is TU, for every directed graph. Adding identity rows (capacities) keeps it TU. That is why

  • maximum flow and minimum-cost flow with integer capacities and demands have integral optimal flows (Max-Flow Min-Cut as LP Duality),
  • shortest paths, whose LP has the matrix NN, have integral distance labels for integer lengths (the dual, NTN^T).

Network matrices generalize this. Fix a directed spanning tree TT on a vertex set. For an arc (u,v)(u, v) (not necessarily in TT), the column has, for each tree arc, +1+1 if the tree arc lies on the uu-vv path in TT traversed forward, −1-1 if traversed backward, and 00 if off the path. Tutte (1965) showed that network matrices are TU, and by Seymour's theorem they are, with two exceptional matrices, the building blocks of all TU matrices.

Interval matrices

A 0/1 matrix has the consecutive-ones property for columns if the 1s in every column are consecutive rows. With rows = time points 1,…,T1, \ldots, T and columns = intervals [sj,tj][s_j, t_j], this is an interval matrix. For a subset RR of rows, sort it by position and give the signs +,−,+,−,…+, -, +, -, \ldots alternately. The chosen rows inside one interval are consecutive in that order, so their alternating sum is 00 or ±1\pm 1. So interval matrices are TU.

An interval matrix is also a network matrix in disguise: subtracting each row from the next (row tt minus row t−1t - 1) turns each column's block of ones into a +1+1 and a −1-1, a node-arc incidence column on a path. Row operations of this kind are unimodular, which gives a second proof.

What interval matrices solve: maximum-weight sets of non-overlapping intervals, max⁡{wTx:Ax≤1, x≥0}\max \{ w^T x : Ax \le \mathbf{1},\ x \ge 0 \} (each time point is used by at most one chosen interval); with Ax≤k1Ax \le k\mathbf{1}, scheduling on kk identical machines; and covering problems such as staffing a timeline with shifts. The program solves the weighted interval problem as an LP and as a dynamic program and finds an integral LP optimum.

python · try it yourself
from scipy.optimize import linprog

intervals = [(1, 3, 5), (2, 5, 6), (4, 6, 5), (6, 8, 4), (7, 9, 3), (1, 9, 9), (3, 4, 2)]   # (start, end, weight)
T = 9
A = [[1 if s <= t <= e else 0 for s, e, _ in intervals] for t in range(1, T + 1)]
res = linprog([-w for _, _, w in intervals], A_ub=A, b_ub=[1] * T, bounds=[(0, None)] * len(intervals), method="highs-ds")
print("LP solution:", [round(float(v), 6) + 0.0 for v in res.x], " value", round(float(-res.fun), 6))

# dynamic program over intervals sorted by end time (weighted interval scheduling)
order = sorted(range(len(intervals)), key=lambda j: intervals[j][1])
best = [0] * (len(order) + 1)
for k, j in enumerate(order, 1):
    s, e, w = intervals[j]
    p = max((q for q in range(k) if q == 0 or intervals[order[q - 1]][1] < s), default=0)
    best[k] = max(best[k - 1], best[p] + w)
print("dynamic program optimum:", best[-1])
LP solution: [1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 0.0]  value 13.0
dynamic program optimum: 13

The LP returns a 0/1 vector, the same value as the dynamic program for weighted interval scheduling. For this problem the DP is faster; the TU view matters when the interval constraints are one part of a bigger LP, or when the dual is wanted (here: weights on time points that cover every interval's weight, a fractional "piercing" bound).

In C++

A Ghouila-Houri check specialised to interval matrices: for every subset of rows (bit mask), apply the alternating signs in row order and confirm that every column sums to −1-1, 00 or 11. This verifies, for one matrix, the argument of the proof above.

cpp · try it yourself
#include <cstdio>
#include <vector>

int main() {
    // rows = time points 1..6, columns = intervals [1,3], [2,5], [4,6], [3,3], [1,6]
    int starts[] = {1, 2, 4, 3, 1}, ends[] = {3, 5, 6, 3, 6};
    int T = 6, n = 5;
    std::vector<std::vector<int>> A(T, std::vector<int>(n));
    for (int t = 0; t < T; t++)
        for (int j = 0; j < n; j++) A[t][j] = (starts[j] <= t + 1 && t + 1 <= ends[j]);
    int checked = 0, failures = 0;
    for (int mask = 1; mask < (1 << T); mask++) {
        std::vector<int> sum(n, 0);
        int sign = 1;
        for (int t = 0; t < T; t++)
            if (mask >> t & 1) {
                for (int j = 0; j < n; j++) sum[j] += sign * A[t][j];
                sign = -sign;                                 // alternate +, -, +, ... in row order
            }
        bool ok = true;
        for (int j = 0; j < n; j++) ok = ok && sum[j] >= -1 && sum[j] <= 1;
        checked++;
        failures += !ok;
    }
    std::printf("row subsets checked: %d, alternating split failed: %d\n", checked, failures);
    std::printf("so every subset has a valid split and the interval matrix is TU\n");
}
row subsets checked: 63, alternating split failed: 0
so every subset has a valid split and the interval matrix is TU

A summary

Family Typical LP Combinatorial min-max theorem from duality
bipartite incidence matching / assignment, transportation König (1931), Egerváry (1931)
directed incidence (+ identity) max flow, min-cost flow, shortest paths max-flow min-cut (Ford and Fulkerson, 1956)
network matrices flows with side structure generalizations of the above
interval (consecutive ones) interval packing and covering, shift scheduling max non-overlapping intervals = min points piercing all intervals (unweighted)

Total unimodularity is sufficient for integrality but not necessary for a particular right-hand side. The matching polytope of a general graph and the spanning tree polytope are integral without being given by TU matrices; their integrality needs other proofs (Edmonds) and, for the analogous dual statements, the theory of total dual integrality (Edmonds and Giles, 1977).

Test yourself

In Ghouila-Houri's test for a bipartite incidence matrix, how are the chosen rows split?

  1. Randomly
  2. Rows of one side get ++, rows of the other side get −-
  3. All rows get ++
  4. Alternately in index order

Why is the node-arc incidence matrix of any directed graph TU?

  1. Because it is square
  2. Putting all chosen rows in R+R^+ gives column sums in {−1,0,1}\{-1, 0, 1\}, since each column has one +1+1 and one −1-1
  3. Because directed graphs have no odd cycles
  4. It is not TU in general

Which problem has an interval (consecutive-ones) constraint matrix?

  1. Vertex cover on a triangle
  2. Choosing a maximum-weight set of pairwise disjoint intervals on a line
  3. The travelling salesman problem
  4. Max-cut