Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

11. Dependency graphs: critical paths, maximum flow and Braess’s paradox

School of Engineering, Nazarbayev University

Why can paying overtime to speed up most of the tasks in a chemical plant turnaround save no time at all on the restart date? And how can a new road with zero travel time make every commuter slower (Braess 1968)? Both questions are answered by Mental Move #20, Optimize Only Zero-Slack Critical Bottlenecks. In this lecture, you will compute topological schedules, slack floats, and critical paths on dependency DAGs (reductions_constraints.critical_path_dag), uncover the Critical Path Shift trap during task crashing, pinpoint single-point-of-failure network bridges, simulate Braess’s Paradox (selfish Nash equilibrium vs. social optimum), and check max-flow / min-cut duality.

Learning objectives

  1. Execute Kahn’s topological sort plus forward/backward pass relaxation (reductions_constraints.critical_path_dag) to compute earliest/latest schedules, total slack floats, and zero-slack critical paths.

  2. Explain why expediting positive-slack tasks saves zero project time and identify exact ‘Critical Path Shift’ knees when crashing bottleneck tasks.

  3. Audit infrastructure networks for single-point-of-failure cut-edges and reproduce Braess’s (1968) Paradox where adding network capacity degrades selfish Wardrop/Nash equilibrium.

  4. Verify Edmonds–Karp Max-Flow == Min-Cut duality and implement stochastic PERT Monte Carlo scheduling to quantify Jensen’s merge-bias delay (E[max⁡PLP]>max⁡PE[LP]\mathbb{E}[\max_P L_P] > \max_P \mathbb{E}[L_P]).

Time: about 60 min

1. Dependency DAGs, Kahn’s Topological Sort & Critical Path Slack

A complex engineering build consists of tasks u∈Vu \in V with durations du≥0d_u \geq 0 and precedence edges (u→v)∈E(u \to v) \in E (“uu must finish before vv can start”). If (V,E)(V, E) has a directed cycle, the schedule deadlocks; otherwise Kahn’s in-degree algorithm yields a topological order (u1,…,uN)(u_1, \dots, u_N) enabling two linear-time O(∣V∣+∣E∣)\mathcal{O}(|V| + |E|) passes:

  1. Forward Pass (Earliest Start / Finish):

    ES(u)=max⁡p∈Pred(u)EF(p)(default 0),EF(u)=ES(u)+du,T∗=max⁡u∈VEF(u)(1.1)\mathrm{ES}(u) = \max_{p \in \mathrm{Pred}(u)} \mathrm{EF}(p) \quad (\text{default } 0), \qquad \mathrm{EF}(u) = \mathrm{ES}(u) + d_u, \qquad T^* = \max_{u \in V} \mathrm{EF}(u) \tag{1.1}
  2. Backward Pass (Latest Start / Finish without delaying T∗T^*):

    LF(u)=min⁡v∈Succ(u)LS(v)(default T∗),LS(u)=LF(u)−du(1.2)\mathrm{LF}(u) = \min_{v \in \mathrm{Succ}(u)} \mathrm{LS}(v) \quad (\text{default } T^*), \qquad \mathrm{LS}(u) = \mathrm{LF}(u) - d_u \tag{1.2}

The difference Slack(u)=LS(u)−ES(u)=LF(u)−EF(u)≥0\mathrm{Slack}(u) = \mathrm{LS}(u) - \mathrm{ES}(u) = \mathrm{LF}(u) - \mathrm{EF}(u) \geq 0 is the total float task uu can slip without delaying T∗T^*. Tasks with Slack(u)=0\mathrm{Slack}(u) = 0 form the Critical Path—the longest path in the DAG.


Demonstration 1: Plant turnaround critical path, Gantt schedule and slack floats
================================================================================
Mental Move #20 (Optimize Only Zero-Slack Critical Bottlenecks): slack(u) = LS(u) - ES(u) == 0 defines critical path
Task            | Dur [h] |  ES [h] |  EF [h] |  LS [h] | Slack [h] | Status
----------------------------------------------------------------------------
A_Purge         |     6.0 |     0.0 |     6.0 |     0.0 |       0.0 | CRITICAL
B_Scaffold      |     4.0 |     0.0 |     4.0 |     2.0 |       2.0 | buffered
E_Exchanger     |    10.0 |     6.0 |    16.0 |    18.0 |      12.0 | buffered
C_ReactorOpen   |     8.0 |     6.0 |    14.0 |     6.0 |       0.0 | CRITICAL
F_PipingWeld    |     7.0 |     4.0 |    11.0 |    16.0 |      12.0 | buffered
D_Catalyst      |    14.0 |    14.0 |    28.0 |    14.0 |       0.0 | CRITICAL
G_ValveCalib    |     5.0 |    11.0 |    16.0 |    23.0 |      12.0 | buffered
H_HydroTest     |     6.0 |    28.0 |    34.0 |    28.0 |       0.0 | CRITICAL
I_Startup       |     5.0 |    34.0 |    39.0 |    34.0 |       0.0 | CRITICAL
<Figure size 880x473 with 1 Axes>

Figure 11.1. Gantt chart of the nine turnaround tasks at their earliest start times. Critical tasks (red) have zero slack; for the other tasks (blue) the hatched bar shows the slack, 2 to 12 h. The project takes 39 h.

What Demonstration 1 shows. Out of 9 turnaround tasks, 4 (B_Scaffold, E_Exchanger, F_PipingWeld, G_ValveCalib) carry 2 to 12 hours of slack float. Paying double-time emergency crews to finish E_Exchanger 5 hours early saves 0.0 hours on plant restart because H_HydroTest is still waiting on D_Catalyst (EF = 28 h).


2. Task Crashing Sensitivity & The Bottleneck Knee

What happens as we progressively crash (expedite) critical task D_Catalyst (14 h→2 h14\ \mathrm{h} \to 2\ \mathrm{h})? Look at the parallel paths feeding H_HydroTest:

  • Primary critical branch A -> C -> D: 6+8+14=28 h6 + 8 + 14 = 28\ \mathrm{h}.

  • Secondary branch A -> E: 6+10=16 h6 + 10 = 16\ \mathrm{h} (slack =12 h= 12\ \mathrm{h}), and B -> F -> G: 4+7+5=16 h4 + 7 + 5 = 16\ \mathrm{h} (slack =12 h= 12\ \mathrm{h}).

So D_Catalyst can be shortened by up to 12 h12\ \mathrm{h} before A -> C -> D ties with A -> E and B -> F -> G at t=16 ht = 16\ \mathrm{h}. Beyond ΔdD=12 h\Delta d_D = 12\ \mathrm{h} it is no longer the only bottleneck, and the project duration stays at 27 h27\ \mathrm{h}.


Demonstration 2: Crashing non-critical tasks (0 savings) against critical bottleneck knee
=========================================================================================
Crashing all 4 non-critical tasks by 50% : 39.0 h -> 39.0 h (0.0 h saved: these tasks have slack)
Crashing D_Catalyst by 12 h (14 -> 2 h)  : 39.0 h -> 27.0 h (12.0 h saved, 1:1 return)
Crashing D_Catalyst by 14 h (14 -> 0 h)  : 39.0 h -> 27.0 h (parallel paths E & G took over at 27.0 h)
<Figure size 792x429 with 1 Axes>

Figure 11.2. Project duration against the hours by which D_Catalyst is shortened. Each hour saves one hour until 12 h (dotted), when the parallel branches become critical; shortening the non-critical tasks (dashed) saves nothing.

What Demonstration 2 shows. Shortening any task off the critical path does not change the project duration (∂T∗/∂du=0\partial T^* / \partial d_u = 0 whenever Slack(u)>0\mathrm{Slack}(u) > 0), the same lesson as Amdahl’s law for parallel programs. Shortening D_Catalyst returns one hour per hour up to 12 h12\ \mathrm{h} and nothing after that.


3. Infrastructure Vulnerability: Single-Point-of-Failure Bridges vs. Redundant Meshes

Just as zero-slack tasks govern time schedules, cut-edges (bridges) and minimum-cut bottlenecks govern spatial infrastructure resilience (power grids, water trunklines, data center interconnects). We audit every link ee of an 8-substation regional transmission graph by measuring the disconnected load or capacity drop ΔF(e)=Fnominal−F(G∖{e})\Delta F(e) = F_{\mathrm{nominal}} - F(G \setminus \{e\}) when link ee fails.


Demonstration 3: Single-point-of-failure bridge and link-outage sensitivity audit
=================================================================================
Outage on link 0->1  : Remaining Flow =  50.0 MW (Capacity Loss =  41.2%)
Outage on link 0->2  : Remaining Flow =  50.0 MW (Capacity Loss =  41.2%)
Outage on link 1->3  : Remaining Flow =  50.0 MW (Capacity Loss =  41.2%)
Outage on link 2->3  : Remaining Flow =  50.0 MW (Capacity Loss =  41.2%)
Outage on link 3->4  : Remaining Flow =   0.0 MW (Capacity Loss = 100.0%)
Outage on link 4->5  : Remaining Flow =  50.0 MW (Capacity Loss =  41.2%)
Outage on link 4->6  : Remaining Flow =  50.0 MW (Capacity Loss =  41.2%)
Outage on link 5->7  : Remaining Flow =  50.0 MW (Capacity Loss =  41.2%)
Outage on link 6->7  : Remaining Flow =  50.0 MW (Capacity Loss =  41.2%)
<Figure size 814x418 with 1 Axes>

Figure 11.3. Loss of throughput when each link of the eight-substation network fails. Any link of the two redundant diamonds costs 41.2 %; the single bridge 3->4 costs 100 %.

What Demonstration 3 shows. Upgrading any of the eight diamond links from 50→200 MW50 \to 200\ \mathrm{MW} adds 0 MW0\ \mathrm{MW} of throughput, because the 85 MW85\ \mathrm{MW} bridge 3->4 limits the flow, and an outage of that one bridge still cuts the flow to zero.


4. Braess’s (1968) Paradox: a Zero-Cost Shortcut That Slows Every Trip

Added capacity can even make a network slower. Consider Dietrich Braess’s (1968) 4-node diamond network carrying F=4,000F = 4{,}000 commuters from SS to TT:

  • Top route S→A→TS \to A \to T: congestion-sensitive bridge cSA(f)=f/100c_{SA}(f) = f / 100 [min] followed by wide highway cAT=45c_{AT} = 45 [min].

  • Bottom route S→B→TS \to B \to T: wide highway cSB=45c_{SB} = 45 [min] followed by congestion-sensitive bridge cBT(f)=f/100c_{BT}(f) = f / 100 [min].

  1. Before the Shortcut: Symmetry splits traffic 2,000/2,0002{,}000 / 2{,}000; every driver takes 20+45=65 min20 + 45 = \mathbf{65\ \mathrm{min}} (the social optimum of this network without the cross-link).

  2. After Opening an Instantaneous Cross-Link A→BA \to B (cAB=0 minc_{AB} = 0\ \mathrm{min}): Because f/100≤40<45f / 100 \leq 40 < 45 for any f≤4,000f \leq 4{,}000, every individual driver sees S→AS \to A as strictly faster than S→BS \to B and B→TB \to T as strictly faster than A→TA \to T. In the Wardrop (Nash) equilibrium all traffic takes the path S→A→B→TS \to A \to B \to T, which loads both bridges fully: every trip takes 40+0+40=80 min40 + 0 + 40 = \mathbf{80\ \mathrm{min}}, 23 % longer than before. The social optimum with the cross-link is 64.69 min on average, so the price of anarchy is 80/64.69=1.23780 / 64.69 = 1.237.


Demonstration 4: Computational simulation of Braess's (1968) routing paradox
============================================================================
At F = 4,000 commuters without shortcut : Nash Equilibrium = 65.0 min
At F = 4,000 commuters with 0-min link  : Nash Equilibrium = 80.0 min (+15.0 min Braess Paradox)
At F = 4,000 Social Optimum with link   : Avg Latency      = 64.69 min (Price of Anarchy = 1.237)
<Figure size 825x451 with 1 Axes>

Figure 11.4. Braess’s network: equilibrium travel time against the demand FF. Above about 3,000 vehicles per hour the Wardrop equilibrium with the zero-time cross-link (solid) is slower than without it (dashed); at F=4,000F = 4{,}000 the times are 80 and 65 min. The dotted curve is the social optimum with the link.

Inside the algorithm

Critical paths and flow networks share a duality between a bottleneck and a bound:

  • Longest Path (Critical Path) ⟺\Longleftrightarrow Minimum Project Makespan (you cannot finish faster than your longest serial chain, and setting start times tu=ES(u)t_u = \mathrm{ES}(u) achieves that exact chain length).

  • Maximum ss-tt Flow ⟺\Longleftrightarrow Minimum ss-tt Cut Capacity (Ford & Fulkerson, 1956): when Edmonds–Karp terminates with no augmenting path in the residual network GfG_f, the set ScutS_{\mathrm{cut}} of vertices still reachable from src in GfG_f defines an ss-tt cut (Scut,V∖Scut)(S_{\mathrm{cut}}, V \setminus S_{\mathrm{cut}}) whose saturated forward capacity equals max_flow. We inspect critical_path_dag and check Max-Flow / Min-Cut duality from scratch.

Check against the library


Inside the algorithm: critical_path_dag and Edmonds-Karp max-flow / min-cut duality
===================================================================================
def critical_path_dag(tasks: dict[str, float], dependencies: list[tuple[str, str]]) -> dict:
    """Compute topological order, earliest/latest schedules, slack floats, and critical path on a project DAG."""
    if not tasks or any(d < 0.0 for d in tasks.values()):
        raise ValueError("Require non-empty tasks with durations >= 0.")
    adj: dict[str, list[str]] = {u: [] for u in tasks}
    preds: dict[str, list[str]] = {u: [] for u in tasks}
    indeg: dict[str, int] = {u: 0 for u in tasks}

    for u, v in dependencies:
        if u not in tasks or v not in tasks:
            raise ValueError(f"Unknown task in dependency ({u!r}, {v!r}).")
        adj[u].append(v)
        preds[v].append(u)
        indeg[v] += 1

    q: deque[str] = deque(sorted([u for u, deg in indeg.items() if deg == 0]))
    topo: list[str] = []
    while q:
        u = q.popleft()
        topo.append(u)
        for v in sorted(adj[u]):
            indeg[v] -= 1
            if indeg[v] == 0:
                q.append(v)

    if len(topo) != len(tasks):
        raise ValueError("Dependency graph contains a cycle; Critical Path Method requires a DAG.")

    es: dict[str, float] = {}
    ef: dict[str, float] = {}
    for u in topo:
        es[u] = max((ef[p] for p in preds[u]), default=0.0)
        ef[u] = es[u] + float(tasks[u])

    proj_dur = max(ef.values())
    ls: dict[str, float] = {}
    lf: dict[str, float] = {}
    for u in reversed(topo):
        lf[u] = min((ls[v] for v in adj[u]), default=proj_dur)
        ls[u] = lf[u] - float(tasks[u])

    slack = {u: ls[u] - es[u] for u in topo}
    crit_nodes = [u for u in topo if abs(slack[u]) < 1e-11]
    return {
        "topological_order": topo,
        "project_duration": float(proj_dur),
        "earliest_start": es,
        "earliest_finish": ef,
        "latest_start": ls,
        "latest_finish": lf,
        "slack": slack,
        "critical_path": crit_nodes,
    }

Max-Flow = 23.0 == Min-Cut Capacity = 23.0 (Brute-force min over 16 cuts = 23.0)
Min-Cut Partition S = [0, 1, 2, 4], T = [3, 5] | Saturated Bottleneck Pipes = [(1, 3, 12.0), (4, 3, 7.0), (4, 5, 4.0)]

Exercises

Worked solutions are in 11_solutions.ipynb. The cell below the list is a short self-check to start from.

  1. Verify a result. Across 50 random positive task-duration vectors on the 9-task turnaround DAG, verify exact primal–dual LP duality between Minimum-Time Feasible Milestone Scheduling (T∗=project_durationT^* = \mathrm{project\_duration}) and Maximum Source-to-Sink Path Length (max⁡P∑u∈Pdu\max_P \sum_{u \in P} d_u), along with precedent feasibility and complementary slackness.

  2. Find how it fails. Verify all ValueError guards on critical_path_dag (empty tasks, negative duration, unknown dependency task, and a cyclic dependency deadlock vs. naive unguarded DFS), then audit a Critical Path Shift scenario where crashing a primary task by 10 h10\ \mathrm{h} yields only 4 h4\ \mathrm{h} of net schedule reduction.

  3. Implement it yourself. Implement pert_monte_carlo_schedule(tasks_abc, dependencies, n_trials=4000, seed=42) using exact Beta-PERT task-duration sampling (mean = (a + 4m + b)/6). Demonstrate Jensen’s Merge-Bias Inequality (E[TPERT]>TCPM(μ)\mathbb{E}[T_{\mathrm{PERT}}] > T_{\mathrm{CPM}}(\boldsymbol{\mu})) on a parallel chip-tapeout DAG and compute P50 / P90 completion quantiles plus per-task Criticality Index (probability each task lies on the realized critical path).


Self-check for the exercises
============================
All checks passed.