Definition · A staged network and its value functionA staged network is a list of stages, each holding some nodes, together with arcs that only ever run forward: an arc may join a node in one stage to a node in any later stage, never to one in the same stage or an earlier one. Each arc carries a cost.
The value function f gives each node the cheapest total from that node to the finish: f(w) = 0 for every node in the last stage, and f(v) = min over arcs out of v of c(v,w) + f(w) otherwise. An argmin at v is an arc attaining that minimum; there may be more than one.
The lab takes the stages as names separated by semicolons and the arcs one clause each, tail then > then head then cost. An arc that runs backwards or sideways is refused with the two stage numbers named, because that is a modelling error rather than a typing one: a network with a cycle in it has no last stage to start from and the recursion has nowhere to bottom out.
stages A ; B C ; D E ; F
arcs A>B 0 A>C 4 B>D 7 B>E 4 C>D 3 C>E 2 D>F 1 E>F 4
filled from the END:
f(F) = 0 last stage
f(D) = 1 + f(F) = 1
f(E) = 4 + f(F) = 4
f(B) = min( 7 + 1 , 4 + 4 ) = min( 8 , 8 ) = 8 TIE: D and E both
f(C) = min( 3 + 1 , 2 + 4 ) = min( 4 , 6 ) = 4 D
f(A) = min( 0 + 8 , 4 + 4 ) = min( 8 , 8 ) = 8 TIE: B and C both
six values written, and the answer is f(A) = 8
Read the last two lines again. f(A) is 8 and there are two ways to attain it, and f(B) is 8 with two ways to attain that. Following the argmins forward from A therefore produces three routes and not one: A B D F, A B E F and A C D F. The lab prices each of them again from the arcs before printing it, and all three come to 8.
The enumeration beside it, and what it is for
This network has four paths in total. Walked forwards and priced independently they come to 8, 8, 8 and 10, so the best is 8 and exactly three paths attain it. That agrees with the recursion, which is the point: the lab runs both and prints both, and shows nothing as an answer when they disagree. The enumeration is an oracle, not an alternative algorithm — it is exponential on purpose, and offering it as a way to solve these problems would undo the lesson.
Example · One arc cost, and the number of best answersChange A>B from 0 to 2 and nothing else. Every value in the table is the same except f(A), which becomes min(2 + 8, 4 + 4) = 8 — still 8, but now attained only through C. The tie at B is still there, f(B) is still 8 with D and E both attaining it, and the four paths now cost 10, 10, 8 and 10.
So the answer is the same number and one route instead of three, and the tie that remains is on no optimal route at all. A recursion that dropped ties would give identical output on both networks. That is worth sitting with: the two cases are one arc cost apart, and nothing in the value 8 distinguishes them.
An arc that skips a stage
Add A>E 3 to the original network. The recursion needs no adjustment at all: f(E) is already settled when f(A) is written, because E lives in a later stage, and the new candidate is 3 + 4 = 7. That beats 8, so f(A) becomes 7 and the single optimal route is A E F. Walking all five paths forwards agrees. What makes this work is not a special case in the code but the ordering: a value is written only once everything it depends on is final, and a forward jump does not disturb that.
Example · Where the stages actually come fromIn a routing problem the stages are given: they are the columns of the map. In most of the problems on this course they are not. A stage is whatever index makes the arcs run one way — an activity, a time period, a candidate, a number of periods left — and choosing it is choosing the model.
That is why this lesson comes first and why it is the easiest one here. Everything about the recursion is visible because the hard half has been done for you. The rest of the course does the hard half.
One last property, easy to miss because it looks like an implementation detail: a value is written once and never revised. If you find yourself wanting to go back and improve f at a node already filled in, either the ordering is wrong or the state is — and the second of those is the subject of everything that follows.