Hi guys.. I'm new to python.. need some help to point out error in this code. I want to plot the result from the total_wait but there are no value shown in the graph. I was able to print it tho.. so i'm kinda confuse.. Below are the code:
import numpy as np
class Simulation:
def generate_interarrival(self):
return np.random.poisson(1./3)
def generate_service(self):
return np.random.poisson(1./4)
def __init__(self):
self.queue = []
self.averageWaitingTime=[]
self.total_wait=[]
self.num_in_system = 0
self.clock = 0.0
self.t_arrival = self.generate_interarrival()
self.t_depart = float('inf')
self.num_arrivals = 0
self.num_departs = 0
self.total_wait = 0.0
self.averageWaitingTime= 0.0
def advance_time(self):
t_event =min(self.t_arrival, self.t_depart)
self.total_wait += self.num_in_system*(t_event - self.clock)
print self.total_wait, 'customer total wait'
self.clock = t_event
if self.t_arrival <=self.t_depart:
self.handle_arrival_event()
else:
self.handle_depart_event()
self.averageWaitingTime =self.total_wait/self.t_depart
print self.averageWaitingTime, ' average waiting time per customer'
def handle_arrival_event(self ):
self.num_in_system +=1
self.num_arrivals += 1
num_arrivals = self.clock+ self.generate_interarrival()
print num_arrivals, ' customer {} interarrival'.format(i)
if self.num_in_system <=1:
self.t_depart = self.clock + self.generate_service()
self.t_arrival = self.clock + self.generate_interarrival()
def handle_depart_event(self):
self.num_in_system -=1
self.num_departs += 1
num_departs = self.clock
print num_departs, ' customer {} departed'.format(i)
if self.num_in_system>0:
self.t_depart = self.clock + self.generate_service()
else:
self.t_depart = float(' inf')
np.random.seed(0)
s = Simulation()
for i in range (1000):
s.advance_time()
import matplotlib.pyplot as plt
plt.plot(s.total_wait)
plt.ylabel('Waiting time(min)')
plt.xlabel('Number of Customers')