LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
qsys_mapmap1.m
1function result = qsys_mapmap1(C0, C1, D0, D1, varargin)
2% QSYS_MAPMAP1 Analyzes a MAP/MAP/1 queue using BUTools MMAPPH1FCFS.
3%
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)
9%
10% The service MAP is converted to an equivalent PH representation.
11%
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
15%
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
25%
26% See also MMAPPH1FCFS, qsys_mapph1, qsys_phph1
27
28% Parse optional arguments
29p = inputParser;
30addParameter(p, 'numQLMoms', 3);
31addParameter(p, 'numQLProbs', 100);
32addParameter(p, 'numSTMoms', 3);
33parse(p, varargin{:});
34
35numQLMoms = p.Results.numQLMoms;
36numQLProbs = p.Results.numQLProbs;
37numSTMoms = p.Results.numSTMoms;
38
39% Build arrival MMAP structure for BUTools (single class)
40D = {C0, C1};
41
42% Convert service MAP to PH representation
43[sigma, S] = mapToPh(D0, D1);
44
45% Service parameters as cell arrays
46sigmaCell = {sigma};
47SCell = {S};
48
49% Call BUTools solver
50[ncMoms, ncDistr, stMoms] = MMAPPH1FCFS(D, sigmaCell, SCell, ...
51 'ncMoms', numQLMoms, 'ncDistr', numQLProbs, 'stMoms', numSTMoms);
52
53% Compute utilization from arrival and service rates
54thetaArr = ctmc_solve(C0 + C1);
55lambda = sum(thetaArr * C1);
56
57thetaSvc = ctmc_solve(D0 + D1);
58mu = sum(thetaSvc * D1);
59rho = lambda / mu;
60
61% Extract results
62if ~isempty(ncMoms)
63 meanQL = ncMoms(1);
64else
65 meanQL = 0;
66end
67
68if ~isempty(stMoms)
69 meanST = stMoms(1);
70else
71 meanST = 0;
72end
73
74% Mean service time from PH
75negSinv = inv(-S);
76meanService = sigma * negSinv * ones(size(S,1), 1);
77
78% Waiting time = sojourn time - service time
79meanWT = max(0, meanST - meanService);
80
81% Build result struct
82result = struct();
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';
91
92end
93
94function [sigma, S] = mapToPh(D0, D1)
95% MAPTOPH Converts a MAP to its equivalent PH representation.
96%
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.
100
101% Stationary distribution of the MAP
102theta = ctmc_solve(D0 + D1);
103
104% Initial distribution for PH is proportional to
105% how customers enter the service process
106sigma = theta * D1;
107total = sum(sigma);
108if total > 0
109 sigma = sigma / total;
110else
111 % Fallback to uniform if no arrivals
112 sigma = ones(1, size(D0, 1)) / size(D0, 1);
113end
114
115% The PH generator is the hidden transition matrix
116S = D0;
117
118end