Write a queuing simulation for a small airport which has only one runway. Airpla
ID: 3752468 • Letter: W
Question
Write a queuing simulation for a small airport which has only one runway. Airplanes waiting to take off join a queue on the ground. Airplanes waiting to land join a queue in the air. Only one plane can be on the runway at a time. All planes in the air must land before any plane can take off. The amount of time to land a plane is constant. The amount of time for a plane to takeoff is also constant, not necessarily the same time as a landing. The algorithm on the back of this page and the class WaitLine which was emailed to you are a good start point for the algorithm Parameters Time to land a plane Time for takeoff Arrival rate for planes landing Arrival rate for planes taking off Length of time to be simulated. Output: Number of planes landed Number of plane that took off Average time a plane waited to take off Average time a plane waited to land Number of planes still waiting to take off Number of planes still waiting to landExplanation / Answer
public class Runway<E> {
private LinkedBlockingQueue<Plane> takeoff;
private LinkedBlockingQueue<Plane> landing;
private LinkedBlockingQueue<Plane> runway;
private int planesLanded;
private int planesTookoff;
private double averageTakeOffWait;
private double averageLandWait;
private int totalTakeoffWait;
private int totalLandingWait;
private int planesWaitingToTakeOff;
private int planesWaitingToLand;
private int maxLandingQueueLength;
private int maxTakeOffQueueLength;
public int timeToLand = 5;
public int timeToTakeoff = 4;
public double landingProbability = .1;
public double takeOffProbability = .1;
public int simulationLength = 1440;
public Runway() {
takeoff = new LinkedBlockingQueue<>();
landing = new LinkedBlockingQueue<>();
runway = new LinkedBlockingQueue<>();
planesLanded = 0;
planesTookoff = 0;
averageTakeOffWait = 0;
averageLandWait = 0;
totalTakeoffWait = 0;
totalLandingWait = 0;
planesWaitingToTakeOff = 0;
planesWaitingToLand = 0;
maxLandingQueueLength = 0;
maxTakeOffQueueLength = 0;
//reset();
}
public void simulate(int duration, double takeoffRate, double landingRate, int landingTime, int takeoffTime) {
for(int count = 0; count < duration; count++) {
if(Math.random() < takeoffRate) {
Plane p = new Plane(landingTime, takeoffTime, count);
takeoff.offer(p);
}
if(Math.random() < landingRate) {
Plane p = new Plane(landingTime, takeoffTime, count);
landing.offer(p);
}
if(runway.size() == 0) {
if(landing.peek() != null) {
Plane landingPlane = landing.poll();
runway.offer(landingPlane);
planesLanded++;
int landTimeWaited = count - landingPlane.getArrivalTime();
totalLandingWait += landTimeWaited;
runway.poll();
} else if(takeoff.peek() != null) {
Plane takeoffPlane = takeoff.poll();
runway.offer(takeoffPlane);
planesTookoff++;
int takeoffTimeWaited = count - takeoffPlane.getArrivalTime();
totalLandingWait += takeoffTimeWaited;
runway.poll();
}
}
}
}
public void report() {
System.out.println(planesLanded + " planes have landed.");
System.out.println(planesTookoff + " planes have taken off.");
System.out.println(landing.size() + " planes still waiting to land.");
System.out.println(takeoff.size() + " planes still waiting to takeoff.");
System.out.println(1.0*totalTakeoffWait/planesTookoff + " average take off wait time.");
System.out.println(1.0*totalLandingWait/planesLanded + " average landing wait time.");
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.