# Copyright 2015 Dr. Greg M. Bernstein
""" Function to compute the Erlang loss formula.
See: https://en.wikipedia.org/wiki/Erlang_%28unit%29#Erlang_B_formula
for the iterative method used here.
For a full derivation see Zukerman, "Queueing Theory and Stochastic
Teletraffic Models", section 8.3, page 132.
"""
def erlangB(A, k):
""" Erlang B formula
Also known as the Erlang loss formula
Parameters
----------
A : float
offered load. Should be less than `k`
k : integer
number of servers or "trunks"
Returns
-------
float
"""
invB = 1.0
for m in xrange(1,k+1):
invB = 1.0 + (float(m)/A)*invB
return 1.0/invB