Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- time += incLength; // increment time
- double lambda = avgGrocPerMin * incLength;
- Random rand = new Random();
- // loop through each queue
- for (int i = 0; i < lines.length; i++) {
- if (lines[i].isEmpty()) { // skip empty queues
- continue;
- }
- // loop to find number of groceries processed in interval
- int k = 0;
- double prob = rand.nextDouble();
- while (true) {
- // calc probability of exactly k groceries during interval (Poisson dist.)
- double probK = Math.pow(lambda, k) * Math.exp(-lambda) / factorial(k);
- if (probK <= prob) { // increment k until cumulative probability, prob, reached
- k++;
- prob -= probK;
- } else {
- break;
- }
- }
- while (!lines[i].isEmpty() && k > 0) {
- lines[i].decFront(); // decrement grocery count
- k--;
- }
- }
- this.display();
- } double probK = Math.pow(lambda, k) * Math.exp(-lambda) / factorial(k);
- if (probK <= prob) { // increment k until cumulative probability, prob, reached
- k++;
- prob -= probK;
- } else {
- break;
- }
- }
- while (!lines[i].isEmpty() && k > 0) {
- lines[i].decFront(); // decrement grocery count
- k--;
- }
- }
- this.display();
- }
Add Comment
Please, Sign In to add comment