Last active
April 15, 2018 20:00
-
-
Save chrisgaraffa/b4ce9385c4ee481c9d91f587f0b9b1fc to your computer and use it in GitHub Desktop.
Erlang-C circuit calculation, in Ruby
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/ruby | |
#### Based on https://www.callcentrehelper.com/erlang-c-formula-example-121281.htm | |
#### Using ruby 2.2.0 | |
#### I'm a pretty awful ruby programmer, so I'm sure there are a thousand ways to do this better. | |
#### Also, thanks StackOverflow | |
def erlangc_circuits(numcalls, numcalls_period, timepercall, targetanswertime, numAgentsBump) | |
#integer, minutes, seconds, seconds, integer | |
###Traffic Intensity: A | |
callMinutes = numcalls * (timepercall/60) | |
callHours = callMinutes / 60 #callHours is in Erlangs | |
#puts "callHours: #{callHours}" | |
###Raw number of agents required (N) | |
rawNumberOfAgents = callHours + 1 + numAgentsBump | |
#puts "rawNumberofAgents: #{rawNumberOfAgents}" | |
###N factorial (N!) | |
rawNumberOfAgentsFactorial = (1..rawNumberOfAgents).reduce(1, :*) | |
#puts "rawNumberOfAgentsFactorial: #{rawNumberOfAgentsFactorial}" | |
###Powers: A^N | |
aToTheNPowers = callHours**rawNumberOfAgents | |
#puts "A^N: #{aToTheNPowers}" | |
###Simply Formula: X = (A^N)/N! * N-(N-A) | |
x = (aToTheNPowers.to_f / rawNumberOfAgentsFactorial.to_f).to_f * (rawNumberOfAgents.to_f / (rawNumberOfAgents.to_f - callHours.to_f)) | |
#puts "x: #{x}" | |
###Simplify Forumla: Y = (Sum i=0 to N-1 (A^i) / (i!)) | |
y = 0 | |
for i in 0..rawNumberOfAgents-1 | |
top = callHours**i | |
bottom = (1..i).reduce(1, :*) | |
y += (top.to_f/bottom.to_f).to_f | |
end | |
#puts "y: #{y}" | |
###Probability call has to wait | |
pw = x.to_f/(y+x).to_f | |
#puts "pw: #{pw}" | |
###Service Level | |
targetTimeOverAHT = (targetanswertime.to_f / timepercall.to_f).to_f | |
rawNumberAgentsMinusCallHours = (rawNumberOfAgents.to_f - callHours.to_f).to_f | |
exp = -1 * (rawNumberAgentsMinusCallHours * targetTimeOverAHT).to_f | |
serviceLevel = 1 - (pw * Math::E**(exp).to_f).to_f | |
#puts "serviceLevel: #{serviceLevel}" | |
return (serviceLevel * 100).to_i, rawNumberOfAgents | |
end | |
foundSolution = false | |
targetServiceLevel = 80 | |
numAgentsToBump = 0.to_i | |
numberOfAgentsRequired = 0 | |
while foundSolution == false | |
serviceLevel, numberOfAgentsRequired = erlangc_circuits(200, 60, 180, 20, numAgentsToBump) | |
#puts "#{serviceLevel} with #{numberOfAgentsRequired}" | |
if (serviceLevel < targetServiceLevel) | |
numAgentsToBump += 1 | |
foundSolution = false | |
else | |
foundSolution = true | |
end | |
end | |
puts "#{numberOfAgentsRequired} operators required" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment