-
Notifications
You must be signed in to change notification settings - Fork 0
/
Servers.py
40 lines (38 loc) · 1.39 KB
/
Servers.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
import numpy as np
class Server():
def __init__(self):
self.TotalServiceTime=0
self.numCustomer=0
class Servers():
def __init__(self,numServers=5):
self.availableServers = [Server() for i in range(numServers)]
self.numServers = numServers
# server customer using one of the servers available
def ServeCustomer(self,env,customer,queue):
server=self.availableServers.pop(0)
if((self.numServers-len(self.availableServers))>queue.maxNumBusyServer):
queue.maxNumBusyServer = self.numServers-len(self.availableServers)
serviceTime= customer.calculateServiceTime()
customer.serviceTime.append(serviceTime)
server.TotalServiceTime+=serviceTime
server.numCustomer+=1
yield env.timeout(serviceTime)
# release server
self.availableServers.append(server)
# check if customer is satisfied
choices = [0, 1]
p = 0.2/(1+customer.num_of_services)
probabilities = [p, 1-p]
satisfied = np.random.choice(choices, 1, p=probabilities)
customer.num_of_services += 1
if not satisfied:
customer.timeSpent+=serviceTime
queue.customers.append(customer)
if(len(queue.customers)>queue.maxLen):
queue.maxLen = len(queue.customers)
else:
customerArrivalTime = customer.arrival_timeStamp
timeNow = env.now
customer.timeSpent = timeNow - customerArrivalTime
queue.customerServerd.append(customer)
return 0