LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
qsys_geoxgeo1.m
1function result = qsys_geoxgeo1(a, beta, s, convention)
2% QSYS_GEOXGEO1 Exact analysis of a discrete-time Geo^X/Geo/1 batch queue.
3%
4% RESULT = QSYS_GEOXGEO1(A, BETA, S) analyzes a slotted single-server queue
5% with batch arrivals:
6% A - per-slot probability that a batch arrives (0 < A <= 1)
7% BETA - batch-size geometric parameter; the batch is supported on
8% {1,2,...} with mean 1/BETA (0 < BETA <= 1)
9% S - per-slot service completion probability (0 < S <= 1)
10% Stability requires LAMBDA = A/BETA < S.
11%
12% RESULT = QSYS_GEOXGEO1(A, BETA, S, CONVENTION) selects the observation
13% epoch, 'LAS_DA' (default) or 'EAS'; see QSYS_GEOGEO1 for what they mean.
14%
15% With A(z) = 1-A+A*X(z) the pgf of the number of jobs arriving in one slot,
16% the slot-boundary content obeys X(t+1) = X(t) - D(t) + A(t) with the
17% departure resolved first, giving
18% P(z) = p_0 S (z-1) A(z) / ( z - A(z)(S+(1-S)z) ), p_0 = 1 - LAMBDA/S
19% and, on differentiating at z = 1,
20% E[N] = LAMBDA + ( A E[X(X-1)]/2 + LAMBDA(1-S) ) / (S - LAMBDA)
21% The batch enters only through its first two factorial moments. For the
22% geometric batch, E[X] = 1/BETA and E[X(X-1)] = 2(1-BETA)/BETA^2. At BETA = 1
23% the batch is always a single job and the result equals QSYS_GEOGEO1.
24%
25% Returns a struct with fields:
26% convention - Observation epoch used, 'LAS_DA' or 'EAS'
27% batchArrivalProb - Per-slot probability that a batch arrives, A
28% batchMean - Mean batch size E[X]
29% batchSecondFactorialMoment - E[X(X-1)]
30% serviceProb - Per-slot service completion probability S
31% arrivalRate - Jobs arriving per slot, LAMBDA = A E[X]
32% throughput - Departures per slot, LAMBDA
33% utilization - Fraction of slots with the server serving, LAMBDA/S
34% boundaryEmptyProb - Empty probability AT THE SLOT BOUNDARY, 1 - LAMBDA/S
35% meanQueueLength - Mean number of jobs in the system
36% meanWaitingQueue - Mean number of jobs waiting, i.e. not in service
37% meanSojournTime - Mean sojourn time in slots, per job (not per batch)
38% meanWaitingTime - Mean waiting time in slots, per job
39% meanServiceTime - Mean service time, 1/S under LAS_DA, (1-S)/S under EAS
40% pgf - Function handle P(z, Az) taking the slot-arrival pgf
41% value A(z) at the same z; defined for 0 < z <= 1
42% analyzer - Identifier string
43%
44% No pmf is returned: for a general batch law the stationary distribution has
45% no elementary closed form, so only the generating function is exact.
46% Likewise BOUNDARYEMPTYPROB is deliberately epoch independent; the empty
47% probability at the EAS epoch is p_0 + S p_1 and has no elementary form.
48%
49% Examples:
50% r = qsys_geoxgeo1(0.1, 0.5, 0.9); % lambda = 0.2
51% r.arrivalRate % 0.2
52% r.meanQueueLength % 0.5143
53%
54% Reference: H. Daduna, Queueing Networks with Discrete Time Scale, LNCS 2046,
55% Springer 2001, chapter 6 for the discrete-time batch framework; the
56% single-node pgf above is the standard discrete-time M/G/1-type derivation.
57%
58% See also QSYS_GEOGEO1, QSYS_MXM1
59%
60% Copyright (c) 2012-2026, Imperial College London
61% All rights reserved.
62
63if nargin < 4 || isempty(convention)
64 convention = 'LAS_DA';
65end
66if ~isnumeric(beta) || ~isscalar(beta) || ~isreal(beta) || beta <= 0 || beta > 1
67 line_error(mfilename, 'beta must be a real scalar in (0,1]');
68end
69batchMean = 1 / beta;
70batchSecondFactorial = 2 * (1 - beta) / (beta ^ 2);
71result = qsys_geoxgeo1_moments(a, batchMean, batchSecondFactorial, s, convention);
72end
73
74function result = qsys_geoxgeo1_moments(a, batchMean, batchSecondFactorial, s, convention)
75% Geo^X/Geo/1 for an arbitrary batch law given by its first two factorial
76% moments. Kept local because the geometric form above is the documented
77% entry point; call QSYS_GEOXGEO1 with the matching beta for other laws, or
78% lift this to its own file if a non-geometric batch is needed directly.
79
80if ~ischar(convention) && ~isstring(convention)
81 line_error('qsys_geoxgeo1', 'convention must be the string ''LAS_DA'' or ''EAS''');
82end
83convention = upper(char(convention));
84if ~strcmp(convention, 'LAS_DA') && ~strcmp(convention, 'EAS')
85 line_error('qsys_geoxgeo1', 'convention must be ''LAS_DA'' or ''EAS''');
86end
87if ~isnumeric(a) || ~isscalar(a) || ~isreal(a) || a <= 0 || a > 1
88 line_error('qsys_geoxgeo1', 'a must be a real scalar in (0,1]');
89end
90if ~isnumeric(s) || ~isscalar(s) || ~isreal(s) || s <= 0 || s > 1
91 line_error('qsys_geoxgeo1', 's must be a real scalar in (0,1]');
92end
93if batchMean < 1
94 line_error('qsys_geoxgeo1', 'mean batch size must be at least 1: a batch that arrives carries at least one job');
95end
96if batchSecondFactorial < 0
97 line_error('qsys_geoxgeo1', 'E[X(X-1)] must be non-negative');
98end
99% E[X^2] = E[X(X-1)] + E[X] >= E[X]^2, so a smaller second factorial moment
100% describes no random variable at all.
101minSecondFactorial = batchMean ^ 2 - batchMean;
102if batchSecondFactorial < minSecondFactorial - 1e-9 * max(1, minSecondFactorial)
103 line_error('qsys_geoxgeo1', 'E[X(X-1)] is below E[X]^2-E[X], so the batch moments describe no random variable');
104end
105
106lambda = a * batchMean;
107if lambda >= s
108 line_error('qsys_geoxgeo1', 'load lambda/s must be strictly less than 1');
109end
110
111rho = lambda / s;
112boundaryEmptyProb = 1 - rho;
113
114% P'(1) from the generating function.
115meanAtBoundary = lambda + (a * batchSecondFactorial / 2 + lambda * (1 - s)) / (s - lambda);
116
117meanSojournAtBoundary = meanAtBoundary / lambda;
118meanWaitingTime = meanSojournAtBoundary - 1 / s;
119meanWaitingQueue = lambda * meanWaitingTime;
120
121if strcmp(convention, 'LAS_DA')
122 meanQueueLength = meanAtBoundary;
123 meanSojournTime = meanSojournAtBoundary;
124 meanServiceTime = 1 / s;
125else
126 % One departure earlier: the epoch drops exactly the departures of the
127 % slot, whose rate is lambda, hence one slot of sojourn.
128 meanQueueLength = meanAtBoundary - lambda;
129 meanSojournTime = meanSojournAtBoundary - 1;
130 meanServiceTime = (1 - s) / s;
131end
132
133result = struct();
134result.convention = convention;
135result.batchArrivalProb = a;
136result.batchMean = batchMean;
137result.batchSecondFactorialMoment = batchSecondFactorial;
138result.serviceProb = s;
139result.arrivalRate = lambda;
140result.throughput = lambda;
141result.utilization = rho;
142result.boundaryEmptyProb = boundaryEmptyProb;
143result.meanQueueLength = meanQueueLength;
144result.meanWaitingQueue = meanWaitingQueue;
145result.meanSojournTime = meanSojournTime;
146result.meanWaitingTime = meanWaitingTime;
147result.meanServiceTime = meanServiceTime;
148result.pgf = @(z, Az) geoxgeo1_pgf(z, Az, s, boundaryEmptyProb, convention);
149result.analyzer = 'qsys_geoxgeo1';
150end
151
152function Pz = geoxgeo1_pgf(z, Az, s, p0, convention)
153if ~isnumeric(z) || ~isscalar(z) || ~isreal(z) || z <= 0 || z > 1
154 line_error('qsys_geoxgeo1', 'pgf argument z must lie in (0,1]');
155end
156if z == 1
157 Pz = 1;
158 return
159end
160denom = z - Az * (s + (1 - s) * z);
161boundary = p0 * s * (z - 1) * Az / denom;
162if strcmp(convention, 'LAS_DA')
163 Pz = boundary;
164else
165 Pz = boundary * (s / z + 1 - s) + p0 * s * (1 - 1 / z);
166end
167end
Definition Station.m:245