Unit 11, lesson 52

Network Flows, Conservation and Cycles

How a directed graph and its incidence matrix turn conservation at each node into a linear system with net supplies, how circulations around cycles span the kernel, and what nonnegative flows and the total supply condition add.

  • Video 52
  • Network Flows

Three junctions are joined by pipes. Junction 1 feeds in 3 units of water per minute, junction 2 draws off 1 unit and junction 3 draws off 2, and water can reach junction 3 either directly or by way of junction 2. Many different splits keep every junction in balance. Which edge flows are possible, how much freedom is left, and which supply patterns can be balanced at all? This lesson writes all the balances as one linear system built from the incidence matrix, reads its kernel as flow around a cycle, and then adds the one-way restrictions that real pipes impose.

Key terms

Directed graph

Definition A directed graph consists of nodes, numbered 1,…,n1, \dots, n, and edges, numbered 1,…,m1, \dots, m. Each edge joins two different nodes and carries an arrow from one to the other, its reference direction. In a flow network, edge kk carries a real number fkf_k, its flow, measured along the arrow, and the flows form a column f\mathbf{f} in Rm\mathbb{R}^m. A positive fkf_k means material moves along the arrow, and a negative fkf_k means it moves against the arrow at the rate ∣fk∣\lvert f_k \rvert. Whether negative flows are physically possible is a separate modeling decision. The graph is connected when any two nodes are joined by a chain of edges, with the arrows ignored.

In plain words On their own, the arrows are bookkeeping, not traffic rules. They fix which sign means which way, and reversing an arrow only changes the sign of its flow.

Example Take three nodes and the edges 1→21 \to 2, 2→32 \to 3 and 1→31 \to 3, numbered in that order, with flows f1,f2,f3f_1, f_2, f_3. Tuples such as (2,1,1)(2, 1, 1) stand for column vectors on this page. The flow f=(2,1,1)\mathbf{f} = (2, 1, 1) moves 2 units per minute from node 1 to node 2, 1 unit from node 2 to node 3 and 1 unit from node 1 to node 3. A value f1=−2f_1 = -2 would mean 2 units per minute moving from node 2 to node 1, the same movement as a flow of 22 on a reversed arrow 2→12 \to 1. This triangle network is connected.

Incidence matrix

Definition The incidence matrix of a directed graph with nn nodes and mm edges is the n×mn \times m matrix BB with entries

bik={1,edge k leaves node i,−1,edge k enters node i,0,otherwise.b_{ik} = \begin{cases} 1, & \text{edge } k \text{ leaves node } i, \\ -1, & \text{edge } k \text{ enters node } i, \\ 0, & \text{otherwise.} \end{cases}

Rows belong to nodes and columns to edges. Each column has exactly one entry 11 and one entry −1-1, so every column sums to zero. As a matrix, BB maps Rm\mathbb{R}^m to Rn\mathbb{R}^n, and entry ii of BfB\mathbf{f} is the total flow leaving node ii minus the total flow entering it, with flows counted with their signs. If the graph is connected, then rank⁡B=n−1\operatorname{rank} B = n - 1. Indeed, for an edge kk from ii to jj, entry kk of B⊤yB^{\top}\mathbf{y} is yi−yjy_i - y_j. So B⊤y=0B^{\top}\mathbf{y} = \mathbf{0} forces equal values at the two ends of every edge, hence at all nodes of a connected graph. The null space of B⊤B^{\top} is therefore the line spanned by the all-ones vector 1=(1,…,1)\mathbf{1} = (1, \dots, 1) in Rn\mathbb{R}^n, and rank⁡B=n−dim⁡Null⁡B⊤=n−1\operatorname{rank} B = n - \dim \operatorname{Null} B^{\top} = n - 1.

In plain words Each column is one edge, recorded as plus one where it starts and minus one where it ends. One unit of flow on that edge moves one unit from its start to its end and creates nothing.

Example For the triangle network,

B=[101−1100−1−1].B = \begin{bmatrix} 1 & 0 & 1 \\ -1 & 1 & 0 \\ 0 & -1 & -1 \end{bmatrix}.

The column of edge 1→21 \to 2 is (1,−1,0)(1, -1, 0), the column of 2→32 \to 3 is (0,1,−1)(0, 1, -1) and the column of 1→31 \to 3 is (1,0,−1)(1, 0, -1). The three rows add to the zero row, so the rank is at most 22. The first two columns are independent, because the combination α(1,−1,0)+β(0,1,−1)\alpha(1, -1, 0) + \beta(0, 1, -1) has first entry α\alpha and last entry −β-\beta, so it vanishes only when α=β=0\alpha = \beta = 0. Hence rank⁡B=2=n−1\operatorname{rank} B = 2 = n - 1.

Conservation at a node

Definition The net supply sis_i of node ii is the rate at which material enters the network from outside at that node. A positive sis_i is a source, a negative sis_i is consumption, and si=0s_i = 0 means the node only passes material on. Assume a steady state, with no storage at the nodes and no loss along the edges. Conservation at node ii then says that the sum of the flows on edges leaving node ii, minus the sum of the flows on edges entering it, equals sis_i. With the supply vector s=(s1,…,sn)\mathbf{s} = (s_1, \dots, s_n), the conservation equations at all nodes form the single system

Bf=s,B\mathbf{f} = \mathbf{s},

with nn equations in mm unknowns. Its solutions are the flows compatible with the supplies. If f0\mathbf{f}_0 is one of them, then they are exactly the vectors f0+z\mathbf{f}_0 + \mathbf{z} with z\mathbf{z} in Null⁡B\operatorname{Null} B.

In plain words What a node takes in from outside must leave through its edges, and what it consumes must arrive through its edges. Supplies belong to nodes and flows belong to edges, so a negative supply is not a negative flow.

Example With supplies s=(3,−1,−2)\mathbf{s} = (3, -1, -2) the triangle gives

f1+f3=3,−f1+f2=−1,−f2−f3=−2.\begin{aligned} f_1 + f_3 &= 3, \\[0.4em] -f_1 + f_2 &= -1, \\[0.4em] -f_2 - f_3 &= -2. \end{aligned}

The flow (2,1,1)(2, 1, 1) satisfies all three. Node 2 receives 2 units, consumes 1 and passes 1 on, so its net outflow is 1−2=−11 - 2 = -1, its net supply. To find every solution, set f1=tf_1 = t. The second equation gives f2=t−1f_2 = t - 1 and the first gives f3=3−tf_3 = 3 - t. The third then holds automatically, since its left side is minus the sum of the other two left sides and −2=−(3−1)-2 = -(3 - 1). So every compatible flow is

f=[tt−13−t]=[0−13]+t[11−1]\mathbf{f} = \begin{bmatrix} t \\ t - 1 \\ 3 - t \end{bmatrix} = \begin{bmatrix} 0 \\ -1 \\ 3 \end{bmatrix} + t\begin{bmatrix} 1 \\ 1 \\ -1 \end{bmatrix}

for some real number tt, and the value t=2t = 2 gives (2,1,1)(2, 1, 1) again.

Circulation around a cycle

Definition A cycle is a closed route through the graph that starts and ends at the same node, uses each edge at most once and passes through no node twice apart from its return to the start. The route may use an edge along or against its arrow. Choose a direction of travel. The circulation around the cycle is the vector c\mathbf{c} in Rm\mathbb{R}^m with ck=1c_k = 1 if the route uses edge kk along its arrow, ck=−1c_k = -1 if it uses edge kk against its arrow, and ck=0c_k = 0 if it does not use edge kk. Then Bc=0B\mathbf{c} = \mathbf{0}, because at each node of the route the edge used to arrive contributes −1-1 and the edge used to leave contributes +1+1, whichever way their arrows point. Hence f+αc\mathbf{f} + \alpha\mathbf{c} has the same net supplies as f\mathbf{f} for every real α\alpha. For a connected graph, rank-nullity gives

dim⁡Null⁡B=m−(n−1)=m−n+1,\begin{aligned} \dim \operatorname{Null} B &= m - (n - 1) \\[0.4em] &= m - n + 1, \end{aligned}

and Null⁡B\operatorname{Null} B is spanned by circulations around cycles.

In plain words Pushing one extra unit around a loop, in the direction of travel, brings one more unit into each node of the loop and takes one more unit out of it. The routes change and every node balance stays as it was. Edges that the loop uses against their arrows lose flow, which is why a circulation can have negative entries.

Example In the triangle, travel 1→2→3→11 \to 2 \to 3 \to 1. The route uses edges 1→21 \to 2 and 2→32 \to 3 along their arrows and edge 1→31 \to 3 against its arrow, so c=(1,1,−1)\mathbf{c} = (1, 1, -1), the direction vector of the solution family above. Directly,

Bc=[1+0−1−1+1+00−1+1]=0.B\mathbf{c} = \begin{bmatrix} 1 + 0 - 1 \\ -1 + 1 + 0 \\ 0 - 1 + 1 \end{bmatrix} = \mathbf{0}.

Raising tt by 11 sends one more unit along the route through node 2 and one unit less along the direct edge. Here m−n+1=3−3+1=1m - n + 1 = 3 - 3 + 1 = 1, so any two compatible flows differ by a multiple of c\mathbf{c}. If the direct edge is removed, the remaining columns (1,−1,0)(1, -1, 0) and (0,1,−1)(0, 1, -1) are independent, the kernel is {0}\{\mathbf{0}\}, and node 1 and node 2 force the unique flows f1=3f_1 = 3 and f2=2f_2 = 2. Removing the only cycle removed the freedom.

Nonnegative flow constraint

Definition If each edge can carry material only along its arrow, as in a one-way pipe or street, the model adds the inequalities fk≥0f_k \ge 0 for every edge kk, written f≥0\mathbf{f} \ge \mathbf{0}. A flow is feasible when it satisfies both Bf=sB\mathbf{f} = \mathbf{s} and f≥0\mathbf{f} \ge \mathbf{0}. The inequalities are an extra requirement of the model, not a consequence of the linear system. The feasible set is the part of the solution set of Bf=sB\mathbf{f} = \mathbf{s} in which every entry is nonnegative. If f\mathbf{f} and g\mathbf{g} are feasible, so is every flow (1−λ)f+λg(1 - \lambda)\mathbf{f} + \lambda\mathbf{g} with 0≤λ≤10 \le \lambda \le 1 between them, but the feasible set is a subspace only in the trivial case where it is {0}\{\mathbf{0}\}. When s≠0\mathbf{s} \ne \mathbf{0} it does not contain 0\mathbf{0}, and when it contains a nonzero f\mathbf{f} it does not contain −f-\mathbf{f}, which has a negative entry. It can be a single point, a bounded segment, an unbounded set, or empty even when Bf=sB\mathbf{f} = \mathbf{s} has solutions.

In plain words The equations say which flows balance, and the inequalities say which flows the pipes allow. A flow can pass every node check and still be ruled out because one of its entries is negative.

Example In the triangle with s=(3,−1,−2)\mathbf{s} = (3, -1, -2), the conditions t≥0t \ge 0, t−1≥0t - 1 \ge 0 and 3−t≥03 - t \ge 0 together give

1≤t≤3.1 \le t \le 3.

The infinite line of signed solutions shrinks to a closed segment. At t=1t = 1 the flow is (1,0,2)(1, 0, 2) and edge 2→32 \to 3 is idle. At t=3t = 3 it is (3,2,0)(3, 2, 0) and the direct edge is idle. The value t=0t = 0 gives (0,−1,3)(0, -1, 3), which balances every node but sends one unit backward along edge 2→32 \to 3, so it is not feasible.

Total supply condition

Definition Every column of BB sums to zero, so 1⊤B=0⊤\mathbf{1}^{\top}B = \mathbf{0}^{\top}. For every flow the entries of BfB\mathbf{f} therefore add to 1⊤Bf=0\mathbf{1}^{\top}B\mathbf{f} = 0, and the system Bf=sB\mathbf{f} = \mathbf{s} can have a solution only if

s1+s2+⋯+sn=0.s_1 + s_2 + \cdots + s_n = 0.

For a connected graph with signed flows the condition is also sufficient. A vector lies in Col⁡B\operatorname{Col} B exactly when it is orthogonal to Null⁡B⊤\operatorname{Null} B^{\top}, and that null space is spanned by 1\mathbf{1}. If the graph splits into several connected pieces with no edges between them, the supplies must add to zero on each piece separately. Under the constraint f≥0\mathbf{f} \ge \mathbf{0} the condition is still necessary but no longer sufficient in general, as the example below shows.

In plain words Edges only move material around inside the network, so the total put in must equal the total taken out. If it does not, then the data or the model is wrong, for example because a node stores material or an outlet is missing, and no choice of routes can repair that.

Example The supplies (3,−1,−1)(3, -1, -1) add to 11, so no flow on the triangle is compatible with them. For any supplies with s1+s2+s3=0s_1 + s_2 + s_3 = 0, the flow (s1,s1+s2,0)(s_1, s_1 + s_2, 0) works. Node 1 gets net outflow s1s_1, node 2 gets −s1+s1+s2=s2-s_1 + s_1 + s_2 = s_2 and node 3 gets −(s1+s2)=s3-(s_1 + s_2) = s_3. The supplies (−1,0,1)(-1, 0, 1) add to zero, and this construction gives the signed solution (−1,−1,0)(-1, -1, 0). With one-way edges, however, node 1 would need f1+f3=−1f_1 + f_3 = -1 with f1≥0f_1 \ge 0 and f3≥0f_3 \ge 0, which is impossible. Node 1 has only outgoing arrows, so it cannot absorb material.

Check yourself

  1. On the triangle network of this page, which of the supply vectors (2,1,−2)(2, 1, -2) and (2,1,−3)(2, 1, -3) can be balanced by signed flows? Give one balancing flow.
Show the answer

The first vector adds to 11, so it fails the total supply condition and no flow balances it. The second adds to 00 and the triangle is connected, so signed solutions exist. The construction (s1,s1+s2,0)(s_1, s_1 + s_2, 0) gives f=(2,3,0)\mathbf{f} = (2, 3, 0). At node 1 the net outflow is 2+0=22 + 0 = 2, at node 2 it is −2+3=1-2 + 3 = 1 and at node 3 it is −3−0=−3-3 - 0 = -3, matching the supplies. Every other balancing flow is (2,3,0)+α(1,1,−1)(2, 3, 0) + \alpha(1, 1, -1).

  1. Four nodes are joined by the edges 1→21 \to 2, 2→42 \to 4, 1→31 \to 3 and 3→43 \to 4, numbered in that order, and the supplies are (5,0,0,−5)(5, 0, 0, -5). Write the incidence matrix and find every signed flow. There are four equations in four unknowns, so is the flow unique? Which flows remain when every edge is one-way?
Show the answer

The incidence matrix is

B=[1010−110000−110−10−1].B = \begin{bmatrix} 1 & 0 & 1 & 0 \\ -1 & 1 & 0 & 0 \\ 0 & 0 & -1 & 1 \\ 0 & -1 & 0 & -1 \end{bmatrix}.

Set f1=tf_1 = t. Node 2 gives −t+f2=0-t + f_2 = 0, so f2=tf_2 = t. Node 1 gives t+f3=5t + f_3 = 5, so f3=5−tf_3 = 5 - t, and node 3 gives f4=f3=5−tf_4 = f_3 = 5 - t. Node 4 then holds, since −t−(5−t)=−5-t - (5 - t) = -5. So

f=[0055]+t[11−1−1].\mathbf{f} = \begin{bmatrix} 0 \\ 0 \\ 5 \\ 5 \end{bmatrix} + t\begin{bmatrix} 1 \\ 1 \\ -1 \\ -1 \end{bmatrix}.

The flow is not unique, although the counts match. The rows of BB add to the zero row and the graph is connected, so rank⁡B=3\operatorname{rank} B = 3 and the kernel has dimension 4−3=14 - 3 = 1. The direction (1,1,−1,−1)(1, 1, -1, -1) is the circulation around the cycle 1→2→4→3→11 \to 2 \to 4 \to 3 \to 1, which uses the last two edges against their arrows. With one-way edges the conditions t≥0t \ge 0 and 5−t≥05 - t \ge 0 give 0≤t≤50 \le t \le 5, from everything through node 3 at t=0t = 0 to everything through node 2 at t=5t = 5.

  1. In the network of question 2 the supplies change to (−2,0,0,2)(-2, 0, 0, 2). Do signed flows exist? Do flows exist when every edge is one-way?
Show the answer

The supplies add to zero and the graph is connected, so signed flows exist. The same steps with f1=tf_1 = t give f=(t,t,−2−t,−2−t)\mathbf{f} = (t, t, -2 - t, -2 - t). For instance t=−2t = -2 gives (−2,−2,0,0)(-2, -2, 0, 0), which moves 2 units from node 4 back to node 1 through node 2. Check node 4, where −f2−f4=2−0=2-f_2 - f_4 = 2 - 0 = 2. Nonnegativity needs t≥0t \ge 0 and −2−t≥0-2 - t \ge 0, that is t≤−2t \le -2, and no tt does both. The feasible set is empty even though the total supply condition holds. The reason is visible at node 1, which has only outgoing edges, so its net outflow f1+f3f_1 + f_3 cannot be −2-2 when both flows are nonnegative.

How this lesson connects