File: qsmminf.m

package info (click to toggle)
octave-queueing 1.2.8-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 2,288 kB
  • sloc: makefile: 56
file content (149 lines) | stat: -rw-r--r-- 4,890 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
## Copyright (C) 2008, 2009, 2010, 2011, 2012, 2018, 2019 Moreno Marzolla
##
## This file is part of the queueing toolbox.
##
## The queueing toolbox is free software: you can redistribute it and/or
## modify it under the terms of the GNU General Public License as
## published by the Free Software Foundation, either version 3 of the
## License, or (at your option) any later version.
##
## The queueing toolbox is distributed in the hope that it will be
## useful, but WITHOUT ANY WARRANTY; without even the implied warranty
## of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
## General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with the queueing toolbox. If not, see <http://www.gnu.org/licenses/>.

## -*- texinfo -*-
##
## @deftypefn {Function File} {[@var{U}, @var{R}, @var{Q}, @var{X}, @var{p0}] =} qsmminf (@var{lambda}, @var{mu})
## @deftypefnx {Function File} {@var{pk} =} qsmminf (@var{lambda}, @var{mu}, @var{k})
##
## Compute utilization, response time, average number of requests and throughput for an infinite-server queue.
##
## The @math{M/M/\infty} system has an infinite number of identical
## servers. Such a system is always stable (i.e., the mean queue
## length is always finite) for any arrival and service rates.
##
## @cindex @math{M/M/}inf system
##
## @tex
## The steady-state probability @math{\pi_k} that there are @math{k}
## requests in the system, @math{k @geq{} 0}, can be computed as:
##
## $$
## \pi_k = {1 \over k!} \left( \lambda \over \mu \right)^k e^{-\lambda / \mu}
## $$
## @end tex
##
## @strong{INPUTS}
##
## @table @code
##
## @item @var{lambda}
## Arrival rate (@code{@var{lambda}>0}).
##
## @item @var{mu}
## Service rate (@code{@var{mu}>0}).
##
## @item @var{k}
## Number of requests in the system (@code{@var{k} @geq{} 0}).
##
## @end table
##
## @strong{OUTPUTS}
##
## @table @code
##
## @item @var{U}
## Traffic intensity (defined as @math{\lambda/\mu}). Note that this is
## different from the utilization, which in the case of @math{M/M/\infty}
## centers is always zero.
##
## @cindex traffic intensity
##
## @item @var{R}
## Service center response time.
##
## @item @var{Q}
## Average number of requests in the system (which is equal to the
## traffic intensity @math{\lambda/\mu}).
##
## @item @var{X}
## Throughput (which is always equal to @code{@var{X} = @var{lambda}}).
##
## @item @var{p0}
## Steady-state probability that there are no requests in the system
##
## @item @var{pk}
## Steady-state probability that there are @var{k} requests in the
## system (including the one being served).
##
## @end table
##
## If this function is called with less than three arguments,
## @var{lambda} and @var{mu} can be vectors of the same size. In this
## case, the results will be vectors as well.
##
## @strong{REFERENCES}
##
## @itemize
## @item
## G. Bolch, S. Greiner, H. de Meer and K. Trivedi, @cite{Queueing Networks
## and Markov Chains: Modeling and Performance Evaluation with Computer
## Science Applications}, Wiley, 1998, Section 6.4
## @end itemize
##
## @seealso{qsmm1,qsmmm,qsmmmk}
##
## @end deftypefn

## Author: Moreno Marzolla <moreno.marzolla(at)unibo.it>
## Web: http://www.moreno.marzolla.name/

function [U_or_pk R Q X p0] = qsmminf( lambda, mu, k )
  if ( nargin < 2 || nargin > 3 )
    print_usage();
  endif
  ( isvector(lambda) && isvector(mu) ) || ...
      error( "lambda and mu must be vectors" );
  [ err lambda mu ] = common_size( lambda, mu );
  if ( err )
    error( "Parameters are of incompatible size" );
  endif
  lambda = lambda(:)';
  mu = mu(:)';
  ( all( lambda>0 ) && all( mu>0 ) ) || ...
  error( "lambda and mu must be >0" );
  if (nargin < 3)
    U_or_pk = Q = lambda ./ mu; # Traffic intensity.
    p0 = exp(-lambda./mu); # probability that there are 0 requests in the system
    R = 1 ./ mu;
    X = lambda;
  else
    (length(lambda) == 1) || error("lambda must be a scalar if this function is called with three arguments");
    isvector(k) || error("k must be a vector");
    all(k>=0 )|| error("k must be >= 0");
    ## expn does not support array arguments, hence we must use arrayfun()
    U_or_pk = arrayfun(@(x) expn(lambda/mu, x) * exp(-lambda/mu), k);
  endif
endfunction
%!test
%! fail( "qsmminf( [1 2], [1 2 3] )", "incompatible size");
%! fail( "qsmminf( [-1 -1], [1 1] )", ">0" );

%!demo
%! ## Given a M/M/inf and M/M/m queue, compute the steady-state probability pk
%! ## of having k requests in the systen.
%! lambda = 5;
%! mu = 1.1;
%! m = 5;
%! k = 0:20;
%! pk_inf = qsmminf(lambda, mu, k);
%! pk_m = qsmmm(lambda, mu, 5, k);
%! plot(k, pk_inf, "-o;M/M/\\infty;", "linewidth", 2, ...
%!      k, pk_m, "-x;M/M/5;", "linewidth", 2);
%! xlabel("N. of requests (k)");
%! ylabel("P_k");
%! title(sprintf("M/M/\\infty and M/M/%d systems, \\lambda = %g, \\mu = %g", m, lambda, mu));