1## Copyright (C) 2014, 2019 Moreno Marzolla
2##
3## This file is part of the queueing toolbox.
4##
5## The queueing toolbox is free software: you can redistribute it and/or
6## modify it under the terms of the GNU General Public License as
7## published by the Free Software Foundation, either version 3 of the
8## License, or (at your option) any later version.
9##
10## The queueing toolbox is distributed in the hope that it will be
11## useful, but WITHOUT ANY WARRANTY; without even the implied warranty
12## of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13## General Public License for more details.
14##
15## You should have received a copy of the GNU General Public License
16## along with the queueing toolbox. If not, see <http://www.gnu.org/licenses/>.
17
18## -*- texinfo -*-
19##
20## @deftypefn {Function File} {@var{C} =} erlangc (@var{A}, @var{m})
21##
22## @cindex Erlang-C formula
23##
24## Compute the steady-state probability of delay in the Erlang delay model.
25##
26## The Erlang-C formula @math{E_C(A, m)} gives the probability that an
27## open queueing system with @math{m} identical servers, infinite
28## wating space, arrival rate @math{\lambda}, individual service rate
29## @math{\mu} and offered load @math{A = \lambda / \mu} has all the
30## servers busy. This is the waiting probability in an
31## @math{M/M/m/\infty} system with @math{m} servers and an infinite
32## queue.
33##
34## @tex
35## @math{E_C(A, m)} is defined as:
36##
37## $$
38## E_C(A, m) = \displaystyle{ {A^m \over m!} {1 \over 1-\rho} \left( \sum_{k=0}^{m-1} {A^k \over k!} + {A^m \over m!} {1 \over 1 - \rho} \right) ^{-1}}
39## $$
40##
41## where @math{\rho = A / m = \lambda / (m \mu)}.
42## @end tex
43##
44## @strong{INPUTS}
45##
46## @table @code
47##
48## @item @var{A}
49## Offered load. @math{A = \lambda / \mu} where
50## @math{\lambda} is the mean arrival rate and @math{\mu} the mean
51## service rate of each individual server (real, @math{0 < A < m}).
52##
53## @item @var{m}
54## Number of identical servers (integer, @math{m @geq{} 1}).
55## Default @math{m = 1}
56##
57## @end table
58##
59## @strong{OUTPUTS}
60##
61## @table @code
62##
63## @item @var{B}
64## The value @math{E_C(A, m)}
65##
66## @end table
67##
68## @var{A} or @var{m} can be vectors, and in this case, the results will
69## be vectors as well.
70##
71## @strong{REFERENCES}
72##
73## @itemize
74## @item
75## G. Zeng, @cite{Two common properties of the Erlang-B function, Erlang-C function, and Engset blocking function}, Mathematical and Computer Modelling, Volume 37, Issues 12-13, June 2003, Pages 1287-1296
76## @end itemize
77##
78## @seealso{erlangb,engset,qsmmm}
79##
80## @end deftypefn
81
82## Author: Moreno Marzolla <moreno.marzolla(at)unibo.it>
83## Web: http://www.moreno.marzolla.name/
84function C = erlangc(A, m)
85  if ( nargin < 1 || nargin > 2 )
86    print_usage();
87  endif
88
89  ( isnumeric(A) && all(A(:) > 0) ) || error("A must be positive");
90
91  if ( nargin == 1 )
92    m = 1;
93  else
94    ( isnumeric(m) && all( fix(m(:)) == m(:)) && all( m(:) > 0 ) ) || error("m must be a positive integer");
95  endif
96
97  [err A, m] = common_size(A, m);
98  if ( err )
99    error("parameters are not of common size");
100  endif
101
102  all( A(:) < m(:) ) || error("A must be < m");
103
104  rho = A ./ m;
105  B = erlangb(A, m);
106  C = B ./ (1 - rho .* (1 - B));
107endfunction
108
109%!test
110%! fail("erlangc('foo',1)", "positive");
111%! fail("erlangc(1,'bar')", "positive");
112