Question: Please complete dissatisfied_departure function . N.B: [ I already post this question two times but could not understand the solution] Here template Code Below: import

Please complete dissatisfied_departure function .
N.B: [ I already post this question two times but could not understand the solution]
Here template Code Below:
import numpy as np np.random.seed(10)
class SSQ: def __init__(self): #Initialization
self.interarrivals= list(np.random.exponential(scale=7, size=100)) # Edit size as necessary self.service_times= list(np.random.uniform(low=2, high=8, size=100)) # Edit size as necessary
print(self.interarrivals) print(self.service_times)
self.clock= 0.0 self.next_arrival=self.interarrivals.pop(0) self.next_departure= float('inf') self.num_in_queue= 0 self.times_of_arrival_in_queue= [] #store times of arrivals who are waiting in the queue self.service_times_in_queue= [] #store service times of waiting customers in the queue self.total_delay=0.0 self.num_of_delays= 0.0 self.customers_served= 0 # Count satisfied customers only
# Task: Following two variables need to be computed in your code # self.area_under_q= 0.0 # self.area_under_b= 0.0 self.server_status= 0 # 0 for IDLE , 1 for BUSY self.last_event_time=0.0 # we will need to store last event clock time self.probability_of_dissatisfaction = 0.15 # Use it to determine if a leaving customer gets back to the server/queue or departs self.queue_policy = 'FIFO' # Task: Set and use queue policy in appropriate places def start(self): while self.num_of_delays
if self.next_arrival
# self.satisfied_departure() or self.dissatisfied_departure() if np.random.choice([0, 1], p=[0.2, 0.8]) == 1: self.satisfied_departure() else: self.dissatisfied_departure()
print("Departure at "+str(self.clock)) print("Server Status:"+str(self.server_status)) print("Times of arrivals in Queue: "+ str(self.times_of_arrival_in_queue)) print("Service times in Queue: "+str(self.service_times_in_queue)) print("Total Delay:" +str(self.total_delay)) print("Next Arrival Time: "+str(self.next_arrival)) print("Next Departure Time: "+str(self.next_departure)) print(" ")
self.last_event_time = self.clock
def arrival(self): #Schedule next arrival , new_arrival = previous_arrival + inter_arrival time of next customer self.next_arrival= self.next_arrival+ self.interarrivals.pop(0) if self.server_status==0: #server is idle self.server_status= 1 #make server BUSY delay=0.0 #so delay is zero self.total_delay += delay self.num_of_delays +=1 #increase the number of customers delayed
#schedule next departure, pop the first element of service_times list to get service time of this customer self.next_departure = self.clock + self.service_times.pop(0) else: #Server is BUSY #increase queue length, this customer will have to wait in the queue self.num_in_queue+=1
#store the arrival time and service time of this customer in seperate lists self.times_of_arrival_in_queue.append(self.clock) self.service_times_in_queue.append(self.service_times.pop(0))
def satisfied_departure(self): # depart from server as the customer is satisfied #check number of customers in the queue if self.num_in_queue==0: #if no customer in the queue #make server IDLE self.server_status= 0 #schedule next departure= infinity self.next_departure= float('infinity') else: #if queue not empty, pop one customer, decrease queue length self.num_in_queue-=1 #AS FIFO, pop first arrival and service time from the queue. IF LIFO we have to pop last arrival and service time #For SJF, find the index of minimum service time from service_times_in_queue list. #Then pop the arrival of that index from times_of_arrival_in_queue for delay count and others.
# Task: Add code for SJF, LIFO and provide choice between the three options based on a global variable if self.queue_policy == 'FIFO': arrival= self.times_of_arrival_in_queue.pop(0) # FIFO Example elif self.queue_policy == 'LIFO': arrival = self.times_of_arrival_in_queue.pop(-1)
delay= self.clock- arrival self.total_delay+=delay self.num_of_delays+=1
self.next_departure = self.clock+ self.service_times_in_queue.pop(0) # FIFO Example
def dissatisfied_departure(self): # depart from server for the moment but the customer is dissatisfied # Task: Write code for this type of departure # The customer gets back to the queue [or directly to the server if it is idle] # The new arrival time for this repeated client would be their departure tinme (current clock) # Generate the new service time for this client from this distribution: Uniform(low=1,high=3) pass
s = SSQ() s.start()
Must Complete the template code given in the class to simulate a single server queue. You need to fulfill the following requirements.| 1) Take an input to determine the queue policy (FIFO/LIFO/SJF). Use that input to make decisions at appropriate places in the code. 2) There is a possibility that a customer might not be satisfied with the service she received. Now add codes in the template to randomly determine whether the customer was satisfied with the service or not at departure. If the customer is not satisfied, put them in the queue again (if the server is busy) or immediately to the server (if the server is idle). The parameters are given in the template code. 3) Stop the simulation when either 25 customers are served and satisfied or the global clock has passed 120 time units. 4) After the simulation is complete, report the following performance measures: a) Average delay b) Expected number of customers in the queue c) Expected utilization of the server
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
