LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
Erlang.m
1classdef Erlang < Markovian
2 % Erlang Multi-phase exponential distribution with reduced variability
3 %
4 % Erlang represents the distribution of the sum of r independent exponential
5 % random variables with the same rate. It models processes with reduced
6 % variability compared to exponential distributions and is commonly used
7 % for service times with more predictable durations.
8 %
9 % @brief Erlang distribution with phase rate and number of phases
10 %
11 % Key characteristics:
12 % - Sum of r independent exponential phases
13 % - Two parameters: phase rate (alpha) and number of phases (r)
14 % - Mean = r/alpha, Variance = r/alpha²
15 % - SCV = 1/r (always ≤ 1, decreasing with r)
16 % - Multi-phase Markovian representation
17 %
18 % The Erlang distribution is used for:
19 % - Service times with reduced variability
20 % - Multi-stage service processes
21 % - Modeling deterministic processes approximately
22 % - Building blocks for phase-type distributions
23 % - Systems where variability decreases with stages
24 %
25 % Example:
26 % @code
27 % service_dist = Erlang(3.0, 4); % 4 phases, rate 3.0 each
28 % % Mean = 4/3.0 = 1.33, SCV = 1/4 = 0.25
29 % samples = service_dist.sample(1000);
30 % @endcode
31 %
32 % Copyright (c) 2012-2026, Imperial College London
33 % All rights reserved.
34
35 methods
36 function self = Erlang(phaseRate, nphases)
37 % ERLANG Create an Erlang distribution instance
38 %
39 % @brief Creates an Erlang distribution with specified phase rate and phases
40 % @param phaseRate Rate parameter for each exponential phase
41 % @param nphases Number of sequential exponential phases (positive integer)
42 % @return self Erlang distribution instance
43 self@Markovian('Erlang',2);
44 setParam(self, 1, 'alpha', phaseRate); % rate in each state
45 setParam(self, 2, 'r', round(nphases)); % number of phases
46 self.obj = jline.lang.processes.Erlang(phaseRate, nphases);
47 r = self.getParam(2).paramValue;
48 self.process = map_erlang(getMean(self),r);
49 self.nPhases = length(self.process{1});
50 end
51
52 function phases = getNumberOfPhases(self)
53 % PHASES = GETNUMBEROFPHASES()
54
55 % Get number of phases in the underpinnning phase-type
56 % representation
57 phases = self.getParam(2).paramValue; %r
58 end
59
60 function ex = getMean(self)
61 % EX = GETMEAN()
62
63 % Get distribution mean
64 alpha = self.getParam(1).paramValue;
65 r = self.getParam(2).paramValue;
66 ex = r/alpha;
67 end
68
69 function SCV = getSCV(self)
70 % SCV = GETSCV()
71 % Get the squared coefficient of variation of the distribution (SCV = variance / mean^2)
72 r = self.getParam(2).paramValue;
73 SCV = 1/r;
74 end
75
76 function setMean(self,MEAN)
77 % UPDATEMEAN(SELF,MEAN)
78 % Update parameters to match the given mean
79 setMean@Markovian(self,MEAN);
80 r = self.getParam(2).paramValue;
81 self.setParam(1, 'alpha', r/MEAN);
82 self.process = map_erlang(getMean(self),r);
83 end
84
85
86 function Ft = evalCDF(self,t)
87 % FT = EVALCDF(SELF,T)
88
89 % Evaluate the cumulative distribution function at t
90 % AT T
91
92 alpha = self.getParam(1).paramValue; % rate
93 r = self.getParam(2).paramValue; % stages
94 Ft = 1;
95 for j=0:(r-1)
96 Ft = Ft - exp(-alpha*t).*(alpha*t).^j/factorial(j);
97 end
98 end
99
100 function L = evalLST(self, s)
101 % L = EVALLAPLACETRANSFORM(S)
102
103 % Evaluate the Laplace transform of the distribution function at t
104 % AT T
105
106 alpha = self.getParam(1).paramValue; % rate
107 r = self.getParam(2).paramValue; % stages
108 L = (alpha / (alpha + s))^r;
109 end
110 end
111
112 methods(Static)
113 function er = fit(MEAN, SCV, SKEW)
114 % ER = FITCENTRAL(MEAN, SCV, SKEW)
115
116 % Fit distribution from first three central moments (mean,
117 % SCV, skewness)
118 er = Erlang.fitMeanAndSCV(MEAN,SCV);
119 er.immediate = MEAN < GlobalConstants.FineTol;
120 end
121
122 % function er = fitRate(RATE)
123 % % ER = FITRATE(RATE)
124 %
125 % % Fit distribution with given rate
126 % line_warning(mfilename,'The Erlang distribution is underspecified by the rate, setting the number of phases to 2.\n');
127 % er = Erlang.fitMeanAndOrder(1/RATE, 2);
128 % er.immediate = 1/RATE < GlobalConstants.FineTol;
129 % end
130
131 % function er = fitMean(MEAN)
132 % % ER = FITMEAN(MEAN)
133 %
134 % % Fit distribution with given mean
135 % line_warning(mfilename,'The Erlang distribution is underspecified by the mean, setting the number of phases to 2.\n');
136 % er = Erlang.fitMeanAndOrder(MEAN, 2);
137 % er.immediate = MEAN < GlobalConstants.FineTol;
138 % end
139
140 function er = fitMeanAndSCV(MEAN, SCV)
141 % ER = FITMEANANDSCV(MEAN, SCV)
142 if SCV>1
143 line_error(mfilename,'The Erlang distribution requires squared coefficient of vairation <= 1.');
144 end
145 % Fit distribution with given mean and squared coefficient of variation (SCV=variance/mean^2)
146 r = ceil(1/SCV);
147 alpha = r/MEAN;
148 er = Erlang(alpha, r);
149 er.immediate = MEAN < GlobalConstants.FineTol;
150 end
151
152 function er = fitMeanAndOrder(MEAN, n)
153 % ER = FITMEANANDORDER(MEAN, N)
154
155 % Fit distribution with given mean and number of phases
156 SCV = 1/n;
157 r = ceil(1/SCV);
158 alpha = r/MEAN;
159 er = Erlang(alpha, r);
160 er.immediate = MEAN < GlobalConstants.FineTol;
161 end
162 end
163
164end