# Ahuja-Orlin

## General Information

Algorithmic problem: Max-flow problems (standard version)

Type of algorithm: loop

## Abstract View

Auxiliary data:

1. A nonnegative integral value $d(v)$ for each node $v\in V$.
2. Each node $v\in V\setminus\{t\}$ has a current arc, which may be implemented as an iterator on the list of outgoing arcs of $v$.
3. A stack $S$ of nodes.

Invariant: After $i \ge 0$ iterations:

1. The flow $f$ is a feasible flow.
2. If all upper bounds are integral, $f$ is integral as well.
3. The values $d(\cdot)$ are a valid distance labeling with respect to $f$.
4. The current arc of a node $v\in V\setminus\{s,t\}$ is either void or one of the outgoing arcs of $v$. No admissible outgoing arc of $v$ precedes the current arc of $v$.
5. Stack $S$ contains a cycle-free flow-augmenting path with respect to $f$. This path starts with $s$ and ends at an arbitrary node of $G$. Each arc on this path is admissible and the current arc of its tail node.

Variant: One of the following actions will take place in the current iteration:

1. An arc is appended to the current path (when going forward in the depth-first search for an augmenting path).
2. At least one arc is saturated (when augmenting along the path up to saturation).
3. The distance label of some node is increased (when going backward in the depth-first search for an augmenting path).

Break condition: It is $d(s)=n$, where $n=|V|$,

## Induction basis

Abstract view:

1. We start with some feasible flow, for example, the zero flow.
2. Also, we start with some valid distance labeling with respect to the initial flow.
3. Stack $S$ is initialized so as to contain $s$ and no other node.
4. The current arc of each node $v\in V$ is reset to be the very first outgoing arc of $v$.

Implementation of step 2 in case $f$ is initialized as the zero flow: A BFS is run on the transpose of $G$ with start node $t$; the resulting distances are the $d$-labels.

Proof of the implementation: Clearly, it is $d(t)=0$, so it remains to show $d(v)\leq d(w)+1$ for each arc $a\in A$. If $f$ is the zero flow, the arcs of the residual network $G_f$ are exactly the arcs of $G$. So, the claim follows immediately from the valid distance property.

## Induction step

Abstract view:

1. Let $v$ be the top element of $S$, that is, the endnode of the corresponding path.
2. If $v=t$:
1. Augment the current flow along the path corresponding to $S$ up to saturation.
2. Remove all nodes but $s$ from $S$.
3. Otherwise:
1. While the current arc of $v$ is not void and not admissible or points to $s$: Move the current arc one step forward.
2. If the current arc of $v$ is now void:
1. Set $d(v):=\tilde{d}+1$, where $\tilde{d}$ denotes the minimum value $d(w)$ over all outgoing arcs $(v,w)$ of $v$ in the residual network.
2. Reset the current arc of $v$ to the beginning of the list of outgoing arcs of $v$.
3. Remove $v$ from $S$.
3. Otherwise, that is, if the current arc is some arc $(v,w)$: Push $w$ on $S$.

Proof: The variant, points 1, 2, and 5 of the invariant, and the first sentence of point 4 of the invariant are obvious. For the second sentence of point 4, note that no admissible arc of $v$ is skipped when the current arc is moved forward, and the current arc is reset whenever outgoing arcs may become admissible due to an increase of $d(v)$. Finally, point 3 of the invariant follows from the conservative increase of $d(v)$ in step 3.2.

## Correctness

First we show that the flow is maximum when the break condition applies. Due to the max-flow min-cut theorem, it suffices to show that, in this moment, there is no more flow-augmenting $(s,t)$-path. However, such a path would have at most $n-1$ arcs, and for each arc $(v,w)$ on this path, it is $d(v)\leq d(w)+1$. This implies $d(s)-d(t)=d(s)\leq n-1$, which contradicts the break condition.

It remains to show that the algorithm indeed terminates. This is proved by the following complexity considerations.

## Complexity

Statement: The asymptotic complexity of the algorithm is in $\mathcal{O}(n^2m)$, where $n=|V|$ and $m=|A|$.

Proof: First we show that no distance label $d(v)$ may become higher than $n$ (in particular, the total number of executions of step 3.2 over all iterations is in $\mathcal{O}(n^2)$).

To see that, recall that $d(s)\lt n$ as long as the break condition is not fulfilled. Whenever the distance label $d(v)$ of a node $v\in V$ is increased, $v$ is the endnode of the current path, which consists solely of admissible arcs. Due to the definition of admissible arcs, it is $d(v)\leq d(s)$ immediately before the current iteration (equality only if $v=s$). Let $(v,w)$ be an arc such that $\tilde{d}=d(w)$, in particular, it is $w\neq s$. For the same reason, it is $d(w)\lt d(s)$, which implies $d(v)\leq d(s)$ immediately after the current iteration.

Now we know $d(u)\leq n$ for all nodes $u\in V$. Next we consider an arbitrary but fixed arc $(v,w)\in A$. Suppose $(v,w)$ has ben saturated at least twice during the algorithm. In both iterations, $(v,w)$ is admissible, which means $d(v)\gt d(w)$. However, in the meantime, some flow must have been sent back from $w$ to $v$, which implies $d(w)\gt d(v)$ in that intermediate iteration. As distance labels are non-decreasing, $d(v)$ must have been increased between any two iterations in which $(v,w)$ is saturated. In summary, each arc is saturated only $\mathcal{O}(n)$ times.

In each execution of step 2.1 of the induction step, at least one arc is saturated, so the total number of executions of step 2.1+2.2 is in $\mathcal{O}(nm)$. The path contains at most $n-1$ arcs, so the total asymptotic complexity for all executions of step 2.1+2 is in $\mathcal{O}(n^2m)$.

Finally, the sequence of outgoing arcs is passed once for each node in step 3.1 between two increases of $d(v)$, so the total asymptotic complexity of all executions of step 3.1 over all iterations is in $\mathcal{O}(n\cdot m)$.

## Remark

This algorithm may be seen as a "lazy" variant on Edmonds-Karp. In fact, the most expensive step there is the computation of a shortest flow-augmenting $(s,t)$-path. This task amounts to computing the true distance from every node to $t$. A valid distance labeling may be seen as "lazily evaluated" true distances.