this is my assignment question.
You must implement a simulation program to model air traffic among a collection of airports, as discussed in class. There are two important extensions that will be made to the model. First, in addition to arriving aircraft using the runway, departing aircraft must also use the same runway. If both arriving and departing aircraft are waiting to use the runway, it should be allocated to the aircraft that has been waiting the longest amount of time. Assume the amount of time a departing aircraft uses the runway follows the same distribution as an arriving aircraft. You should develop the appropriate queueing model abstraction for this system, and implement in with a simulation program.
Second, you will implement a network of airports rather than a single airport. Specifics of this system are described below.
1 Aircraft Behavior
The simulation contains N aircraft that are initially uniformly distributed among the airports. The number of aircraft does not change throughout the simulation. When the simulation starts each aircraft should schedule an initial departure event for itself with time selected from an exponential distribution with mean of 1 hour. Whenever a plane takes off it flies to a randomly selected airport from the possible destinations for the airport it is leaving, specified in the traffic network topology, as discussed below. An aircraft is equally likely to select any of the possible destinations. Run the simulation for 24 hours.
The amount of time to fly to a destination airport is uniformly distributed between 1.0 and 2.0 hours. Upon arrival, the plane must wait until the runway at the destination airport is free. Assume that once the plane has been cleared to land, it requires exclusive use of the runway for 2 minutes. Assume the amount of time spent on the ground is uniformly distributed between 0.75 and 1.5 hours.
Your simulator should compute the following statistics for each airport: (1) number of aircraft that landed during the simulation, (2) number of aircraft that departed during the simulation, and (3) average amount of time an aircraft had to wait for that airport’s runway when it arrived.
2 Air Traffic Network
The traffic network is specified as a graph, with nodes representing airports, and links representing possible flights. If aircraft can fly from airport i to airport j, then there is a link from node i to node j in the graph. A file input by your program specifies the network topology. The format for this file is a list of lines, one per nodes. Nodes are numbered 0, 1, … Each line lists (1) an airport number, and (2) a list of possible destination nodes for aircraft departing from that airport. For example, the file:
0 1 2
1 0
2 0
indicates aircraft departing from airport 0 may be destined for airport 1 or airport 2, and all aircraft departing from airport 1 and airport 2 always fly to airport 0. You may assume there are up to MAX_NODES airports in the simulation, and MAX_DESTINATIONS possible destinations (outgoing links) of any airport. MAX_NODES and MAX_DESTINATIONS should be defined as constants in your program.
3 Implementation
You will need to implement two parts:
• A simulation engine. This should include the pending event set implementation and a random number generator. The pending event set must be implemented using dynamic memory allocation (malloc and free). You are free to choose the random number generator and priority queue you wish to use, but you must implement these from scratch (as opposed to using a canned library). You will need to define and document and application programmer’s interface (API) that is used to develop the simulation model.
• A simulation model and graph generator. The graph generator is a program, completely independent of the simulator, that creates files of the specified format according to certain parameters that you specify (e.g., number of nodes, average node degree). The simulation model program must then read this file, create a network of the specified topology, and simulate the aircraft.
Assume simulation time is implemented as a double precision floating point number.
This is what I've done.But I was wondering am I on the right track.
I'm quites lost now.
And can we use random exponent?
I got problem in displayrunwaystatus,in fact the part where the exponent function is suppose to be random exponent.
#include <iostream>
#include <stdlib.h>
#include <iomanip>
#include <string>
#include <cmath>
using namespace std;
int *airplanes = NULL;
int size;
int flight_no[12];
string dest[20];
float dtime[10]; //departure time
float atime[10]; // arrival time
float ltime[10]; //landing time
int a;
float air;
float ground;
void menu(void)
{
cout <<"Airport Menu Options " <<endl;
cout <<endl;
cout <<"1 = Enter Flight Information" <<endl;
cout <<"2 = Display Flight Information" <<endl;
cout <<"3 = Display Runway Status" <<endl;
cout <<endl;
cout <<"0 = quit" <<endl;
cout <<endl;
}
void flightinformation(void)
{
cout <<"How many Flight Information you would like to key in : "<<endl;
cin >> size;
airplanes = new int[size];
for(a = 0; a < size; a++)
{
cout <<"Enter Flight information for " << airplanes[a] <<endl;
cout <<endl;
cout <<"Flight Number ";
cin >>flight_no[a];
cout <<"Destination ";
cin >>dest[a];
cout <<"Departure Time (in 24 Hours Mode) ";
cin >>dtime[a];
if(dtime[a]<0000 || dtime[a] >2400)
{
cout << "Error!"<<endl;
}
cout <<"Arrival Time(in 24 Hours Mode) ";
cin >>atime[a];
if(atime[a]<0000 || atime[a] >2400)
{
cout << "Error!"<<endl;
}
cout <<endl;
}
delete []airplanes;
}
void displayflightinfo(void)
{
cout <<" " <<left;
cout << setw(15) <<"Flight Number | "<<setw(13) <<"Destination | " <<setw(16)
<<"Departure Time | " <<"Arrival Time" <<endl;
cout <<endl;
for(int b = 0; b < size; b++)
{
cout <<left;
cout <<airplanes[b] <<" " <<setw(15) <<flight_no[b] <<" " <<setw(13) <<dest[b]
<<" " <<setw(16) <<dtime[b] <<" " <<atime[b];
cout <<endl;
}
system("pause");
}
void displayrunwaystatus(void)
{
cout <<"Enter a Plane number to check its status" <<endl;
int j;
cout <<"Plane ";
cin >>j;
for(int i=1;i >= atime[j];i++)
{
air = air + 1;
ltime[j] = atime[j] + (exp(1.5));
cout << "Landing Time : " << ltime[j] <<endl;
if(i==ltime[j])
{
cout << "Runway is occupied" << endl;
}
if(i>=ltime[j])
{
air = air - 1;
ground = ground + 1;
if(air > 0)
{
ltime[j] = i + exp(1.5);
}
else
cout << "Runway is free" <<endl;
ltime[j] = atime[j] + exp(1.5);
}
}
system("pause");
}
int main()
{
int a;
do
{
cout <<endl;
menu();
cin >> a;
cout <<endl;
switch(a)
{
case 1: flightinformation();
break;
case 2: displayflightinfo();
break;
case 3: displayrunwaystatus();
break;
}
}while (a!= 0);
return 0;
}