1%% Probabilistic Branching Workflow Example (OR-fork/join)
2% A workflow with probabilistic choice between branches.
9% Copyright (c) 2012-2026, Imperial College London
16wf = Workflow(
'BranchingWorkflow');
19A = wf.addActivity(
'A', Exp.fitMean(1.0));
20B = wf.addActivity(
'B', Exp.fitMean(2.0));
21C = wf.addActivity(
'C', Exp.fitMean(5.0));
22D = wf.addActivity(
'D', Exp.fitMean(0.5));
24% Define precedences with probabilities
25wf.addPrecedence(Workflow.OrFork(A, {B, C}, [0.6, 0.4]));
26wf.addPrecedence(Workflow.OrJoin({B, C}, D));
28%% Convert to phase-type distribution
32fprintf(
'Branching Workflow: A -> [B(60%%) | C(40%%)] -> D\n');
33fprintf(
'Activity means: A=1.0, B=2.0, C=5.0, D=0.5\n');
34expected_branch = 0.6 * 2.0 + 0.4 * 5.0;
35fprintf(
'Expected branch mean: 0.6*2.0 + 0.4*5.0 = %.2f\n', expected_branch);
36fprintf(
'Expected total mean: %.2f\n', 1.0 + expected_branch + 0.5);
37fprintf(
'Computed PH mean: %.4f\n', ph.getMean());
38fprintf(
'Number of phases: %d\n', size(ph.getSubgenerator(), 1));