library(PRA)
# 10,000 iterations locally; fewer on CRAN so the vignette builds quickly.
n_sims <- if (nzchar(Sys.getenv("NOT_CRAN"))) 10000L else 1000L
n_lev <- if (nzchar(Sys.getenv("NOT_CRAN"))) 5000L else 500LThis case study analyzes the schedule of a mid-rise building. Its six work packages run on overlapping paths, share one tower crane and two finishing crews, and face two discrete risk events. Adding up task durations misses two effects. Where parallel paths merge, the finish is set by whichever path runs longest, so the expected finish is later than any single path suggests (merge bias). And a shared resource can hold an activity back after its predecessors are done. The analysis therefore works on the network itself: a deterministic critical path, resource leveling, and a Monte Carlo schedule risk analysis that reschedules the network in every iteration. A causal risk network then replaces independent risk events with risks that share a root cause and act through the resources every activity depends on. Comparing the traditional analysis with the network’s observational, conditional and interventional queries shows what the causal structure adds.
The schedule has six work packages, with durations in weeks:
bp <- building_project
bp$schedule_activities
#> id name duration fixed_cost
#> 1 T1 Site Preparation & Earthworks 6 200000
#> 2 T2 Foundations 8 600000
#> 3 T3 Structural Frame 16 1600000
#> 4 T4 Building Envelope 11 1100000
#> 5 T5 Mechanical/Electrical/Plumbing 14 1200000
#> 6 T6 Interior Fit-out & Finishes NA 500000
bp$schedule_links
#> source target type lag
#> 1 T1 T2 FS 0
#> 2 T2 T3 FS 0
#> 3 T3 T4 SS 8
#> 4 T3 T4 FF 2
#> 5 T4 T5 SS 4
#> 6 T4 T6 FS 0
#> 7 T5 T6 SS 6
#> 8 T5 T6 FF 4The envelope (T4) starts 8 weeks into the structural frame (start-to-start) and finishes at least 2 weeks after it (finish-to-finish). MEP rough-in starts 4 weeks into the envelope. Fit-out follows envelope dry-in and must finish at least 4 weeks after MEP. Fit-out has no fixed duration: it is 24 crew-weeks of work by two finishing crews, so its duration depends on crew productivity.
bp$schedule_resources
#> id capacity rate
#> 1 Excavation crew 1 18000
#> 2 Concrete crew 1 22000
#> 3 Steel erector 1 30000
#> 4 Tower crane 1 12000
#> 5 MEP subcontractor 2 35000
#> 6 Finishing crew 3 20000
bp$schedule_assignments
#> activity resource units work
#> 1 T1 Excavation crew 1 NA
#> 2 T2 Excavation crew 1 NA
#> 3 T2 Concrete crew 1 NA
#> 4 T3 Concrete crew 1 NA
#> 5 T3 Steel erector 1 NA
#> 6 T3 Tower crane 1 NA
#> 7 T2 Tower crane 1 NA
#> 8 T4 Tower crane 1 NA
#> 9 T4 MEP subcontractor 1 NA
#> 10 T5 MEP subcontractor 1 NA
#> 11 T5 Finishing crew 1 NA
#> 12 T6 Finishing crew 2 24A single tower crane serves the foundations, frame and envelope. Each resource has a cost per unit per week, and each activity can carry a fixed cost for materials and lump sums.
The schedule model combines the network with the uncertainty: a duration distribution for each estimated activity, a productivity distribution for the finishing crews, a correlation matrix across the five estimated durations, and the risk register.
proj <- project_schedule(
activities = bp$schedule_activities,
links = bp$schedule_links,
duration_dists = bp$duration_dists,
resources = bp$schedule_resources,
productivity_dists = bp$productivity_dists,
assignments = bp$schedule_assignments,
risks = bp$risk_register,
cor_mat = bp$cor_mat[1:5, 1:5],
start_date = bp$start_date,
time_unit = "weeks"
)
proj
#> Project Schedule
#> Activities: 6 Links: 8 Resources: 6 Risks: 2
#> Time unit: weeks Start: 2027-03-01
#>
#> id name duration driver predecessors
#> T1 Site Preparation & Earthworks 6 distribution
#> T2 Foundations 8 distribution T1
#> T3 Structural Frame 16 distribution T2
#> T4 Building Envelope 11 distribution T3SS+8, T3FF+2
#> T5 Mechanical/Electrical/Plumbing 14 distribution T4SS+4
#> T6 Interior Fit-out & Finishes 12 resource T4, T5SS+6, T5FF+4Activity-on-node network. Red marks the deterministic critical path; edge labels give non-FS link types and lags.
plan <- cpm(proj)
plan
#> Critical Path Method
#> Project finish: 45 weeks
#> Critical path: T1 -> T2 -> T3 -> T4 -> T6
#>
#> id duration ES EF LS LF total_float free_float critical
#> T1 6 0 6 0 6 0 0 TRUE
#> T2 8 6 14 6 14 0 0 TRUE
#> T3 16 14 30 14 30 0 0 TRUE
#> T4 11 22 33 22 33 0 0 TRUE
#> T5 14 26 40 27 41 1 1 FALSE
#> T6 12 33 45 33 45 0 0 TRUEThe critical path method (Kelley and Walker, 1959) makes two passes through the network. The forward pass gives each activity’s early start: the latest of zero and the constraint of each incoming link. A finish-to-start (FS) link gives predecessor finish + lag, start-to-start (SS) gives predecessor start + lag, finish-to-finish (FF) gives predecessor finish + lag − duration, and start-to-finish (SF) gives predecessor start + lag − duration. The backward pass mirrors this from the project finish to give late starts. Total float is late start minus early start, and activities with zero total float form the critical path. Free float is the slip an activity can absorb before it delays any successor.
Deterministic schedule. Grey bars show total float; the dashed line is the project finish.
The critical path plan overlaps the envelope with the frame, but both need the one crane. Resource leveling resolves the conflict with a serial schedule-generation scheme (Kolisch, 1996). It repeatedly takes the eligible activity with the smallest late start and places it at the earliest time that satisfies its links and keeps every resource within capacity for the activity’s whole duration.
Resource-leveled schedule: the envelope waits for the crane.
The crane conflict costs eight weeks. Once resources move dates, float no longer identifies the critical activities. Criticality instead comes from the driving path, traced back from the finish through binding links and through resource hand-offs.
Schedule risk analysis repeats the leveled schedule calculation many times. In each iteration it samples correlated activity durations, crew productivity and risk events, then reschedules the network with the crane constraint in force:
set.seed(2027)
risk <- sra(proj, num_sims = n_lev, level = TRUE)
risk
#> Schedule Risk Analysis (resource-leveled)
#> Iterations: 500
#> Deterministic finish: 53 weeks (P11)
#> Mean finish: 59.5 weeks SD: 5.374
#> Finish percentiles:
#> 10% 50% 80% 90%
#> 52.75 59.34 64.27 66.38
#> Cost percentiles:
#> 10% 50% 80% 90%
#> 8450000 8928000 9379000 9561000
#> Most critical activities:
#> id criticality cruciality
#> T1 1 0.644
#> T2 1 0.664
#> T3 1 0.686
#> T4 1 0.588
#> T6 1 0.124Project finish: histogram and cumulative probability.
The leveled deterministic plan sits low on the cumulative curve. The gap reflects merge bias, correlated and right-skewed durations, uncertain crew productivity and the two risk events. Schedule contingency is the gap between a high-confidence finish (P80) and the median (P50):
summary(risk)$activities
#> id mean_duration mean_finish finish_p90 criticality sensitivity cruciality
#> 3 T3 17.238496 34.271964 39.761306 1.000 0.6861565 0.6861565
#> 2 T2 9.535597 17.033468 21.219490 1.000 0.6639660 0.6639660
#> 1 T1 7.497872 7.497872 9.644654 1.000 0.6438782 0.6438782
#> 4 T4 12.467529 46.739494 53.672538 1.000 0.5884851 0.5884851
#> 5 T5 15.513377 53.785342 60.943024 0.324 0.5132641 0.1662976
#> 6 T6 12.348124 59.501836 66.379881 1.000 0.1235906 0.1235906
#> ssi
#> 3 0.4548036
#> 2 0.3314006
#> 1 0.3087281
#> 4 0.4008866
#> 5 0.1524601
#> 6 0.1484243Deterministic bars shaded by criticality index, with P10-P90 finish whiskers and P50 ticks.
Activities ranked by cruciality.
Network shaded by criticality index.
Each risk in the register occurs independently in each iteration with its stated probability. When it occurs, a sampled delay is added to every activity it affects, and its cost impact is added to project cost.
risk$risk_stats
#> id prob occurrence finish_impact cost_impact rank
#> 1 Adverse weather 0.35 0.358 5.066005 309547.6 1
#> 2 Late design changes 0.25 0.242 4.072130 657193.9 2A risk’s finish impact is the mean finish in iterations where it occurred minus the mean where it did not. Its cost impact is the same difference in total cost, so it includes the extra resource cost of the delay as well as the risk’s own cost. These impacts rank where risk responses pay off most:
Risk events ranked by mean finish impact.
A causal network answers three different kinds of question about the project finish or cost, Y (Pearl, 2009):
A traditional analysis has no such distinction. It is either deterministic (the leveled critical path) or a simulation in which every risk is an independent register entry. To compare like with like, the independent version below keeps the labor shortage and supply-chain pressure at their overall probabilities (0.41 and 0.34) but drops the boom that links them. The causal queries ask what securing labor is worth: conditioning on no labor shortage, against intervening to prevent one.
discrete <- function(p) list(type = "discrete", values = c(1, 0),
probs = c(p, 1 - p))
# Traditional: the same two risks, independent, at their overall probabilities.
indep_net <- prob_net(
data.frame(id = c("Labor", "Supply")),
data.frame(source = character(), target = character()),
list(Labor = discrete(0.4 * 0.8 + 0.6 * 0.15),
Supply = discrete(0.4 * 0.7 + 0.6 * 0.1))
)
# Intervention: cut the arc from the boom into a node and fix its value.
do_net <- function(node, value) {
prob_net_update(boom_net,
remove_links = data.frame(source = "Boom", target = node),
update_distributions = setNames(list(discrete(value)), node)
)
}
run <- function(net) {
set.seed(2027)
sra(with_net(net), num_sims = n_sims, level = TRUE, keep_samples = TRUE)
}
indep <- run(indep_net)
do_labor <- run(do_net("Labor", 0))
# Conditioning: keep the iterations with no labor shortage.
draws <- risk_boom$samples$risk_net
no_labor <- draws$Labor == 0
query <- function(finish, cost) {
c(finish_mean = mean(finish),
finish_P80 = unname(quantile(finish, 0.8)),
cost_mean = mean(cost) / 1e6,
cost_P80 = unname(quantile(cost, 0.8)) / 1e6)
}
round(rbind(
"Deterministic (leveled CPM)" =
c(leveled$finish, leveled$finish, leveled$cost / 1e6, leveled$cost / 1e6),
"Simulation, independent risks" =
query(indep$total_distribution, indep$cost_distribution),
"Observational P(Y)" =
query(risk_boom$total_distribution, risk_boom$cost_distribution),
"Seeing P(Y | Labor = 0)" =
query(risk_boom$total_distribution[no_labor],
risk_boom$cost_distribution[no_labor]),
"Doing P(Y | do(Labor = 0))" =
query(do_labor$total_distribution, do_labor$cost_distribution)
), 2)
#> finish_mean finish_P80 cost_mean cost_P80
#> Deterministic (leveled CPM) 53.00 53.00 8.52 8.52
#> Simulation, independent risks 61.21 66.10 9.18 9.57
#> Observational P(Y) 61.23 66.29 9.18 9.59
#> Seeing P(Y | Labor = 0) 59.56 63.93 9.01 9.34
#> Doing P(Y | do(Labor = 0)) 59.49 63.98 9.03 9.38Costs are in millions.
Project finish under the traditional analyses and the causal queries. Curves that coincide are drawn wide underneath and narrow on top.
Three points stand out.
The gap is clearest when the risks are ranked. The ranking statistics used earlier compare iterations where a risk occurred with those where it did not, which is a conditional (seeing) comparison. The interventional effect of supply pressure compares runs with the risk forced on and forced off:
do_on <- run(do_net("Supply", 1))
do_off <- run(do_net("Supply", 0))
supply <- function(stats) {
unlist(stats[stats$id == "Supply", c("finish_impact", "cost_impact")])
}
effect <- rbind(
"Traditional (independent risks)" = supply(indep$risk_net_stats),
"Seeing (causal network)" = supply(risk_boom$risk_net_stats),
"Doing (causal network)" =
c(do_on$total_mean - do_off$total_mean,
mean(do_on$cost_distribution) - mean(do_off$cost_distribution))
)
effect[, "cost_impact"] <- effect[, "cost_impact"] / 1e6
round(effect, 2)
#> finish_impact cost_impact
#> Traditional (independent risks) 0.16 0.24
#> Seeing (causal network) 1.81 0.36
#> Doing (causal network) 0.00 0.22Effect of supply-chain pressure on the finish and on cost, by type of analysis.
Supply pressure only raises cost rates, so it cannot delay the finish. Seeing nonetheless credits it with a delay of about 1.8 weeks, borrowed from the labor shortage through their shared cause, and overstates its cost impact for the same reason. Doing gives the true effect: no delay, and only the extra cost of the concrete and steel crews. The independent model shows no systematic delay either (what remains is sampling noise), but only because it assumes the shared cause away. It cannot represent the boom at all, so it cannot say what insulating the project from it would be worth. Risk responses should be ranked by interventional effects, which only a causal model can supply.
Each activity’s cost is its resource cost (units × rate × duration) plus fixed cost plus its share of risk costs. It is spread over the activity’s dates in each iteration and accumulated into a cost S-curve band:
Cumulative cost: P50 line and P10-P90 band.
Resource usage is summarized the same way. With leveling, no iteration exceeds capacity:
Resource usage against capacity.
Repeating the analysis without leveling prices the resource constraint in probabilistic terms:
set.seed(2027)
free <- sra(proj, num_sims = n_sims)
rbind(
unconstrained = free$percentiles,
leveled = risk$percentiles
)
#> 10% 50% 80% 90%
#> unconstrained 45.66267 50.41643 54.20293 56.00787
#> leveled 52.74782 59.33911 64.26586 66.37988With a single crane, the P80 finish moves from 54.2 to 64.3 weeks. That is the figure to weigh against the cost of a second crane.
Kelley, J. E., and Walker, M. R. (1959). Critical-path planning and scheduling. Proceedings of the Eastern Joint Computer Conference, 160–173.
Kolisch, R. (1996). Serial and parallel resource-constrained project scheduling methods revisited: Theory and computation. European Journal of Operational Research, 90(2), 320–333.
Pearl, J. (2009). Causality: Models, Reasoning, and Inference (2nd ed.). Cambridge University Press.
Project Management Institute (2009). Practice Standard for Project Risk Management. PMI.
Williams, T. M. (1992). Criticality in stochastic networks. Journal of the Operational Research Society, 43(4), 353–357.