Learn
Lesson · Networks: Flows, Paths and Assignments · Paths, cuts and matchings

Shortest Paths and Node Potentials

Relax every arc, as many rounds as there are nodes, and the labels settle. What they settle on is not just a list of distances: it is a feasible solution of the dual programme, πⱼ − πᵢ ≤ cᵢⱼ on every arc, and the tight arcs are the shortest routes. Because every constraint is a difference, adding a constant to every label changes nothing — which is what makes them prices. A negative cycle is the dual saying it has no feasible point at all.

primal min Σ cᵢⱼ xᵢⱼ with one unit supplied at s and one demanded at t dual max πₜ − πₛ subject to πⱼ − πᵢ ≤ cᵢⱼ on every arc relax arc (i,j): if πᵢ + cᵢⱼ < πⱼ then πⱼ := πᵢ + cᵢⱼ tight arc: πⱼ − πᵢ = cᵢⱼ the tight arcs carry the shortest routes every constraint is a DIFFERENCE, so π and π + k are equally feasible an improvement in round n certifies a negative cycle: no potentials exist
The two programmes, the relaxation, and the two things a shift cannot change

Core ideas

What this lesson establishes

The algorithm takes three lines. What it computes takes a lesson, because the labels are the dual and readers meet them as distances.

1

A label is a price, and the whole vector floats

The dual constraint πⱼ − πᵢ ≤ cᵢⱼ involves only the difference of two labels, and so does the objective πₜ − πₛ. Add seven to every label and every constraint still holds and the objective is unchanged: the lab has a control that does exactly this and reports both facts. A distance from the source is one particular normalisation of a potential, chosen by setting πₛ = 0.

2

Tightness is complementary slackness

An arc with πⱼ − πᵢ = cᵢⱼ is tight. Complementary slackness says that flow can only travel on tight arcs, and that is exactly the statement that the shortest route uses tight arcs and no others. The lab draws the tight arcs heavily, so the shortest-path tree is visible as the subgraph where the dual constraint holds with equality.

3

A negative cycle is infeasibility, not a bug

Add the constraints round a cycle: the labels cancel completely and what is left is 0 ≤ (the cycle's total cost). A cycle of negative total cost therefore makes the dual infeasible, and by duality the primal is unbounded — go round the cycle forever and the cost falls forever. The relaxation detects it by still improving in a round it should not, and the lab names the cycle and prints what it costs.

The material

What the labels are, and what a negative cycle says

The dual first, then the relaxation that finds a feasible point of it, then the shift, then the case with no feasible point at all.

The shortest-path problem is already on this course: one unit supplied at the source, one demanded at the sink, and the costs read as lengths. What is new here is its dual, which is worth writing down because the labels every shortest-path algorithm computes turn out to be a feasible point of it.

Definition · Node potentials

A vector π, one number per node, is feasible for the shortest-path dual when πⱼ − πᵢ ≤ cᵢⱼ for every arc from i to j. The dual problem is to maximise πₜ − πₛ over all such vectors.

An arc is tight when the inequality holds with equality. The reduced cost of an arc is cᵢⱼ − (πⱼ − πᵢ), which is non-negative exactly when π is feasible.

The constraint says something plain: the price at the head may exceed the price at the tail by at most the cost of getting there. Any feasible π therefore has πₜ − πₛ at most the cost of every path from source to sink — add the constraints along the path and the intermediate terms cancel — so the dual objective is a lower bound on the shortest path. That is weak duality, in one line, with no machinery.

arcs s>a 4 s>b 2 b>a 1 a>t 3 b>t 7 relaxation, one round = one pass over the arcs in the order typed round 0 s 0 a - b - t - round 1 s 0 a 3 b 2 t 6 round 2 s 0 a 3 b 2 t 6 nothing moved, stop check every arc: c - (pi_j - pi_i) s>a 4 - (3 - 0) = 1 slack s>b 2 - (2 - 0) = 0 TIGHT b>a 1 - (3 - 2) = 0 TIGHT a>t 3 - (6 - 3) = 0 TIGHT b>t 7 - (6 - 2) = 1 slack dual objective pi_t - pi_s = 6 - 0 = 6 the tight arcs are exactly the route s, b, a, t, which costs 6

Two things about that table are worth noticing. The first is that a ends at 3 rather than 4: the direct arc costs 4 and the route through b costs 2 + 1 = 3, so the direct arc ends up slack. The second is that one pass over the arcs was enough, because the order they were typed in happened to relax them usefully; the second round is what proves it, by changing nothing.

The shift, and why the labels are prices

Example · Add seven to everything

Take the labels 0, 3, 2, 6 and add 7 to each, giving 7, 10, 9, 13. Every arc constraint still holds — each is a difference, and the seven cancels — and the dual objective is still 13 − 7 = 6. The same tight arcs are still tight.

Now add 5 to one label only. The lab reports the arcs that are violated, in red. This is the contrast that makes the point: the vector floats as a whole and does not float component by component, which is precisely the behaviour of a price.

This is why the lesson is called potentials rather than distances. Calling them distances is not wrong — the normalisation πₛ = 0 makes each label the distance from the source — but it hides the fact that the object is determined only up to a constant, and it makes the next two courses harder than they need to be, where the same potentials are used to reprice a network without changing which route is cheapest.

Example · A negative arc is fine

s>a 4, s>b 2, a>b −3, b>t 2, a>t 6 has a negative cost on it, and the labels settle at 0, 4, 1, 3 with s>a, a>b and b>t tight. The cheapest way to b is through a at 4 − 3 = 1, not the direct arc at 2.

So a negative cost is not a problem in itself — it is perfectly meaningful when an arc earns rather than spends. What cannot be tolerated is a cycle whose total is negative, which is a different thing entirely.

When no potentials exist

Example · Three arcs and no feasible dual point

x>y 1, y>z −3, z>x 1, x>z 5. Add the dual constraints round the cycle x, y, z, x: the labels cancel and what is left is 0 ≤ 1 + (−3) + 1 = −1. No vector π can satisfy all three, so the dual is infeasible.

The relaxation finds this by still improving when it should have stopped: the labels go 0, ∞, ∞ then −1, 1, −2 then −2, 0, −3 then −3, −1, −4, one unit lower every round and never settling. The lab names the cycle y, z, x and reports that it costs −1.

The word for this on the primal side is unbounded: send a unit round that cycle as many times as you like and the cost falls without limit. An unbounded primal and an infeasible dual are the pair the duality course described, and here they arrive as a picture you can point at.

One thing deliberately absent from this page is a second algorithm. Dijkstra's algorithm computes the same labels faster on non-negative costs, it belongs to Discrete Mathematics' “Shortest Paths and Dijkstra's Algorithm”, and putting it beside this one would invite the question “which is better” when the question here is “what are these numbers”. They are a dual solution. That is the lesson.

Interactive

Shortest paths as a linear programme

The labels are dual variables — prices on the nodes — and a negative cycle is dual infeasibility

Distance labels are pricesthe dual of the shortest-path programme: max πₜ − πₛ with π₌ − πₐ ≤ cₐ₌
a tight arc: the inequality holds with equalityan arc with slackan arc the potentials violate

Method

Finding the potentials, and checking somebody else's

Checking is much cheaper than finding, and this is the lesson where that gap is widest.

1

Set the source to zero and everything else to infinity

Zero is a normalisation. Any other value for the source works and shifts every label by the same amount, which the lab will show you; zero is chosen because it makes the labels read as distances.

2

Relax every arc, and repeat until a round changes nothing

Relaxing arc (i, j) means: if πᵢ + cᵢⱼ is less than πⱼ, lower πⱼ to it. A round that changes nothing is the stopping condition and the proof of feasibility at once.

3

If a round still improves after as many rounds as there are nodes, stop and find the cycle

There is a negative cycle, the dual is infeasible and the primal unbounded. Report the cycle and what it costs; no set of labels exists to report instead.

4

Check the result arc by arc

πⱼ − πᵢ ≤ cᵢⱼ on every arc, not just the ones on the route you expect. This is one subtraction per arc and it is the whole verification — a feasible π is a certificate that no path is shorter than πₜ − πₛ.

5

Read the route off the tight arcs

The arcs where the inequality is an equality carry the shortest paths. If more than one tight route reaches the sink, there is more than one shortest path, and that is information rather than ambiguity.

Potentials, tightness and cycles

Score 0 / 0

Three networks: one ordinary, one with a negative arc, one with no answer

Each block is the labels the relaxation settles on, the arc-by-arc check, and the dual objective. All three are what the lab reports.

NETWORK 1 s>a 4 s>b 2 b>a 1 a>t 3 b>t 7 round 0 0 - - - round 1 0 3 2 6 round 2 0 3 2 6 settled tight s>b, b>a, a>t 3 of 5 arcs dual pi_t - pi_s = 6 and the route s,b,a,t costs 6 shift +7 7 10 9 13 every arc still satisfied dual 13 - 7 = 6 unchanged shift one label by +5 instead: arcs violated, and the lab says which NETWORK 2 s>a 4 s>b 2 a>b -3 b>t 2 a>t 6 round 1 0 4 1 3 round 2 0 4 1 3 settled tight s>a, a>b, b>t dual 3. Note b is reached at 1 THROUGH a, not at 2 direct a negative ARC is fine NETWORK 3 x>y 1 y>z -3 z>x 1 x>z 5 round 0 0 - - round 1 -1 1 -2 round 2 -2 0 -3 round 3 -3 -1 -4 still falling the cycle y, z, x costs -3 + 1 + 1 = -1 adding the three dual constraints round it gives 0 ≤ -1 so the dual is INFEASIBLE and the primal UNBOUNDED

Network 1 settles after a single pass because the arcs happen to have been typed in a helpful order; the second round is not wasted, it is the proof. Reorder the arcs in the box and watch the number of rounds change while the answer does not.

For a rehearsal, take network 1 and hand-write the labels 0, 4, 2, 7. Every arc constraint holds, so this is a feasible dual point too — and its objective is 7, which is more than 6 and therefore impossible. Find your error: b>a gives 4 − 2 = 2 > 1, so the point is not feasible after all. This is the whole skill: a claimed certificate is checked arc by arc, not by eye.

The harder rehearsal: on network 3, change y>z from −3 to −2. The cycle now costs zero, the labels settle, and a feasible potential exists. A zero-cost cycle is the boundary case, and it is worth seeing both sides of it.

Common mistakes

1
Calling the labels distances and stopping thereThey are distances under the normalisation πₛ = 0 and they are potentials in general, and the difference matters as soon as you want to reprice a network, check somebody else's answer, or say what the dual objective is. A vector determined only up to a constant is a price; treating it as a fixed quantity leads to arguments about whose numbers are right when both are.
2
Confusing a negative arc with a negative cycleA negative arc is ordinary. A negative cycle makes the problem unbounded and no labels exist. Readers who have learned Dijkstra's algorithm first often carry over its non-negativity requirement as though it were a property of the problem rather than of that algorithm.
3
Checking a claimed potential only along the routeFeasibility is a statement about every arc, and the arcs that are not on the route are where a wrong claim hides. It is one subtraction per arc. A potential that passes every arc is a certificate; a potential that has only been checked along one path certifies nothing.

Check your understanding

✓
Finish when you can hand back a set of potentials and a one-line argument that no path is shorter.

You should be able to write the shortest-path dual, run the relaxation to a settled vector, check every arc, identify the tight arcs and read the route off them, explain why a constant shift changes nothing, and recognise a negative cycle as dual infeasibility rather than as a failure of the method.

Note: One number per node, checkable arc by arc, and it proves a lower bound on every route at once — the dual of a network problem keeps turning out to be a small object a reader can verify by hand. “Maximum Flow and Minimum Cut” does the same thing, and there the dual solution is not a set of numbers but a set of nodes: a cut, whose capacity bounds every flow and which the residual network hands you for free the moment the algorithm stops.

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.