"""callCenter.py Model shows use of get command with a filter function. Scenario: A call center runs around the clock. It has a number of agents online with different skills/competences. Calls by clients with different questions arrive at an expected rate of callrate per minute (expo. distribution). An agent only deals with clients with questions in his competence areas. The number of agents online and their skills remain constant -- when an agent goes offline, he is replaced by one withe thesame skills. The expected service time tService[i] per question follows an exponential distribution. Clients are impatient and renege if they don't get service within time tImpatience. * Determine the waiting times of clients. * Determine the percentage renegers * Determine the percentage load on agents. """ from SimPy.Simulation import * import random as r ## Model components ----------------------------------------------------------- class Client(Process): def __init__(self,need): Process.__init__(self) self.need=need def getServed(self,callCenter): self.done=SimEvent() callsWaiting=callCenter.calls self.served=False self.tArrive=now() yield put,self,callsWaiting,[self] yield hold,self,tImpatience # get here either after renege or after interrupt of renege==successful call if self.interrupted(): #success, got service callCenter.renegeMoni.observe(success) # wait for completion of service yield waitevent,self,self.done else: #renege callCenter.renegeMoni.observe(renege) callsWaiting.theBuffer.remove(self) callCenter.waitMoni.observe(now()-self.tArrive) if callsWaiting.monitored: callsWaiting.bufferMon.observe(y=len(callsWaiting.theBuffer)) class CallGenerator(Process): def __init__(self,name,center): Process.__init__(self,name) self.buffer=center.calls self.center=center def generate(self): while now()<=endTime: yield hold,self,r.expovariate(callrate) ran=r.random() for aNeed in clientNeeds: if ran