Debian Codegraph @

docs/examples/callCenter_OO.py

raw symbols SCIP
1 """callCenter_OO.py
2 Model shows use of get command with a filter function.
3
4 Scenario:
5 A call center runs around the clock. It has a number of agents online with
6 different skills/competences.
7 Calls by clients with different questions arrive at an expected rate of callrate
8 per minute (expo. distribution). An agent only deals with clients with questions
9 in his competence areas. The number of agents online and their skills remain constant --
10 when an agent goes offline, he is replaced by one withe thesame skills.
11 The expected service time tService[i] per question
12 follows an exponential distribution.
13 Clients are impatient and renege if they don't get service within time
14 tImpatience.
15
16 * Determine the waiting times of clients.
17 * Determine the percentage renegers
18 * Determine the percentage load on agents.
19 """
20 from SimPy.Simulation import *
21 import random as r
22 ## Model components -----------------------------------------------------------
23 class Client(Process):
24 def __init__(self,need,sim):
25 Process.__init__(self,sim=sim)
26 self.need=need
27 def getServed(self,callCenter):
28 self.done=SimEvent(sim=self.sim)
29 callsWaiting=callCenter.calls
30 self.served=False
31 self.tArrive=self.sim.now()
32 yield put,self,callsWaiting,[self]
33 yield hold,self,tImpatience
34 # get here either after renege or after interrupt of renege==successful call
35 if self.interrupted():
36 #success, got service
37 callCenter.renegeMoni.observe(success)
38 # wait for completion of service
39 yield waitevent,self,self.done
40 else:
41 #renege
42 callCenter.renegeMoni.observe(renege)
43 callsWaiting.theBuffer.remove(self)
44 callCenter.waitMoni.observe(self.sim.now()-self.tArrive)
45 if callsWaiting.monitored:
46 callsWaiting.bufferMon.observe(y=len(callsWaiting.theBuffer))
47
48 class CallGenerator(Process):
49 def __init__(self,name,center,sim):
50 Process.__init__(self,name=name,sim=sim)
51 self.buffer=center.calls
52 self.center=center
53 def generate(self):
54 while self.sim.now()<=endTime:
55 yield hold,self,r.expovariate(callrate)
56 ran=r.random()
57 for aNeed in clientNeeds:
58 if ran<probNeeds[aNeed]:
59 need=aNeed
60 break
61 c=Client(need=need,sim=self.sim)
62 self.sim.activate(c,c.getServed(callCenter=self.center))
63 class Agent(Process):
64 def __init__(self,name,skills,sim):
65 Process.__init__(self,name=name,sim=sim)
66 self.skills=skills
67 self.busyMon=Monitor(name="Load on %s"%self.name,sim=self.sim)
68 def work(self,callCtr):
69 incoming=callCtr.calls
70 def mySkills(buffer):
71 ret=[]
72 for client in buffer:
73 if client.need in self.skills:
74 ret.append(client)
75 break
76 return ret
77 self.started=self.sim.now()
78 while True:
79 self.busyMon.observe(idle)
80 yield get,self,incoming,mySkills
81 self.busyMon.observe(busy)
82 theClient=self.got[0]
83 callCtr.waitMoni.observe(self.sim.now()-theClient.tArrive)
84 self.interrupt(theClient) # interrupt the timeout renege
85 yield hold,self,tService[theClient.need]
86 theClient.done.signal()
87
88 class Callcenter:
89 def __init__(self,name,sim):
90 self.calls=Store(name=name,unitName="call",monitored=True,sim=sim)
91 self.waitMoni=Monitor("Caller waiting time",sim=sim)
92 self.agents=[]
93 self.renegeMoni=Monitor("Renegers",sim=sim)
94
95 renege=1
96 success=0
97 busy=1
98 idle=0
99
100 ## Experiment data ------------------------------------------------------------
101 centerName="SimCityBank"
102 clientNeeds=["loan","insurance","credit card","other"]
103 aSkills=[["loan"],["loan","credit card"],["insurance"],["insurance","other"]]
104 nrAgents={0:1,1:2,2:2,3:2} #skill:nr agents of that skill
105 probNeeds={"loan":0.1,"insurance":0.2,"credit card":0.5,"other":1.0}
106 tService={"loan":3.,"insurance":4.,"credit card":2.,"other":3.} # minutes
107 tImpatienceRange = (0.5,1.,2.,) # minutes
108 callrate=7./10 # Callers per minute
109 endTime=10*24*60 # minutes (10 days)
110 r.seed(12345)
111
112 ## Model ----------------------------------------------------------------------
113 class CallCenterModel(Simulation):
114 def run(self):
115 self.initialize()
116 callC=Callcenter(name=centerName,sim=self)
117 for i in nrAgents.keys(): #loop over skills
118 for j in range(nrAgents[i]): # loop over nr agents of that skill
119 a=Agent(name="Agent type %s"%i,skills=aSkills[i],sim=self)
120 callC.agents.append(a)
121 self.activate(a,a.work(callCtr=callC))
122 cg=CallGenerator(name="Call generator",center=callC,sim=self)#buffer=callC.calls)
123 self.activate(cg,cg.generate())
124 self.simulate(until=endTime)
125 return callC
126
127 for tImpatience in tImpatienceRange:
128 ## Experiment ------------------------------------------------------------------
129 callCenter=CallCenterModel().run()
130 ## Analysis/output -------------------------------------------------------------
131 print "\ntImpatience=%s minutes"%tImpatience
132 print "=================="
133 callCenter.waitMoni.setHistogram(low=0.0,high=float(tImpatience))
134 try:
135 print callCenter.waitMoni.printHistogram(fmt="%6.1f")
136 except:
137 pass
138 renegers=[1 for x in callCenter.renegeMoni.yseries() if x==renege]
139 print "\nPercentage reneging callers: %4.1f\n"\
140 %(100.0*sum(renegers)/callCenter.renegeMoni.count())
141 for agent in callCenter.agents:
142 print "Load on %s (skills= %s): %4.1f percent"\
143 %(agent.name,agent.skills,agent.busyMon.timeAverage()*100)
144
145