1% Finds all the paths coming out of start, computes the total response time along them, and identifies all the stations along these paths
2function [ri, stat, RN] = paths(sn,
P, curNode, endNode, r, RN, currentTime, stats)
11 if ~isnan(sn.nodeToStation(curNode))
12 currentRn = RN(sn.nodeToStation(curNode), r);
13 stats(end + 1) = sn.nodeToStation(curNode);
15 for nextNode=find(
P(curNode, :))
16 if sn.nodetype(nextNode) == NodeType.Fork & ~isempty(find(sn.fj(nextNode,:)))
17 % Encountered nested fork, compute the max along the parallel paths
18 joinIdx = find(sn.fj(nextNode,:));
19 if RN(sn.nodeToStation(joinIdx), r) == 0
20 [ri1, stat1, RN] = paths(sn,
P, nextNode, joinIdx, r, RN, 0, []);
23 parallel_branches = length(ri1);
24 for pow=0:(parallel_branches - 1)
25 current_sum = sum(1./sum(nchoosek(lambdai, pow + 1),2));
26 d0 = d0 + (-1)^pow * current_sum;
28 RN(sn.nodeToStation(joinIdx), r) = d0;
31 [ri1, stat1, RN] = paths(sn,
P, joinIdx, endNode, r, RN, currentTime + currentRn, stats);
33 [ri1, stat1, RN] = paths(sn,
P, nextNode, endNode, r, RN, currentTime + currentRn, stats);