LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
fj_dist2fj.m
1%{ @file fj_dist2fj.m
2 % @brief Convert LINE PH/MAP distribution to FJ_codes format
3 %
4 % @author LINE Development Team
5%}
6
7%{
8 % @brief Convert LINE PH/MAP distribution to FJ_codes format
9 %
10 % @details
11 % Converts LINE's MAP representation {D0, D1} to FJ_codes format.
12 % For arrivals: returns (lambda, lambda0, lambda1, ma, Ia)
13 % For service: returns (mu, ST, St, tau_st, SerChoice)
14 %
15 % Supported distributions:
16 % - Exponential (Exp)
17 % - 2-phase Hyperexponential (HyperExp with 2 phases)
18 % - 2-phase Erlang (Erlang with 2 phases)
19 % - 2-phase MAP (MAP with 2 states)
20 %
21 % @par Syntax:
22 % @code
23 % fjDist = fj_dist2fj(lineMAP, distType, sn, ist, r)
24 % @endcode
25 %
26 % @par Parameters:
27 % <table>
28 % <tr><th>Name<th>Description
29 % <tr><td>lineMAP<td>LINE MAP representation {D0, D1}
30 % <tr><td>distType<td>'arrival' or 'service'
31 % <tr><td>sn<td>Network structure (for getting rate and process type)
32 % <tr><td>ist<td>Station index
33 % <tr><td>r<td>Class index
34 % </table>
35 %
36 % @par Returns:
37 % <table>
38 % <tr><th>Name<th>Description
39 % <tr><td>fjDist<td>FJ_codes compatible structure
40 % </table>
41 %
42 % @par Reference:
43 % Z. Qiu, J.F. Pérez, and P. Harrison, "Beyond the Mean in Fork-Join Queues:
44 % Efficient Approximation for Response-Time Tails", IFIP Performance 2015.
45 % Copyright 2015 Imperial College London
46%}
47function fjDist = fj_dist2fj(lineMAP, distType, sn, ist, r)
48
49fjDist = struct();
50
51% Get process type and mean rate
52procType = sn.procid(ist, r);
53mean_rate = sn.rates(ist, r);
54
55% Extract D0 and D1 from LINE MAP format
56D0 = lineMAP{1};
57D1 = lineMAP{2};
58nPhases = size(D0, 1);
59
60% Check number of phases
61if nPhases > 2
62 line_error(mfilename, 'FJ_codes only supports distributions with at most 2 phases. Found %d phases.', nPhases);
63end
64
65% Compute mean arrival/service rate (lambda or mu)
66lambda = map_lambda(lineMAP);
67mean_time = 1 / lambda;
68
69if strcmp(distType, 'arrival')
70 % ===== ARRIVAL PROCESS =====
71 fjDist.lambda = lambda;
72 fjDist.lambda0 = D0;
73 fjDist.lambda1 = D1;
74 fjDist.ma = nPhases;
75 fjDist.Ia = eye(nPhases);
76
77 % Determine arrival choice for logging/debugging
78 if procType == ProcessType.EXP
79 fjDist.ArrChoice = 1; % Exp
80 elseif procType == ProcessType.HYPEREXP && nPhases == 2
81 fjDist.ArrChoice = 2; % HE2
82 elseif procType == ProcessType.ERLANG && nPhases == 2
83 fjDist.ArrChoice = 3; % ER2
84 elseif procType == ProcessType.MAP && nPhases == 2
85 fjDist.ArrChoice = 4; % MAP2
86 else
87 line_error(mfilename, 'Unsupported arrival distribution type: %s with %d phases.', ...
88 ProcessType.toText(procType), nPhases);
89 end
90
91else
92 % ===== SERVICE PROCESS =====
93 % Convert MAP to PH representation for service
94 % PH is represented as (tau_st, ST) where:
95 % - tau_st is initial probability vector
96 % - ST is the rate matrix
97 % - St is the exit vector (computed as -ST * ones)
98
99 % For service, we need to compute the PH representation from MAP
100 % The initial distribution for service is the stationary distribution
101 pie = map_pie(lineMAP);
102
103 fjDist.mu = lambda; % Mean service rate
104 fjDist.ST = D0; % Rate matrix
105 fjDist.St = -D0 * ones(nPhases, 1); % Exit vector
106 fjDist.tau_st = pie(:)'; % Initial probability (as row vector)
107
108 % Determine service choice for logging/debugging
109 if procType == ProcessType.EXP
110 fjDist.SerChoice = 1; % Exp
111 elseif procType == ProcessType.HYPEREXP && nPhases == 2
112 fjDist.SerChoice = 2; % HE2
113 elseif procType == ProcessType.ERLANG && nPhases == 2
114 fjDist.SerChoice = 3; % ER2
115 else
116 line_error(mfilename, 'Unsupported service distribution type: %s with %d phases.', ...
117 ProcessType.toText(procType), nPhases);
118 end
119end
120
121end