Iterative Compression
Branching needs a small obstruction to branch on. Some problems do not offer one: for odd cycle transversal (delete vertices to make a graph bipartite) the obstructions are odd cycles of any length, and no lemma like the one for feedback vertex set bounds the choices. Iterative compression, introduced by Reed, Smith and Vetta (2004) for exactly this problem, takes a different route: it is easier to improve a solution that is one vertex too large than to find one from nothing, because the too-large solution reveals the structure of the graph.
The scheme
Call a graph problem hereditary if a solution for restricted to an induced subgraph is a solution for that subgraph. Vertex cover, feedback vertex set and odd cycle transversal are all hereditary: deleting vertices never creates new edges or cycles.
COMPRESSION for a problem: given , and a solution with , find a solution of size at most or report that none exists.
Order the vertices and let .
ITERATIVE-COMPRESSION(G, k)
1 X = empty set // a solution for G_0
2 for i = 1 to n
3 Z = X + v_i // a solution for G_i of size <= k + 1
4 if |Z| <= k: X = Z; continue
5 X = COMPRESS(G_i, k, Z)
6 if X = NONE: return NO // G_i, hence G, has no solution of size k
7 return XLine 3 works for vertex deletion problems: adding to a solution of gives a solution of . Line 6 uses heredity: a solution of size for would restrict to one for . So the whole problem costs calls to COMPRESS, and it suffices to make compression FPT.
Guessing the overlap
COMPRESS starts by guessing how the new solution meets the old one . For each of the subsets , look for a solution with . The vertices of are now forbidden: they must stay out of . What remains is a disjoint version of the problem, in which the forbidden part is small and the rest of the graph is simple (because was a solution).
For vertex cover the disjoint version is trivial, which makes it a clean first example. is a cover, so is independent. Fix and let .
- If contains an edge, no cover avoids both endpoints: reject this guess.
- Otherwise every edge inside has an endpoint in , and every edge between and must be covered by its endpoint outside . So the best cover with is exactly , where lies outside .
So compression for vertex cover takes time, and the whole algorithm . That is worse than branching, but the scheme is what matters. The program traces it on a small graph.
from itertools import combinations
def compress(adj, verts, k, Z):
best, guesses = None, 0
for r in range(len(Z) + 1):
for Y in combinations(sorted(Z), r):
guesses += 1
W = set(Z) - set(Y)
if any(b in adj[a] for a in W for b in W):
continue # an edge inside W: impossible
X = set(Y) | {b for a in W for b in adj[a] if b in verts}
if len(X) <= k and (best is None or len(X) < len(best)):
best = X
return best, guesses
def iterative_compression(adj, order, k, trace=False):
X, verts, total = set(), set(), 0
for v in order:
verts.add(v)
Z = X | {v}
if len(Z) <= k:
X = Z
else:
X, g = compress(adj, verts, k, Z)
total += g
if X is None:
return None, total
if trace:
print(f"add {v}: solution {sorted(X)}")
return X, total
edges = [(0, 1), (1, 2), (2, 3), (3, 0), (1, 4), (4, 5), (5, 6), (6, 4), (3, 7)]
adj = {v: set() for v in range(8)}
for a, b in edges:
adj[a].add(b); adj[b].add(a)
X, g = iterative_compression(adj, range(8), 4, trace=True)
print("k = 4:", sorted(X), "after", g, "guesses")
X, g = iterative_compression(adj, range(8), 3)
print("k = 3:", X, "after", g, "guesses")add 0: solution [0]
add 1: solution [0, 1]
add 2: solution [0, 1, 2]
add 3: solution [0, 1, 2, 3]
add 4: solution [1, 3]
add 5: solution [1, 3, 5]
add 6: solution [1, 3, 5, 6]
add 7: solution [1, 3, 4, 5]
k = 4: [1, 3, 4, 5] after 64 guesses
k = 3: None after 48 guesses
The trace shows the invariant: after step the set is a cover of with at most vertices. With the compression of some fails, which proves that itself has no cover of size 3 (the 4-cycle and the triangle are disjoint and need vertices).
Checking against brute force
On random graphs the algorithm must agree with exhaustive search. The program also counts the guesses examined over all compression steps, which the analysis bounds by .
import random
from itertools import combinations
def compress(adj, verts, k, Z):
guesses = 0
for r in range(len(Z) + 1):
for Y in combinations(sorted(Z), r):
guesses += 1
W = set(Z) - set(Y)
if any(b in adj[a] for a in W for b in W):
continue
X = set(Y) | {b for a in W for b in adj[a] if b in verts}
if len(X) <= k:
return X, guesses
return None, guesses
def ic(adj, n, k):
X, verts, total = set(), set(), 0
for v in range(n):
verts.add(v)
X = X | {v}
if len(X) > k:
X, g = compress(adj, verts, k, X)
total += g
if X is None:
return None, total
return X, total
def opt(adj, n):
E = [(a, b) for a in adj for b in adj[a] if a < b]
for s in range(n + 1):
for S in combinations(range(n), s):
if all(a in S or b in S for a, b in E):
return s
print(" n OPT IC(k=OPT) IC(k=OPT-1) guesses bound n*2^(k+1)")
for seed in range(5):
n = 14
rng = random.Random(seed)
adj = {v: set() for v in range(n)}
for a, b in combinations(range(n), 2):
if rng.random() < 0.2:
adj[a].add(b); adj[b].add(a)
o = opt(adj, n)
X, g = ic(adj, n, o)
Xn, _ = ic(adj, n, o - 1)
print(f"{n} {o:4} {len(X):10} {str(Xn):>12} {g:8} {n * 2 ** (o + 1):16}") n OPT IC(k=OPT) IC(k=OPT-1) guesses bound n*2^(k+1)
14 4 4 None 28 448
14 6 6 None 96 1792
14 5 5 None 41 896
14 6 6 None 208 1792
14 7 7 None 80 3584
In C++
Iterative compression for vertex cover with vertex sets as 64-bit masks. A guess is a submask of , enumerated with the standard sub = (sub - 1) & Z loop.
#include <bit>
#include <cstdint>
#include <cstdio>
#include <vector>
int main() {
const int n = 24;
std::vector<uint64_t> adj(n, 0);
unsigned s = 3;
for (int a = 0; a < n; a++)
for (int b = a + 1; b < n; b++) {
s = s * 1103515245u + 12345u;
if ((s >> 16) % 100 < 12) { adj[a] |= 1ULL << b; adj[b] |= 1ULL << a; }
}
for (int k = 8;; k++) {
uint64_t X = 0, verts = 0;
long guesses = 0;
bool ok = true;
for (int v = 0; v < n && ok; v++) {
verts |= 1ULL << v;
uint64_t Z = X | (1ULL << v);
if (std::popcount(Z) <= k) { X = Z; continue; }
ok = false;
for (uint64_t Y = Z;; Y = (Y - 1) & Z) { // all subsets of Z
guesses++;
uint64_t W = Z & ~Y, NW = 0;
bool indep = true;
for (uint64_t w = W; w; w &= w - 1) {
int a = std::countr_zero(w);
if (adj[a] & W) indep = false;
NW |= adj[a] & verts;
}
uint64_t cand = Y | NW;
if (indep && std::popcount(cand) <= k) { X = cand; ok = true; break; }
if (Y == 0) break;
}
}
std::printf("k = %2d: %s after %ld guesses\n", k, ok ? "cover found" : "no cover ", guesses);
if (ok) {
std::printf("cover:");
for (int v = 0; v < n; v++) if (X >> v & 1) std::printf(" %d", v);
std::printf("\n");
break;
}
}
}k = 8: no cover after 941 guesses
k = 9: no cover after 2479 guesses
k = 10: cover found after 5250 guesses
cover: 0 1 2 7 9 10 12 14 16 17
Odd cycle transversal and feedback vertex set
The scheme pays off where the disjoint problem is not trivial but still polynomial or FPT.
Odd cycle transversal (sketch). Given an OCT of size , is bipartite. Guess and, for the kept vertices , guess which side of the final bipartition each one lands on: guesses in total. Each kept vertex now forces its neighbours in toward the opposite side. Deciding which vertices of to delete so that all these forced sides are consistent turns into a minimum vertex cut between two terminal sets in an auxiliary graph, computable by max-flow (Max-Flow Min-Cut) in polynomial time. The result is an algorithm (Reed, Smith and Vetta, 2004), the first proof that odd cycle transversal is FPT.
Feedback vertex set (stated). In the disjoint version, is a forest and the solution must avoid . Branching on forest vertices with a measure that counts both and the number of components of gives for compression, hence a deterministic algorithm (Chen, Fomin, Liu, Lu and Villanger, 2008). Refinements of the same approach lowered the base below 4.
Iterative compression has also settled problems open for years, such as directed feedback vertex set (Chen, Liu, Lu, O'Sullivan and Razgon, 2008). The common shape: the old solution of size is used as a small "window" into the graph that turns a global problem into a local one, at a cost of guesses.
Test yourself
Why may iterative compression stop with NO as soon as one compression step fails?
- Because later vertices only make the problem easier
- Because the problem is hereditary: a solution of size for would restrict to one for every induced subgraph
- Because the order of the vertices is random
- Because compression is exact only on the last step
In compression for vertex cover, a guess fixes . What is the best cover for that guess?
- itself
- , provided is independent
- alone
How many guesses does the compression step for odd cycle transversal make, and why?
- : only which vertices of to keep
- : each vertex of is deleted, or kept on one of the two sides