1function [Q,U,R,T,C,X,lG] = solver_nc_lcfsqn(sn, options, lcfsStat, lcfsprStat)
2% [Q,U,R,T,C,X,LG] = SOLVER_NC_LCFSQN(SN, OPTIONS, LCFSSTAT, LCFSPRSTAT)
3% Specialized NC solver
for LCFS + LCFS-PR 2-station networks
5% This function wraps the pfqn_lcfsqn_ca algorithm and computes performance
6% metrics
using the convolution approach.
9% sn - network structure
10% options - solver options
11% lcfsStat - index of the LCFS station
12% lcfsprStat - index of the LCFS-PR station
15% Q - queue length matrix (stations x
classes)
16% U - utilization matrix (stations x
classes)
17% R - response time matrix (stations x
classes)
18% T - throughput matrix (stations x
classes)
19% C - cycle time vector (1 x
classes)
20% X - throughput vector (1 x
classes)
21% lG - log of normalizing constant
23% Copyright (c) 2012-2026, Imperial College London
30% Extract service times
for each class at each station
31% alpha(r) = mean service time at LCFS station
for class r
32% beta(r) = mean service time at LCFS-PR station
for class r
39 % Service rate at station
for class r
40 mu_lcfs = rates(lcfsStat, r);
41 mu_lcfspr = rates(lcfsprStat, r);
43 if mu_lcfs <= 0 || ~isfinite(mu_lcfs)
44 line_error(mfilename, sprintf(
'Invalid service rate at LCFS station for class %d.', r));
46 if mu_lcfspr <= 0 || ~isfinite(mu_lcfspr)
47 line_error(mfilename, sprintf(
'Invalid service rate at LCFS-PR station for class %d.', r));
50 alpha(r) = 1 / mu_lcfs;
51 beta(r) = 1 / mu_lcfspr;
55% Get population vector
59% Call the LCFS convolution algorithm to get normalizing constant
60[G, ~] = pfqn_lcfsqn_ca(alpha, beta, N);
62% Compute log normalizing constant
69% Initialize output matrices
74% Compute throughputs and queue lengths
for each class
75% Based on the approach in lcfsqn_perf.m
78 % Compute throughput
using permanent calculations
80 Tx = make_Tx(alpha, beta, xt, K, R, r);
82 T_lcfs(1:2,r) = T_lcfs(1:2,r) + alpha(r)^(xt-1) * permT / G;
84 % Compute queue length at station 1 (LCFS)
85 Yx = make_Yx(alpha, beta, xt, K, R, r);
87 Q_lcfs(1,r) = Q_lcfs(1,r) + permY/G;
89 % Queue length at station 2 (LCFS-PR) by conservation
90 Q_lcfs(2,r) = njobs(r) - Q_lcfs(1,r);
98 U_lcfs(i,r) = T_lcfs(i,r) * alpha(r);
100 U_lcfs(i,r) = T_lcfs(i,r) * beta(r);
105% Map results back to LINE format
106% Initialize output matrices
for all stations
115Q(lcfsStat, :) = Q_lcfs(1, :);
116Q(lcfsprStat, :) = Q_lcfs(2, :);
119U(lcfsStat, :) = U_lcfs(1, :);
120U(lcfsprStat, :) = U_lcfs(2, :);
122% Throughput
is the same at all stations in a closed network
126 T(lcfsStat, r) = T_lcfs(1,r);
127 T(lcfsprStat, r) = T_lcfs(2,r);
131% Compute response times: R = Q / T (
using Little
's Law)
132for k = [lcfsStat, lcfsprStat]
135 R_resp(k, r) = Q(k, r) / T(k, r);
140% Compute cycle times: C = sum of response times at all stations
143 C(r) = R_resp(lcfsStat, r) + R_resp(lcfsprStat, r);
147% Return R_resp in variable R (overriding function parameter)
152function Tx = make_Tx(alpha, beta, xt, K, R, r)
153% Make Tx matrix for throughput computation
154% alpha : vector of length R
155% beta : vector of length R
157% K : total population
158% R : number of classes
159% r : class index to exclude
162 Tx = sym(zeros(K-1, K-1));
164 Tx = zeros(K-1, K-1);
172 Tx(idx, j) = alpha(i)^j;
175 Tx(idx, xt-1+j) = alpha(i)^(xt+j-1) * beta(i);
181function Y = make_Yx(alpha, beta, xt, K, R, r)
182% Make Yx matrix for queue length computation
183% alpha : vector of length R
184% beta : vector of length R
186% K : total population
187% R : number of classes
191 Y = sym(zeros(K, K));
198 Y(i, j) = alpha(i)^j;
202 Y(i, xt+j) = alpha(i)^(xt+j-1) * beta(i);