LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
paths.m
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)
3 if curNode == endNode
4 ri = currentTime;
5 stat = stats;
6 return
7 end
8 ri = [];
9 stat = [];
10 currentRn = 0;
11 if ~isnan(sn.nodeToStation(curNode))
12 currentRn = RN(sn.nodeToStation(curNode), r);
13 stats(end + 1) = sn.nodeToStation(curNode);
14 end
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, []);
21 lambdai = 1./ri1;
22 d0 = 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;
27 end
28 RN(sn.nodeToStation(joinIdx), r) = d0;
29 RN(stat1, r) = 0;
30 end
31 [ri1, stat1, RN] = paths(sn, P, joinIdx, endNode, r, RN, currentTime + currentRn, stats);
32 else
33 [ri1, stat1, RN] = paths(sn, P, nextNode, endNode, r, RN, currentTime + currentRn, stats);
34 end
35 ri = [ri, ri1];
36 stat = [stat, stat1];
37 end
38end