Copy link to clipboard
Copied
I need to calculate the Erlang C function for some contact center software. A picture of the function and a brief discussion is here.
I cobbled together a solution based on the approach normally used in Excel udsing the poisson distribution:
private function poissonA():Number
{
return (Math.pow(trafficIntensity(), _numberAgents) *
Math.exp(-1 * trafficIntensity())) /
com.subhumanmedia.Main.factorial(_numberAgents);
}
private function poissonB():Number
{
var result:Number = 0;
for (var i:int = -1; i < _numberAgents; i++)
{
result += (Math.pow(trafficIntensity(), i) *
Math.exp( -1 * trafficIntensity()) /
com.subhumanmedia.Main.factorial(i));
}
return (result);
}
public function erlangCFunction():Number
{
var pA:Number = poissonA();
return(pA / (pA + ((1 - agentOccupancy()) * poissonB())));
}
This works and it's ok for the few people who are currently using it. But it has limits I need to solve. It will only work for up to roughly 170 agents because of the maximum 64-bit floating point number. Also, on the face of it it seems pretty inefficient. I have tried to overcome the number size limitations by using a BigInteger implementation but that is stalled because Math.exp( -1 * trafficIntensity()) is never going to be an integer and I don't know how to multiply a BigIntger by a float. For BigIntegers I'm using As3Crypto .
I'm not much of a coder and even less of a mathematician. Can anyone give some suggestions for how to approach this? I've spent literally hours reading articles related to this but didn't find any practical help (at least that I could reccognize and knew how to apply).
I'm looking for either (1) a way to implement the current approach using only BigIntegers or preferably (2) a way to recast the original formula that is inherently more efficient to calculate.
Thanks in advance.
Ron
Copy link to clipboard
Copied
I had the same question, and got some help at probability - Erlang C for Large Numbers - Mathematics Stack Exchange
In VBA
Function ErlangC(u As Double, m As Long) As Double
' Returns the probability of waiting when dialing into a call center
' u = call intensity = calls/s * duration
' m = number of agents on hand
' m > u or wait times will grow without limit
Dim LnFactM As Double
Dim LnU As Double
Dim k As Long
Dim d As Double
With WorksheetFunction
LnFactM = .GammaLn(m + 1)
LnU = Log(u)
For k = 0 To m - 1
d = d + Exp(LnFactM - .GammaLn(k + 1) + (k - m) * LnU)
Next k
End With
ErlangC = 1 / (1 + (1 - u / m) * d)
End Function
For example, =ErlangC(1000, 1030) returns 24.9%
Copy link to clipboard
Copied
With further credit to user Dap at math.stackexchange, a version that requires no iteration:
Function DapErlangC(u As Double, m As Long) As Double
' shg 2017
' Credit to user Dap at
' https://math.stackexchange.com/questions/2446752/erlang-c-for-large-numbers
' Returns the probability of waiting when dialing into a call center
' u = call intensity = calls/s * duration
' m = number of agents on hand
' m > u or wait times will grow without limit
With WorksheetFunction
DapErlangC = 1 / (1 + (1 - u / m) * Exp(.GammaLn(m + 1) - m * Log(u) + u) * .Poisson(m - 1, u, True))
End With
End Function
It works equally well as a formula.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now