LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
pathsCS.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] = pathsCS(sn, orignodes, P, curNode, endNode, curClass, 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), curClass);
13 stats(end + 1) = sn.nodeToStation(curNode);
14 end
15 for transition=find(P((curClass-1)*orignodes+curNode, :))
16 nextClass = floor((transition - 1) / orignodes) + 1;
17 nextNode = transition-(nextClass-1) * orignodes; % new class
18 if sn.nodetype(nextNode) == NodeType.Fork & ~isempty(find(sn.fj(nextNode,:)))
19 % Encountered nested fork, compute the max along the parallel paths
20 joinIdx = find(sn.fj(nextNode,:));
21 if RN(sn.nodeToStation(joinIdx), nextClass) == 0
22 [ri1, stat1, RN] = pathsCS(sn, P, nextNode, joinIdx, nextClass, RN, 0, []);
23 lambdai = 1./ri1;
24 d0 = 0;
25 parallel_branches = length(ri1);
26 for pow=0:(parallel_branches - 1)
27 current_sum = sum(1./sum(nchoosek(lambdai, pow + 1),2));
28 d0 = d0 + (-1)^pow * current_sum;
29 end
30 RN(sn.nodeToStation(joinIdx), nextClass) = d0;
31 RN(stat1, nextClass) = 0;
32 end
33 [ri1, stat1, RN] = pathsCS(sn, orignodes, P, joinIdx, endNode, nextClass, RN, currentTime + currentRn, stats);
34 else
35 [ri1, stat1, RN] = pathsCS(sn, orignodes, P, nextNode, endNode, nextClass, RN, currentTime + currentRn, stats);
36 end
37 ri = [ri, ri1];
38 stat = [stat, stat1];
39 end
40end