我正在为虚拟呼叫中心开发程序。它具有以下情形:
呼叫者在某个特定位置随机排队进入呼叫中心队列
率,例如每小时100个通话
固定数量的代理(例如50个) 服务队列the
我已经注意到,即使队列中的调用者数量越来越多,在25次迭代之后,可用的代理数量也总是返回到原始的50个。我想我一定不能正确处理从忙碌队列到可用队列的代理迁移:
class Agent
attr_accessor :serve_time, :time_limit
@@total_time = 0
@@number_of_callers = 0
def initialize
@serve_time = 0
@time_limit = 0
end
def generate_time_limit
@time_limit = rand(2.0..20.0)
end
def time_limit_reached?
@serve_time >= @time_limit
end
def self.add_serve_time(time)
@@total_time += time
@@number_of_callers += 1
self.avg_serve_time
end
def self.avg_serve_time
return 'unknown' if @@number_of_callers == 0
@@total_time / @@number_of_callers.to_f
end
end
class Caller
attr_accessor :wait_time
@@total_time = 0
@@number_of_callers = 0
def initialize
@wait_time = 0
end
def self.add_wait_time(time)
@@total_time += time
@@number_of_callers += 1
self.avg_wait_time
end
def self.avg_wait_time
return 'unknown' if @@number_of_callers == 0
@@total_time / @@number_of_callers.to_f
end
end
caller_queue = []
free_agent_queue = []
busy_agent_queue = []
#initiate agents
free_agent_queue = Array.new(50){Agent.new}
# Start the queue
100.times do |t|
caller_queue.push(Caller.new)
print "#{t}) queued callers #{caller_queue.size}, available agents #{free_agent_queue.size}, "
caller_queue.each { |c| c.wait_time += 1 }
# if there is avail agent and a caller in the queue, take the last
# caller in the queue out, take the last avail agent out and put that
# agent in the busy agent queue.
if free_agent_queue.any? && caller_queue.any?
busy_agent_queue.push(free_agent_queue.pop)
busy_agent_queue.last.generate_time_limit
busy_agent_queue.each { |b| b.serve_time += 1}
Caller.add_wait_time(caller_queue.pop.wait_time)
end
print "avg wait time #{Caller.avg_wait_time}, "
# any agents who's call time is up, take them out of the busy queue
# and back into the avail agent queue
busy_agent_queue.reject!{ |a|
if a.time_limit_reached?
Agent.add_serve_time(a.serve_time)
free_agent_queue.push(a)
true
else
false
end
}
puts "avg serve time #{Agent.avg_serve_time}"
end
有人可以告诉我编写代码来处理代理或实现所列方案的方式是否有问题吗? 我认为平均服务时间也可能与此有关,因为计数似乎太高了。我应该以自己的方式使用类方法/变量吗?
我将不胜感激!