Learn
Lesson · Networks: Flows, Paths and Assignments · The network as a programme

Arcs, Capacities and Conservation

A network on this course is not a picture. It is a list of ordered arcs, each with a capacity and a cost, and a supply at every node; and a flow on it is a number per arc that has to survive two separate tests. Conservation is local, so a flow can balance in total and still fail. Capacity is a different test entirely, so a flow can conserve everywhere and still ask an arc to carry more than it can.

an arc is ORDERED: a to b and b to a are two objects, two capacities, two costs conservation at node i: (out of i) − (into i) = bᵢ one equation per node capacity on arc j: 0 ≤ xⱼ ≤ uⱼ one row per BOUNDED arc only Σᵢ bᵢ = 0, or nothing is feasible: add the node equations and every flow cancels s>a 5:2 capacity 5, cost 2 per unit s>a *:2 no upper bound at all
The two tests a flow must pass, and the one the data must pass first

Core ideas

What this lesson establishes

Drawing the arrows is the easy part. The three ideas here are the ones that decide whether what you have written down can be solved at all.

1

An arc is ordered, and an adjacency matrix cannot hold one

A matrix indexed by a pair of nodes has one cell for that pair. A directed network needs two: a to b may hold 4 units at a price of 2 while b to a holds 3 at a price of 5, and those are different variables in the programme that follows. The lab stores an array of arcs for exactly this reason, and it will hold two copies of the same arc if you type it twice.

2

Conservation is local, and its failures cancel

Each node carries one equation: what leaves minus what arrives equals what that node supplies. Add all those equations together and every arc appears once positively and once negatively, so the total is always zero — which means a single overall verdict can never detect a violation. The imbalances have to be reported node by node or they are invisible.

3

Capacity is a second test, and an unbounded arc is not a large number

A flow that conserves at every node has said nothing about whether the arcs can carry it. Those are two independent checks and the lab runs both. An arc written with no upper bound contributes no capacity row at all — which is what “unbounded” means, and is different from an arc bounded by some very large constant, because the constant can bind and infinity cannot.

The material

Everything a network is, before anything is optimised

The data, then the two tests, then the three ways the data itself can already be wrong.

Definition · A directed network with capacities and costs

A directed network is a set of nodes together with a list of arcs. Each arc has a tail, a head, a capacity u (possibly no upper bound) and a cost c per unit. Each node i carries a supply bᵢ, positive where goods enter the network and negative where they leave.

A flow is one number xⱼ ≥ 0 for each arc. It is feasible when it conserves at every node and respects every capacity.

The lab takes a network as text, one clause per arc: s>a 5:2 is an arc from s to a with capacity 5 and cost 2. A * in the capacity field means no upper bound; 7/2 is seven halves, exactly, because the field separator is a colon and a slash is therefore free to mean division. A clause running from a node back to itself is refused rather than drawn, and so is a negative capacity.

the network the supplies a proposed flow s>a 5:2 s : 4 s>a 4 a>b 4:2 t : -4 a>b 2 b>a 3:5 b>a 0 a>t 3:1 a>t 2 b>t 4:3 b>t 2 conservation, node by node: out − in supplied s 4 − 0 = 4 4 ✓ a 2 + 2 − 4 = 0 0 ✓ b 0 + 2 − 2 = 0 0 ✓ t 0 − 4 = −4 −4 ✓ capacity: 4 ≤ 5, 2 ≤ 4, 0 ≤ 3, 2 ≤ 3, 2 ≤ 4 ✓ cost: 4(2) + 2(2) + 0(5) + 2(1) + 2(3) = 20

Two arcs in that list join the same pair of nodes. a>b carries up to 4 at a price of 2; b>a carries up to 3 at a price of 5. They are two variables. Sending one unit forward and two back costs 12; sending two forward and one back costs 9 — same total movement, different bill, because the directions are priced separately. The lab draws the pair in its own colour so that the two arrows cannot be read as one edge.

Conservation fails locally, and the total will not tell you

Example · A flow that balances overall and is not a flow

Change one number in the flow above — a>b from 2 to 1 — and the net outflows become 4, −1, 1, −4 against supplies 4, 0, 0, −4. Node a now takes in one more unit than it sends on, and node b sends on one more than it takes in.

Those two errors are equal and opposite, so the imbalances still sum to zero, and any check that adds them up passes. The lab names a and b instead, and shades the two of them, because a verdict of “this flow is invalid” is not something a reader can act on.

Example · A flow that conserves everywhere and is still impossible

Set the supplies to s: 5, t: −5 and the flow to s>a 5, a>b 5, b>a 0, a>t 0, b>t 5. Every node balances exactly.

Two arcs are over capacity: a>b is asked for 5 where it holds 4, and b>t for 5 where it holds 4. Conservation cannot see this, because the node equations contain no capacities at all. The two tests are separate and the lab runs them separately.

Two things the data can get wrong before any flow does

Add the node equations together. Every arc leaves exactly one node and enters exactly one, so its variable appears once with a plus and once with a minus and cancels. What is left is Σᵢ bᵢ = 0. So if the supplies do not sum to zero, the equations contradict each other and no flow of any kind exists — a test that costs one addition and needs no algorithm.

Example · Six in, four out

Leave the network alone and set the supplies to s: 6, t: −4. The lab reports a total of 2 and stops: adding the four node equations gives 2 = 0.

This is worth meeting before the programme is written rather than after a solver reports infeasibility, because the diagnosis is completely different. Nothing is wrong with the network; the demand does not match the supply, and the fix is to say what happens to the surplus.

The second is quieter. A flow may only name arcs that exist: write s>c 1 on a network with no such arc and the lab refuses it rather than creating one. This sounds pedantic until you have spent twenty minutes on a transportation problem in which a route you assumed was available was never in the data.

Everything from here on is this object with an objective attached. The arcs become the columns of a matrix, the nodes become its rows, the supplies become the right-hand side, and the whole of the rest of the course is what that matrix turns out to be like.

Interactive

Arcs, capacities and conservation

Two arcs between the same pair are two variables — and conservation is checked node by node

Arcs, capacities and conservationan arc is ordered: a to b and b to a are two objects
an arc inside its capacityover capacity, or a node that failsan arc whose reverse is also here

Method

Checking a flow somebody has handed you

The data first, then conservation, then capacity, and the cost last. Doing them in that order means an infeasible instance never reaches the arithmetic.

1

Add the supplies up

If Σ bᵢ is not zero, stop. There is no feasible flow and no flow you write down will be one. This is one addition and it is the cheapest test on the course.

2

Check that every arc in the flow is an arc in the network

And that every arc in the network has been given a value, even if that value is zero. A missing arc is usually a typing error; an invented arc is usually a wish.

3

Compute net outflow at each node separately

Out minus in, one node at a time, against bᵢ. Do not add the results up: the sum is always zero and it will tell you nothing. Write the imbalance beside each node and look for the non-zero ones.

4

Check every capacity, including the ones you think are slack

0 ≤ xⱼ ≤ uⱼ on each arc. Conservation has said nothing about this. An arc with no upper bound needs only xⱼ ≥ 0.

5

Only then price it

Σⱼ cⱼ xⱼ. Pricing an infeasible flow produces a number, and the number is meaningless; the lab still prints it, because a reader who watches a cost appear beside a red banner learns something a hidden field cannot teach.

Arcs, nodes, and what each test can see

Score 0 / 0

One network, four flows, and what each one fails

The same five arcs throughout. Only the supplies and the flow change, and each line of arithmetic below is a test rather than a step towards an answer.

arcs s>a 5:2 a>b 4:2 b>a 3:5 a>t 3:1 b>t 4:3 A supplies s:4 t:-4 flow 4, 2, 0, 2, 2 total supply 4 + (-4) = 0 data ok net out s: 4 a: 0 b: 0 t: -4 conserves capacity 4/5 2/4 0/3 2/3 2/4 fits cost 8 + 4 + 0 + 2 + 6 = 20 FEASIBLE B supplies s:4 t:-4 flow 4, 1, 0, 2, 2 net out s: 4 a: -1 b: 1 t: -4 ^^^^^ ^^^ two nodes fail sum of imbalances 4 - 1 + 1 - 4 = 0 always, so useless cost 8 + 2 + 0 + 2 + 6 = 18 a cheaper NON-flow C supplies s:5 t:-5 flow 5, 5, 0, 0, 5 net out s: 5 a: 0 b: 0 t: -5 conserves capacity 5/5 5/4 0/3 0/3 5/4 ^^^ ^^^ two arcs over D supplies s:6 t:-4 flow 4, 2, 0, 2, 2 total supply 6 + (-4) = 2 ≠ 0 adding the four node equations gives 2 = 0 INFEASIBLE, and no flow needed to be written at all two arcs, one pair of nodes: a>b 4:2 and b>a 3:5 1 forward and 2 back 1(2) + 2(5) = 12 2 forward and 1 back 2(2) + 1(5) = 9

Case B is the one to sit with. It is cheaper than case A, it passes every capacity, and the imbalances add to zero. Nothing about it is wrong except that it is not a flow, and the only way to find that out is to look at the nodes one at a time.

For a rehearsal, take case A and try to move one unit off a>t without breaking anything. You will find that the unit has to go somewhere, that the only other way out of a is a>b, and that b then has to pass it on — so the repair is forced, and the repaired flow costs 22 rather than 20. That forced chain is a cycle in disguise, and it comes back as the stepping-stone cycle in the transportation lessons.

The harder rehearsal: type an arc with * in the capacity field and satisfy yourself that the lab stops printing a capacity ratio for it. An unbounded arc contributes no row to the programme that follows, which is not the same thing as contributing a row with a very large number in it.

Common mistakes

1
Treating the two arcs between a pair of nodes as one edgeThis is the undirected habit surviving into a directed setting, and it is the error this lesson exists for. The two arcs have separate capacities, separate costs and separate variables, and nothing in the model makes their flows related. A reader who collapses them will later write a transportation tableau with the wrong number of columns and never find out why the answer is cheap.
2
Adding the imbalances up and reading the total as a verdictThe total is zero for every flow ever written, feasible or not. It is not a weak check, it is a check with no information in it. Report the imbalance at each node separately, and if you are writing code that reports a single boolean, make it return the list of failing nodes instead.
3
Modelling an unbounded arc with a large constantA capacity of one million is a capacity: it appears as a row in the programme, it can be tight at the optimum, and it can produce a shadow price on a constraint you invented. An arc with no upper bound contributes no row at all. If the quantity really is unbounded, say so; if it is not, use the real bound.

Check your understanding

✓
Finish when you can take a drawing and a proposed flow and say exactly which test fails and where.

You should be able to write a directed network as arcs with capacities and costs, check the supplies sum to zero before anything else, compute net outflow node by node without adding the results up, check capacities separately, and explain why an arc and its reverse are two variables.

Note: Everything checked here was checked against the network as written down, and nothing yet has been optimised. That is the right order: a flow that fails conservation is not a bad solution, it is not a solution. The next lesson, “The Minimum-Cost Flow Programme”, turns these same two tests into the rows of a matrix and hands the result to the simplex method — at which point four problems you may have met separately turn out to be the same one.

Kept in this browser only, for you. Nothing is sent anywhere and nothing checks it. Carry it to another device.

Feedback and recommendations

Something to change about this lesson? Write it down, tick it off when it is handled, and export the list when you want to act on it. Kept in this browser only: nothing is sent anywhere, and nobody is notified.

No recommendations yet for this lesson.