-
Notifications
You must be signed in to change notification settings - Fork 0
/
erlang.py
53 lines (42 loc) · 2 KB
/
erlang.py
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
'''
Created on 6 mei 2014
Erlang functions for use in calculators
@author: Patrick.Hubers
'''
from math import exp, ceil, trunc
def Workload(volume, avgHandleTime, intervalLength=60):
return( (volume*avgHandleTime)/(60.0*intervalLength) )
def Occupancy(numAgents, workload):
return( workload/(numAgents*1.0) )
def ErlangB(numAgents, workload):
inverse_b = 1.0
for k in range(1, numAgents):
inverse_b = 1.0 + inverse_b * k / workload
return(1.0 / inverse_b)
def ErlangC(numAgents, workload):
erlangc = numAgents * ErlangB(numAgents, workload) / (numAgents - workload * (1 - ErlangB(numAgents, workload)))
return( erlangc )
def AverageWaitingTime(numAgents, volume, avgHandleTime, intervalLength):
workload = Workload(volume, avgHandleTime, intervalLength)
return( (ErlangC(numAgents,workload)*avgHandleTime)/(numAgents-workload) )
def ServiceLevel(numAgents, volume, avgHandleTime, intervalLength, maxWaitingTime):
workload = Workload(volume, avgHandleTime, intervalLength)
return( 1-ErlangC(numAgents,workload)* exp(-(numAgents-workload)*((maxWaitingTime*1.0)/avgHandleTime)) )
def AgentsForServiceLevel(volume, avgHandleTime, intervalLength, maxWaitingTime, serviceGoal):
workload = Workload(volume, avgHandleTime, intervalLength)
agents = trunc(ceil(workload))
while( ServiceLevel(agents, volume, avgHandleTime, intervalLength, maxWaitingTime) < serviceGoal ):
agents += 1
return( agents )
if __name__ == '__main__':
vol = 400
aht = 180
wl = Workload(vol, aht, 60)
print('Workload for %d calls/hour with an AHT of %d seconds is %d' % (vol, aht, wl))
sgoal = 0.8
stime = 20
agents = AgentsForServiceLevel(vol, aht, 60, stime, sgoal)
print('Required agents for a service level of %d/%d is %d' % (sgoal*100, stime, agents))
print('Waiting chance for a caller is %f ' % ErlangC(agents, wl))
print('Service level is %f ' % ServiceLevel(agents, vol, aht, 60, stime))
print('Occupancy is %f' % Occupancy(agents, wl))