Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import math
- import random
- #---------------QUESTION 1A---------------
- def nextTime(mean):
- for i in range(mean):
- x=random.random()
- arrivaltime = (-(mean)) * (math.log(1-x))
- print arrivaltime
- #---------------------------------------------------------------------------------------------------------------------------------------------------------------------
- #---------------QUESTION 1B---------------
- def singlequeue():
- #Initialising the variables used for calculating the average
- totalqueue=0
- count=0
- #Asking the user what they wish to use for alpha and beta
- a = raw_input('Please enter the average interarrival time (alpha): ')
- b = raw_input('Please enter the average service times (beta): ')
- #Setting alpha and beta to integer numbers
- a =int(a)
- b=int(b)
- #For 1 -> n times, do
- for i in range(1, 201):
- c=0 #c to store the current time
- ta=0 #ta to store the time to the next customer arrival
- ts=0 #ts to store the time until the customer has finished being served
- q=1 #Q to store the current length of the queue
- maxqueue=0 #maxqueue is used to show the maximum queue after the 8 hours
- while c < 480: #While the time is less than 8 hours
- if q!=0: #If the length of the queue is not 0
- if ta<ts:
- ts = ts - ta
- c = c + ta
- q=q+1
- x=random.random()
- ta = -a * (math.log(1-x))
- if maxqueue < q:
- maxqueue = q
- else:
- ta = ta - ts
- c = c + ts
- q=q-1
- x=random.random()
- ts = -b * (math.log(1-x))
- elif q==0: #If the length of the queue is 0
- c = c +ta
- q=q+1
- x=random.random()
- ta = -a * (math.log(1-x))
- if maxqueue < q:
- maxqueue = q
- if totalqueue == 0: #If totalqueue equals 0, then the total queue is the maximum length
- totalqueue = maxqueue
- else: #If a totalqueue has already been set, then the maximum queue is simply added to the total
- totalqueue = totalqueue + maxqueue
- count += 1 #Counting how many times the simulation is run
- avgqueue = totalqueue / float(count) #Working out that the average length is the totalqueue divided by the amount of times the simulation is run
- print 'Average queue was : ', avgqueue #Printing the value of the Average Queue Length
Add Comment
Please, Sign In to add comment