Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Please help me with this question. In Java. TIA Modify MM1Queue.java to make a program MD1Queue.java that simulates a queue for which the service times
Please help me with this question. In Java. TIA
Modify MM1Queue.java to make a program MD1Queue.java that simulates a queue for which the service times are fixed (deterministic) at rate . Verify Little's law for this model.
public class MM1Queue { public static void main(String[] args) { double lambda = Double.parseDouble(args[0]); // arrival rate double mu = Double.parseDouble(args[1]); // service rate Queuequeue = new Queue (); // arrival times of customers double nextArrival = StdRandom.exp(lambda); // time of next arrival double nextDeparture = Double.POSITIVE_INFINITY; // time of next departure // double expectedWait = 1.0 / (mu - lambda); // W = expected time in system double totalWait = 0.0; long customersServiced = 0; // histogram object Histogram hist = new Histogram(60 + 1); StdDraw.setCanvasSize(1000, 600); StdDraw.enableDoubleBuffering(); // simulate an M/M/1 queue while (true) { // it's an arrival if (nextArrival <= nextDeparture) { if (queue.isEmpty()) nextDeparture = nextArrival + StdRandom.exp(mu); queue.enqueue(nextArrival); nextArrival += StdRandom.exp(lambda); } // it's a departure else { double wait = nextDeparture - queue.dequeue(); hist.addDataPoint(Math.min(60, (int) (Math.round(wait)))); totalWait += wait; customersServiced++; StdDraw.clear(); hist.draw(); StdDraw.show(); StdDraw.pause(30); if (queue.isEmpty()) nextDeparture = Double.POSITIVE_INFINITY; else nextDeparture += StdRandom.exp(mu); } } } }
----------------------------------------------------------------------------------------------------------------------------------
public class MD1Queue { public static void main(String[] args) { double lambda = Double.parseDouble(args[0]); // arrival rate double mu = Double.parseDouble(args[1]); // service rate Histogram hist = new Histogram(60 + 1); Queuequeue = new Queue (); StdDraw.setCanvasSize(700, 500); StdDraw.enableDoubleBuffering(); double nextArrival = StdRandom.exp(lambda); // time of next arrival double nextService = nextArrival + 1/mu; // time of next completed service // simulate the M/D/1 queue while (true) { // next event is an arrival while (nextArrival < nextService) { queue.enqueue(nextArrival); nextArrival += StdRandom.exp(lambda); } // next event is a service completion double arrival = queue.dequeue(); double wait = nextService - arrival; // update the histogram StdDraw.clear(); hist.addDataPoint(Math.min(60, (int) (Math.round(wait)))); hist.draw(); StdDraw.show(); StdDraw.pause(20); // update the queue if (queue.isEmpty()) nextService = nextArrival + 1/mu; else nextService = nextService + 1/mu; } } }
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