Notes
Notes - notes.io |
import numpy.random
import simpy
import random
from random import seed
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import time
from simpy.util import start_delayed
seed(8889189) #for seed of randint function
random_seed = 997811 #for seed of other random generators
interarrivalTimes = []
serviceTimes = []
waitingTimes = []
renegingTimes = []
value = []
avg = []
in_queue, in_system = [],[]
tme_in_queue, len_in_queue = [],[]
interarrival_time = 10
service_time = 8
num_server = [1,2]
print('Customer_Num -- Arrival Time -- Service Begin -- Service End -- Num Server')
class Markovian(object):
def __init__(self, env):
self.env = env
def getService(env, Customer, server):
# new Customer arrives in the system
waitingStart = env.now
arrivalStart = env.now
serviceEnd = env.now
serviceStart = env.now
queue_in = env.now
length = len(server.queue)
tme_in_queue.append(queue_in)
len_in_queue.append(length)
req = server.request()
yield req
#checks if the server is empty or not, if empty, enters from the below command
queue_out = env.now
serviceStart = env.now
length = len(server.queue)
tme_in_queue.append(queue_out)
len_in_queue.append(length)
time_in_queue = queue_out - queue_in
in_queue.append(time_in_queue)
waitingTimes.append(serviceStart - waitingStart)
#starts service, and appends waiting times
#print('%.1f Begin Service of Customer %d' % (serviceStart, Customer))
yield env.timeout(random.expovariate(1.0/service_time))
serviceEnd = env.now
serviceTimes.append(env.now - serviceStart)
yield server.release(req)
#print('%.1f End Service of Customer %d' % (env.now, Customer))
#print("Customer %d spent %7.4f time in server" %(Customer,))
for i in range(len(num_server)):
if(num_server[i] == 1):
print('%d --------------- %.2f -------- %.2f -------- %.2f -------- 1' % (Customer, arrivalStart, serviceStart, serviceEnd))
elif(num_server[i] == 2):
print('%d --------------- %.2f -------- %.2f -------- %.2f -------- 2' % (Customer, arrivalStart, serviceStart, serviceEnd))
def generator(env, server):
markovian = Markovian(env)
Customer = 0
# generate new Customers
while True:
t = random.expovariate(1.0/interarrival_time)
yield env.timeout(t)
interarrivalTimes.append(t)
Customer += 1
#print('%.1f Arrival of Customer %d' % (env.now, Customer))
env.process(Markovian.getService(env, Customer, server))
def avg_line(df_length):
## finds the time average number of customers in the waiting line
## use the next row to figure out how long the queue was
df_length['delta_time'] = df_length['time'].shift(-1) - df_length['time']
df_length = df_length[0:-1]
avg = np.average(df_length['len'], weights=df_length['delta_time'])
return avg
def main():
random.seed(6)
env = simpy.Environment()
server = simpy.Resource(env, len(num_server))
env.process(Markovian.generator(env, server))
t=1000
env.run(until = t)
df1 = pd.DataFrame(tme_in_queue, columns=['time'])
df2 = pd.DataFrame(len_in_queue, columns=['len'])
df_length = pd.concat([df1, df2], axis=1)
avg_length = Markovian.avg_line(df_length)
print('The average number of customer in queue is %.2f' % (avg_length))
if __name__ == "__main__":
main()
|
Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...
With notes.io;
- * You can take a note from anywhere and any device with internet connection.
- * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
- * You can quickly share your contents without website, blog and e-mail.
- * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
- * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.
Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.
Easy: Notes.io doesn’t require installation. Just write and share note!
Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )
Free: Notes.io works for 12 years and has been free since the day it was started.
You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;
Email: [email protected]
Twitter: http://twitter.com/notesio
Instagram: http://instagram.com/notes.io
Facebook: http://facebook.com/notesio
Regards;
Notes.io Team