1function result = qsys_mapmap1(C0, C1, D0, D1, varargin)
2% QSYS_MAPMAP1 Analyzes a MAP/MAP/1 queue
using BUTools MMAPPH1FCFS.
4% RESULT = QSYS_MAPMAP1(C0, C1, D0, D1) analyzes a MAP/MAP/1 queue with:
5% C0 - Arrival MAP hidden transition matrix (n x n)
6% C1 - Arrival MAP arrival transition matrix (n x n)
7% D0 - Service MAP hidden transition matrix (m x m)
8% D1 - Service MAP observable transition matrix (m x m)
10% The service MAP
is converted to an equivalent PH representation.
12% RESULT = QSYS_MAPMAP1(...,
'numQLMoms', K) computes K queue length moments
13% RESULT = QSYS_MAPMAP1(...,
'numQLProbs', N) computes N queue length probs
14% RESULT = QSYS_MAPMAP1(...,
'numSTMoms', K) computes K sojourn time moments
16% Returns a
struct with fields:
17% meanQueueLength - Mean number of customers in system
18% meanWaitingTime - Mean waiting time in queue
19% meanSojournTime - Mean sojourn time (waiting + service)
20% utilization - Server utilization
21% queueLengthDist - Queue length distribution
P(Q=n)
22% queueLengthMoments- Raw moments of queue length
23% sojournTimeMoments- Raw moments of sojourn time
24% analyzer - Name of analyzer used
26% See also MMAPPH1FCFS, qsys_mapph1, qsys_phph1
28% Parse optional arguments
30addParameter(p, 'numQLMoms', 3);
31addParameter(p, 'numQLProbs', 100);
32addParameter(p, 'numSTMoms', 3);
35numQLMoms = p.Results.numQLMoms;
36numQLProbs = p.Results.numQLProbs;
37numSTMoms = p.Results.numSTMoms;
39% Build arrival
MMAP structure for BUTools (single class)
42% Convert service MAP to PH representation
43[sigma, S] = mapToPh(D0, D1);
45% Service parameters as cell arrays
50[ncMoms, ncDistr, stMoms] = MMAPPH1FCFS(D, sigmaCell, SCell, ...
51 'ncMoms', numQLMoms,
'ncDistr', numQLProbs,
'stMoms', numSTMoms);
53% Compute utilization from arrival and service rates
54thetaArr = ctmc_solve(C0 + C1);
55lambda = sum(thetaArr * C1);
57thetaSvc = ctmc_solve(D0 + D1);
58mu = sum(thetaSvc * D1);
74% Mean service time from PH
76meanService = sigma * negSinv * ones(size(S,1), 1);
78% Waiting time = sojourn time - service time
79meanWT = max(0, meanST - meanService);
83result.meanQueueLength = meanQL;
84result.meanWaitingTime = meanWT;
85result.meanSojournTime = meanST;
86result.utilization = rho;
87result.queueLengthDist = ncDistr;
88result.queueLengthMoments = ncMoms;
89result.sojournTimeMoments = stMoms;
90result.analyzer =
'BUTools:MMAPPH1FCFS';
94function [sigma, S] = mapToPh(D0, D1)
95% MAPTOPH Converts a MAP to its equivalent PH representation.
97% The PH representation captures the service time distribution
98% of the MAP, with initial distribution derived from the
99% stationary distribution weighted by observable transition rates.
101% Stationary distribution of the MAP
102theta = ctmc_solve(D0 + D1);
104% Initial distribution
for PH
is proportional to
105% how customers enter the service process
109 sigma = sigma / total;
111 % Fallback to uniform
if no arrivals
112 sigma = ones(1, size(D0, 1)) / size(D0, 1);
115% The PH generator
is the hidden transition matrix