Guest User

Untitled

a guest
Feb 16th, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 KB | None | 0 0
  1. time += incLength; // increment time
  2.  
  3. double lambda = avgGrocPerMin * incLength;
  4. Random rand = new Random();
  5.  
  6. // loop through each queue
  7. for (int i = 0; i < lines.length; i++) {
  8.  
  9. if (lines[i].isEmpty()) { // skip empty queues
  10. continue;
  11. }
  12.  
  13. // loop to find number of groceries processed in interval
  14. int k = 0;
  15. double prob = rand.nextDouble();
  16. while (true) {
  17. // calc probability of exactly k groceries during interval (Poisson dist.)
  18. double probK = Math.pow(lambda, k) * Math.exp(-lambda) / factorial(k);
  19. if (probK <= prob) { // increment k until cumulative probability, prob, reached
  20. k++;
  21. prob -= probK;
  22. } else {
  23. break;
  24. }
  25. }
  26.  
  27. while (!lines[i].isEmpty() && k > 0) {
  28. lines[i].decFront(); // decrement grocery count
  29. k--;
  30. }
  31. }
  32. this.display();
  33. } double probK = Math.pow(lambda, k) * Math.exp(-lambda) / factorial(k);
  34. if (probK <= prob) { // increment k until cumulative probability, prob, reached
  35. k++;
  36. prob -= probK;
  37. } else {
  38. break;
  39. }
  40. }
  41.  
  42. while (!lines[i].isEmpty() && k > 0) {
  43. lines[i].decFront(); // decrement grocery count
  44. k--;
  45. }
  46. }
  47. this.display();
  48. }
Add Comment
Please, Sign In to add comment