Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- import math
- import csv
- #Graphs imports
- import matplotlib.pyplot as plt
- import numpy as npy
- def singleQueue(alpha, beta, time=480):
- """
- >>> random.seed(57)
- >>> singleQueue(10, 3, 480)
- 3
- >>> random.seed(101)
- >>> singleQueue(5, 3, 480)
- 6
- >>> random.seed(101)
- >>> singleQueue(5, 3)
- 6
- >>> random.seed(935)
- >>> singleQueue(10, 9, 280)
- 10
- >>> type(singleQueue(10, 9, 280))
- <class 'int'>
- """
- #Sets the initial variables to correct starting point.
- c = 0
- ta = 0
- ts = 0
- Q = 1
- maxQ = 0
- #Used to loop the first clause of the alogrithim until c < simTime is no.
- while c < time:
- #Asks if ta < ts to allow the code to follow the correct path.
- if ta < ts:
- #The code will go down the 'left path' updating all information and variables.
- ts = ts - ta
- c = c + ta
- Q = Q + 1
- #Used to update the max length of the queue.
- if Q >maxQ:
- maxQ = Q
- #Update a random time for the next customer arrival.
- ta = nextTime(alpha)
- else:
- #Similair to the 'if' statement, however goes down the 'right path'.
- ta = ta - ts
- c = c + ts
- Q = Q - 1
- #Update the time to be served.
- ts = nextTime(beta)
- #To fulfill the final conditions of Q = 0?
- while Q == 0:
- c = c + ta
- Q = Q + 1
- if Q > maxQ:
- maxQ = Q
- ta = nextTime(alpha)
- return maxQ
- def doubleQueue(alpha, beta, time=480):
- ta = 0
- ts1 = 0
- ts2 = 0
- c = 0
- maxQ = 0
- Q = 1
- while c < time:
- if ta < ts1 and ta < ts2:
- ts = ts - ta
- ts2 = ts2 - ta
- c = c + ta
- Q = Q + 1
- if Q > maxQ:
- maxQ = Q
- ta = nextTime(alpha)
- else:
- if ts1 < ts2:
- ta = ta - ts1
- ts2 = ts2 - ts1
- c = c + ts1
- Q = Q - 1
- ts1 = nextTime(beta)
- else:
- ta = ta - ts2
- ts1 = ts1 - ts2
- c = c + ts1
- Q = Q - 1
- ts2 = nextTime(beta)
- while Q == 0:
- c = c + ta
- Q = Q + 1
- if Q > maxQ:
- maxQ = Q
- ta = nextTime(alpha)
- return maxQ
- #3b:
- #Plot points on a graph
- #Assign graph parameters
- plt.title('The relationship between the introduction of a second teller and maximum queue times')
- plt.ylabel('Max Queue length')
- plt.xlabel('Alpha / Beta values')
- #Declare required vars
- alphavars = npy.arange(1.1,10,0.1)
- betavars = npy.arange(1,0,-0.1)
- b = 1
- plotpoints =[]
- for a in alphavars:
- maxQ_value = 0
- for i in range(100):
- maxQ_value += singleQueue(a,b)
- plotpoints.append(maxQ_value / 100)
- b = b-0.1
- plt.plot(alphavars,plotpoints,label ="Unaltered Queue")
- for a in alphavars:
- maxQ_value = 0
- for i in range(100):
- maxQ_value += doubleQueue(a,b)
- plotpoints.append(maxQ_value / 100)
- b = b-0.1
- plt.plot(alphavars,plotpoints,label ="Double Queue")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement