LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
sn_set_service_coc.m
1function sn = sn_set_service_coc(sn, stationIdx, classIdx, rate, scv)
2% SN_SET_SERVICE_COC Update service rate preserving cell-of-cells format.
3%
4% Works like sn_set_service with autoRefresh=true, but writes mu, phi,
5% proc, pie using cell-of-cells indexing (sn.mu{i}{k}) instead of 2D
6% cell indexing (sn.mu{i,k}). This avoids reshaping the cell arrays,
7% which would break solvers that expect cell-of-cells format.
8%
9% Inputs:
10% sn - NetworkStruct
11% stationIdx - station index (1-based)
12% classIdx - class index (1-based)
13% rate - new service rate (positive scalar)
14% scv - squared coefficient of variation (default 1.0)
15%
16% Copyright (c) 2012-2026, Imperial College London
17% All rights reserved.
18% This code is released under the 3-Clause BSD License.
19
20if nargin < 5 || isempty(scv)
21 scv = 1.0;
22end
23
24% Update rates and scv matrices
25sn.rates(stationIdx, classIdx) = rate;
26sn.scv(stationIdx, classIdx) = scv;
27
28% Skip if rate is invalid
29if isnan(rate) || rate <= 0 || isinf(rate)
30 return;
31end
32
33meanVal = 1.0 / rate;
34
35% Determine process type and create MAP based on SCV
36if isnan(scv) || abs(scv - 1.0) < 1e-10
37 MAP = map_exponential(meanVal);
38 nPhases = 1;
39 procType = ProcessType.EXP;
40elseif scv < 1.0
41 k = max(1, ceil(1.0 / scv));
42 MAP = map_erlang(meanVal, k);
43 nPhases = k;
44 procType = ProcessType.ERLANG;
45else
46 MAP = map_hyperexp(meanVal, scv);
47 if ~isempty(MAP)
48 nPhases = 2;
49 procType = ProcessType.HYPEREXP;
50 else
51 MAP = map_exponential(meanVal);
52 nPhases = 1;
53 procType = ProcessType.EXP;
54 end
55end
56
57D0 = MAP{1};
58D1 = MAP{2};
59
60% Update in cell-of-cells format
61sn.proc{stationIdx}{classIdx} = MAP;
62sn.procid(stationIdx, classIdx) = procType;
63sn.phases(stationIdx, classIdx) = nPhases;
64sn.phasessz(stationIdx, classIdx) = max(nPhases, 1);
65
66% Recompute phaseshift for this station
67cumSum = 0;
68sn.phaseshift(stationIdx, 1) = 0;
69for c = 1:sn.nclasses
70 cumSum = cumSum + sn.phasessz(stationIdx, c);
71 if c + 1 <= size(sn.phaseshift, 2)
72 sn.phaseshift(stationIdx, c + 1) = cumSum;
73 end
74end
75
76% Update mu (rates from -diag(D0))
77sn.mu{stationIdx}{classIdx} = -diag(D0);
78
79% Update phi (completion probabilities)
80phiVec = zeros(nPhases, 1);
81for i = 1:nPhases
82 d1RowSum = sum(D1(i, :));
83 d0Diag = -D0(i, i);
84 if d0Diag ~= 0
85 phiVec(i) = d1RowSum / d0Diag;
86 end
87end
88sn.phi{stationIdx}{classIdx} = phiVec;
89
90% Update pie (initial phase distribution)
91sn.pie{stationIdx}{classIdx} = map_pie(MAP);
92
93end