Airport Problem Simulation
Airport Problem Simulation
Airport Problem Simulation
Entities: The following are the entities of the given system Airport Runway
Planes
Events: The following are the events that can occur in the given system Takeoff
Landing
System States: The states that can be changed by the given events are Number of Aeroplanes in the Landing queue
Number of Aeroplanes in the Takeoff queue
Status of the Runway (Busy/Idle)
State Variables: The following are the state variables for the given system
Start
End
Start
Runway idle?
Stop
Stop Simulation
Landing Event- When the airplane arrives, check the runway status. If
the runway status is idle, then update the runway status to busy.
Otherwise, that airplane waits in the queue, so the number of airplane in
the queue increases one and store the arrival time to the list of arrival
time.
Start
Runway idle?
Stop
Stop Simulation
Event occur routine- Call the timing routine to move the clock to the
event. Update the area under Q(t), B(t), and time of last event. If the next
is arrival, call function take-off(), else call function landing().
Is runway busy?
Event type = 0?
Generate next arrival time for airplane take-off routine- This routine
is to generate next arrival time randomly.
Generate next arrival time for airplane landing routine- This routine
is to generate next departure time randomly.
Report routine- The report shows about time of simulation end, mean of
airplanes in queue, mean of delay time, and the percentage of runway
utilisation.
struct plane
{
int id ;
int tm ;
};
struct queue
{
int count ;
int front ;
int rear ;
}
( pq -> count )++ ;
struct airport
{
struct queue landing ;
struct queue takeoff ;
struct queue *pl ;
struct queue *pt ;
int idletime ;
int landwait, takeoffwait ; // mean calculations
int nvarianceland , nvariancetakeoff; // variance calculations
int nland, nplanes, nrefuse, ntakeoff ;
struct plane pln ;
};
if ( wish == 1 )
flag = 0 ;
else
{
if( wish == 0 )
flag = 1 ;
}
}
else
flag = 1 ;
}
} while ( flag == 0 ) ;
}
switch ( action )
{
case ARRIVE :
printf ( "\n" ) ;
printf ( "Plane %d ready to land.\n", ap -> nplanes ) ;
break ;
case DEPART :
printf ( "\nPlane %d ready to take off.\n", ap -> nplanes ) ;
break ;
}
}
case DEPART :
if ( endtime > 0 )
printf ( "\tPercentage of time runway idle: %lf \n", ( ( double ) ap ->
idletime / endtime ) * 100.0 ) ;
em = exp ( -expectedvalue ) ;
x = rand( ) / ( double ) INT_MAX ;
while ( x > em )
{
n++ ;
x *= rand( ) / ( double ) INT_MAX ;
}
return n ;
}
case't' :
addqueue ( ap -> pt, ap -> pln ) ;
break ;
}
}
case't' :
p1 = delqueue ( ap -> pt ) ;
break ;
}
return p1 ;
}
case't' :
return ( size ( *( ap.pt ) ) ) ;
return 0 ;
}
case't' :
return ( full ( *( ap.pt ) ) ) ;
}
return 0 ;
}
case't' :
return ( empty ( *( ap.pt ) ) ) ;
}
return 0 ;
}
void myrandomize( )
{
srand ( ( unsigned int ) ( time ( NULL ) % 10000 ) ) ;
}
int main( )
{
airport a ;
int i, pri, curtime, endtime ;
double expectarrive, expectdepart ;
plane temp ;
if ( ! ( apempty ( a, 'l' ) ) )
{
temp = apdelqueue ( &a, 'l' ) ;
land ( &a, temp, curtime ) ;
}
else
{
if ( ! ( apempty ( a, 't' ) ) )
{
temp = apdelqueue ( &a, 't' ) ;
fly ( &a, temp, curtime ) ;
}
else
idle ( &a, curtime ) ;
}
}
Output: