Advertisement
Guest User

Untitled

a guest
Dec 14th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.31 KB | None | 0 0
  1. import random
  2. import math
  3. import csv
  4. #Graphs imports
  5. import matplotlib.pyplot as plt
  6. import numpy as npy
  7.  
  8.  
  9. def singleQueue(alpha, beta, time=480):
  10.     """
  11.    >>> random.seed(57)
  12.    >>> singleQueue(10, 3, 480)
  13.    3
  14.    >>> random.seed(101)
  15.    >>> singleQueue(5, 3, 480)
  16.    6
  17.    >>> random.seed(101)
  18.    >>> singleQueue(5, 3)
  19.    6
  20.    >>> random.seed(935)
  21.    >>> singleQueue(10, 9, 280)
  22.    10
  23.    >>> type(singleQueue(10, 9, 280))
  24.    <class 'int'>
  25.    """
  26.     #Sets the initial variables to correct starting point.
  27.     c = 0
  28.     ta = 0
  29.     ts = 0
  30.     Q = 1
  31.     maxQ = 0
  32.  
  33.     #Used to loop the first clause of the alogrithim until c < simTime is no.
  34.     while c < time:
  35.         #Asks if ta < ts to allow the code to follow the correct path.
  36.         if ta < ts:
  37.             #The code will go down the 'left path' updating all information and variables.
  38.             ts = ts - ta
  39.             c = c + ta
  40.             Q = Q + 1
  41.             #Used to update the max length of the queue.
  42.             if Q >maxQ:
  43.                 maxQ = Q
  44.             #Update a random time for the next customer arrival.
  45.             ta = nextTime(alpha)
  46.         else:
  47.             #Similair to the 'if' statement, however goes down the 'right path'.
  48.             ta = ta - ts
  49.             c = c + ts
  50.             Q = Q - 1
  51.             #Update the time to be served.
  52.             ts = nextTime(beta)
  53.         #To fulfill the final conditions of Q = 0?
  54.         while Q == 0:
  55.             c = c + ta
  56.             Q = Q + 1
  57.             if Q > maxQ:
  58.                 maxQ = Q
  59.             ta = nextTime(alpha)
  60.     return maxQ
  61.  
  62.  
  63.  
  64. def doubleQueue(alpha, beta, time=480):
  65.     ta = 0
  66.     ts1 = 0
  67.     ts2 = 0
  68.     c = 0
  69.     maxQ = 0
  70.     Q = 1
  71.     while c < time:
  72.         if ta < ts1 and ta < ts2:
  73.             ts = ts - ta
  74.             ts2 = ts2 - ta
  75.             c = c + ta
  76.             Q = Q + 1
  77.             if Q > maxQ:
  78.                 maxQ = Q
  79.             ta = nextTime(alpha)
  80.         else:
  81.             if ts1 < ts2:
  82.                 ta = ta - ts1
  83.                 ts2 = ts2 - ts1
  84.                 c = c + ts1
  85.                 Q = Q - 1
  86.                 ts1 = nextTime(beta)
  87.             else:
  88.                 ta = ta - ts2
  89.                 ts1 = ts1 - ts2
  90.                 c = c + ts1
  91.                 Q = Q - 1
  92.                 ts2 = nextTime(beta)
  93.         while Q == 0:
  94.             c = c + ta
  95.             Q = Q + 1
  96.             if Q > maxQ:
  97.                 maxQ = Q
  98.             ta = nextTime(alpha)
  99.     return maxQ
  100.  
  101. #3b:
  102.  
  103. #Plot points on a graph
  104. #Assign graph parameters
  105. plt.title('The relationship between the introduction of a second teller and maximum queue times')
  106. plt.ylabel('Max Queue length')
  107. plt.xlabel('Alpha / Beta values')
  108. #Declare required vars
  109. alphavars = npy.arange(1.1,10,0.1)
  110. betavars = npy.arange(1,0,-0.1)
  111. b = 1
  112. plotpoints =[]
  113.  
  114. for a in alphavars:
  115.         maxQ_value = 0
  116.         for i in range(100):
  117.             maxQ_value += singleQueue(a,b)
  118.         plotpoints.append(maxQ_value / 100)
  119.         b = b-0.1
  120. plt.plot(alphavars,plotpoints,label ="Unaltered Queue")
  121.  
  122. for a in alphavars:
  123.         maxQ_value = 0
  124.         for i in range(100):
  125.             maxQ_value += doubleQueue(a,b)
  126.         plotpoints.append(maxQ_value / 100)
  127.         b = b-0.1
  128. plt.plot(alphavars,plotpoints,label ="Double Queue")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement