Advertisement
Guest User

Little Allocation, v0.1

a guest
Sep 22nd, 2013
50
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Little's law, the traffic intensity in an M/M/c queue
  2. # Parameters:
  3. #   lam: lambda, the poisson parameter
  4. #   mu : mu/W, the average time spent in the queue/using the server/product
  5. def Little(lam, mu):
  6.     return ceil(lam * mu)
  7.  
  8. # Erlang-C function, the probability that a user must queue
  9. # Parameters
  10. #   c  : the number of queues/servers/products
  11. #   rho: the average load of each queue/server/product
  12. def E_2c(c,rho):
  13.     crho = c * rho
  14.     a = crho**c / factorial(c)
  15.     b = 1 / (1 - rho)
  16.     var('k')
  17.     d = sum( crho** k / factorial(k), k, 0, c-1)
  18.     ab = a * b
  19.     return ab / (d+ab)
  20.  
  21. # Expected exploitation
  22. # Find the expected number of users in system
  23. # Parameters:
  24. #   c  : the number of queues/servers/products
  25. #   rho: the average load of each queue/server/product
  26. def Expe_t(c,rho):
  27.     a = rho / (1-rho)
  28.     return a*E_2c(c,rho)+(c*rho)
  29.  
  30. # Little Allocation by Probability for an M/M/c queue
  31. # Find the number of queues/servers/products needed to ensure the following conditions:
  32. #   *the probability of queueing is less than p_q.
  33. # Parameters
  34. #   lam: lambda, the poisson parameter
  35. #   mu : the average time spent in the queue/using the server/product
  36. #   n  : the number of users interacting with the system
  37. #   p_q: the probability that the user will have to wait in the queue/for the server/product
  38. def Little_alloc_p(lam,mu,n,p_q):
  39.     L = Little(lam,mu) #traffic intensity
  40.     c = L + 1
  41.     rho = L / c
  42.     p = E_2c(c,rho)
  43.     while p_q < p:
  44.         c = c + 1 #a more advanced method should be used for large values of c
  45.         rho = L / c
  46.         p = E_2c(c,rho)
  47.     return c
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement