Question
Please fix if (time
Please fix "if (time
import java.util.LinkedList;
import java.util.Queue;
import java.util.Random;
public class MM1Queue {
private static final double LAMBDA = 10; // arrival rate
private static final double RHO = MU / LAMBDA; // traffic intensity
private static final int NUM_CUSTOMERS = 10000;
private static final double MU = 8; // service rate
public static void main(String[] args) {
Queue
Random random = new Random();
double totalWaitTime = 0;
double totalIdleTime = 0;
double time = 0;
int customersServed = 0;
// Trace the first 30 customers
System.out.println("Clock Time\tFuture Events\tDelayed List");
int traceCustomers = 0;
while (customersServed < NUM_CUSTOMERS) {
// Check if there's an arrival
if (time < NUM_CUSTOMERS / LAMBDA) {
queue.offer(time + (1 / LAMBDA) * random.nextDouble());
time = queue.peek();
}
// Check if the server is idle
if (!queue.isEmpty()) {
double arrivalTime = queue.poll();
totalWaitTime += time - arrivalTime;
time += (1 / MU) * random.nextDouble();
customersServed++;
} else {
totalIdleTime += (NUM_CUSTOMERS / LAMBDA - time);
time = NUM_CUSTOMERS / LAMBDA;
}
// Trace the first 30 customers
if (traceCustomers < 30) {
System.out.println(String.format("%.2f\t\t%.2f\t\t%d", time, time + (1 / MU), queue.size()));
traceCustomers++;
}
}
System.out.println(" Average queue length: " + (totalWaitTime / NUM_CUSTOMERS));
System.out.println("Average server idle time: " + (totalIdleTime / NUM_CUSTOMERS));
}
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started