LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
refreshChains.m
1function [chains, visits, rt, nodevisits, rtnodes] = refreshChains(self, propagate)
2% [CHAINS, VISITS, RT, NODEVISITS, RTNODES] = REFRESHCHAINS(PROPAGATE)
3%
4% PROPAGATE : true if the change needs to trigger recomputation of visits and station capacities (default: true)
5
6% Copyright (c) 2012-2026, Imperial College London
7% All rights reserved.
8
9if nargin<2 || nargin<3
10 propagate = true;
11end
12
13%% obtain routing matrix
14sn = self.sn;
15rates = sn.rates;
16[rt,~,rtnodes] = self.refreshRoutingMatrix(rates);
17sn = self.sn;
18
19%% determine class switching mask
20stateful = find(sn.isstateful); stateful = stateful(:)';
21K = sn.nclasses;
22if isempty(self.csMatrix) % only for models created without a call to link()
23 csmask = false(K,K);
24 for r=1:K
25 for s=1:K
26 for isf=1:length(stateful) % source
27 for jsf=1:length(stateful) % source
28 if rt((isf-1)*K+r, (jsf-1)*K+s) > 0
29 % this is to ensure that we use rt, which is
30 % the stochastic complement taken over the stateful
31 % nodes, otherwise sequences of cs can produce a wrong
32 % csmask
33 csmask(r,s) = true;
34 end
35 end
36 end
37 end
38 end
39
40 for isf=1:length(stateful) % source
41 % this is to ensure that also stateful cs like caches
42 % are accounted
43 ind = sn.statefulToNode(isf);
44 isCS = sn.nodetype(ind) == NodeType.Cache | sn.nodetype(ind) == NodeType.ClassSwitch;
45 for r=1:K
46 csmask(r,r) = true;
47 for s=1:K
48 if r~=s
49 if isCS
50 if self.nodes{ind}.server.csFun(r,s,[],[])>0
51 csmask(r,s) = true;
52 end
53 end
54 end
55 end
56 end
57 end
58 sn.csmask = csmask;
59else
60 % Start with csMatrix from link(), but also include any transitions
61 % that may have been created by stochastic complement through
62 % non-stateful nodes (e.g., auto-added ClassSwitch nodes)
63 csmask = self.csMatrix;
64 for r=1:K
65 for s=1:K
66 for isf=1:length(stateful)
67 for jsf=1:length(stateful)
68 if rt((isf-1)*K+r, (jsf-1)*K+s) > 0
69 csmask(r,s) = true;
70 end
71 end
72 end
73 end
74 end
75 sn.csmask = csmask;
76end
77
78if isfield(sn,'refclass') && length(sn.refclass)<sn.nchains
79 % if the number of chains changed dynamically, extend refclass
80 sn.refclass(end+1:sn.nchains) = 0;
81end
82
83self.sn = sn;
84
85%% compute visits
86if propagate
87 [visits, nodevisits, sn] = sn_refresh_visits(sn, sn.chains, rt, rtnodes);
88end
89
90self.sn = sn;
91
92%% call dependent capacity refresh
93if propagate
94 refreshCapacity(self); % capacity depends on chains and rates
95end
96
97end