The subject of this programming assignment is to run a simul
The subject of this programming assignment is to run a simulation of waiting queues. we consider, for example, the queues of passengers at a check-in counter of an airline.
- we have two classes of service: coach and first class.
- there is one queue for each class of service
- there are three coach check-in stations and two first-class stations
- each class of service is characterized by two parameters: rate of arrival of passengers, and average length of service (for example: we have one first-class passenger every three minutes on average, and each first class passenger requires an average of eight minutes of service).
- The input to the simulation is: the average rate of arrival and the average rate of service of each class of service, as well as the length of simulation (in minutes) and whether the simulation ends abruptly or when all queues and stations are flushed out.
- The output of the simulation is any type of metrics you may be interested to collect, such as (for each class of service): max waiting time, average waiting time, rate of occupancy of service stations, average length of waiting queues, max length of waiting queues, number of passengers served, number of unserved passengers at the end of the simulation (if an abrupt end). you may, if you like, illustrate the evolution of the queue in real time.
design hints: - you define your own time variable; just use an integer. DO NOT use the system time nor real-time. - define a queue ADT and use it/ instantiate it to implement the waiting queues. - make the program as simple as possible.
Solution
Note: Programming language is not specified, solution is prepared in C# language
The C# program code is shown below:
//Include libraries
using System;
using System.Collections;
using System.Collections.Generic;
//Define class Airline
public class Airline
{
//Define main method
public static void Main(string[] args)
{
// Declare variables
int lpassengerNumber = 0;
//Define object
object lremovedObject = null;
//Define a queue for firts class
Queue lqueueFirstClass = new Queue();
//Define a queue for coach
Queue lqueueCoach = new Queue();
//Declare variable
int passengerArrivalTime;
//Define lrandomPassengerArrivalTime
Random lrandomPassengerArrivalTime = new Random();
//Define lrandomPassengerType
Random lrandomPassengerType = new Random();
//Declare variables
double averageArrivalRateFirstClassR1;
double averageArrivalRateCoachR2;
int experimentDurationInMinutes;
int lpassengersTotalServiceTime = 0;
int maximumServiceTimeFirstClass;
int maximumServiceTimeCoach;
//Define lrandomServiceTime
Random lrandomServiceTime = new Random();
//Declare variable
int serviceTime;
//Define queue for classes
Queue lserviceStation1FirstClass = new Queue();
Queue lserviceStation2FirstClass = new Queue();
//Define queue for coaches
Queue lserviceStation1Coach = new Queue();
Queue lserviceStation2Coach = new Queue();
Queue lserviceStation3Coach = new Queue();
//Declare variables
float averageServiceTime;
float lmaximumServiceTime;
int numbersServedInFirstClass;
int numbersServedInCouch;
int maximumQueueLengthFirstClassPassenger;
int maximumQueueLenghtCouchPassesnger;
// Get experiment duration from user
Console.Write(\"Enter experiment duration (in minutes): \");
experimentDurationInMinutes = Convert.ToInt32(Console.ReadLine());
//Get average arrival rate
Console.Write(\"\ \ Enter average arrival rate for First Class passengers: \");
averageArrivalRateFirstClassR1 = Convert.ToDouble(Console.ReadLine());
//Get average arrival rate
Console.Write(\"Enter average arrival rate for Coach passengers: \");
averageArrivalRateCoachR2 = Convert.ToDouble(Console.ReadLine());
// Display message
Console.Write(\"\ \ NOTE: First Class passengers has minimum service time of 1 minute\");
//Get service time for first class passengers.
Console.Write(\"\ Enter maximum service time for First Class passenger \");
maximumServiceTimeFirstClass = Convert.ToInt32(Console.ReadLine());
// Display message
Console.Write(\"\ \ Coach passengers has minimum service time of 1 minute\");
//Get service time for coach passengers
Console.Write(\"\ Enter maximum (S2) SERVICE TIME for Coach passenger (in minutes): \");
maximumServiceTimeCoach = Convert.ToInt32(Console.ReadLine());
//Loop until condition
while (lpassengersTotalServiceTime < experimentDurationInMinutes)
{
//Increment count
lpassengerNumber++;
//Generate random arrival time and place in queue
passengerArrivalTime = 1 + lrandomPassengerArrivalTime.Next(experimentDurationInMinutes);
//Generate passenger type
if (lrandomPassengerType.Next(1, 3) == 1)
{
//Load queue with information
lqueueFirstClass.Enqueue(\"Passenger \"+lpassengerNumber);
//If value is 1
if (maximumServiceTimeFirstClass == 1) serviceTime = 1;
//If value not 1
else
//Generate random service time
serviceTime = 1 + lrandomServiceTime.Next(maximumServiceTimeFirstClass);
//Set lpassengersTotalServiceTime
lpassengersTotalServiceTime = lpassengersTotalServiceTime + serviceTime;
//Load queue with second information
lqueueFirstClass.Enqueue(serviceTime);
//Load queue with third information
lqueueFirstClass.Enqueue(passengerArrivalTime);
}
//If its a coach passenger
else
{
//Load in queue with first information.
lqueueCoach.Enqueue(\"Passenger \" + lpassengerNumber);
//If value is 1
if (maximumServiceTimeCoach == 1)
//Set value
serviceTime = 1;
//If value not 1
else
//Generate random service time
serviceTime = 1 + lrandomServiceTime.Next(maximumServiceTimeCoach);
//Set lpassengersTotalServiceTime
lpassengersTotalServiceTime = lpassengersTotalServiceTime + serviceTime;
//Load in queue with second information.
lqueueCoach.Enqueue(serviceTime);
//Load in queue with third information.
lqueueCoach.Enqueue(passengerArrivalTime);
}
}
//Define maximum queue length
maximumQueueLengthFirstClassPassenger = (lqueueFirstClass.Count) / 3;
//Define maximum queue length
maximumQueueLenghtCouchPassesnger = (lqueueCoach.Count) / 3;
//Loop until length
for (int passengerCounter = lpassengerNumber; passengerCounter >= 1; passengerCounter--)
{
//If service station count is 0 and queue is non empty
if ((lserviceStation1FirstClass.Count == 0) && (lqueueFirstClass.Count != 0))
{
for (int lcounter = 3; lcounter >= 1; lcounter--)
lserviceStation1FirstClass.Enqueue(lremovedObject = lqueueFirstClass.Dequeue());
}
//If service station count is 0 and queue is non empty
else if ((lserviceStation2FirstClass.Count == 0) && (lqueueFirstClass.Count != 0))
{
for (int lcounter = 3; lcounter >= 1; lcounter--)
lserviceStation2FirstClass.Enqueue(lremovedObject = lqueueFirstClass.Dequeue());
}
//If service station count is 0 and queue is non empty
else if ((lserviceStation1Coach.Count == 0) && (lqueueCoach.Count != 0))
{
for (int lcounter = 3; lcounter >= 1; lcounter--)
lserviceStation1Coach.Enqueue(lremovedObject = lqueueCoach.Dequeue());
}
else if ((lserviceStation2Coach.Count == 0) && (lqueueCoach.Count != 0))
{
for (int lcounter = 3; lcounter >= 1; lcounter--)
lserviceStation2Coach.Enqueue(lremovedObject = lqueueCoach.Dequeue());
}
//If service station count is 0 and queue is non empty
else if ((lserviceStation3Coach.Count == 0) && (lqueueCoach.Count != 0))
{
for (int lcounter = 3; lcounter >= 1; lcounter--)
lserviceStation3Coach.Enqueue(lremovedObject = lqueueCoach.Dequeue());
}
//If service station count is 0 and queue is non empty
else if (((lserviceStation1FirstClass.Count == 0) && (lqueueFirstClass.Count == 0)) && (lqueueCoach.Count != 0))
{
for (int lcounter = 3; lcounter >= 1; lcounter--)
lserviceStation1FirstClass.Enqueue(lremovedObject = lqueueCoach.Dequeue());
}
//If service station count is 0 and queue is non empty
else if (((lserviceStation2FirstClass.Count == 0) && (lqueueFirstClass.Count == 0)) && (lqueueCoach.Count != 0))
{
for (int lcounter = 3; lcounter >= 1; lcounter--)
lserviceStation2FirstClass.Enqueue(lremovedObject = lqueueCoach.Dequeue());
}
}
//Display message
Console.WriteLine(\"\ \ STATISTICS GENERATED BY SIMULATION:\");
//Dispaly results
averageServiceTime = (float)lpassengersTotalServiceTime / (float)lpassengerNumber;
Console.WriteLine(\"\ \ AVERAGE SERVICE TIME= {0}\", averageServiceTime);
if (maximumServiceTimeFirstClass >= maximumServiceTimeCoach)
lmaximumServiceTime = maximumServiceTimeFirstClass;
else
lmaximumServiceTime = maximumServiceTimeCoach;
Console.WriteLine(\"\ \ MAXIMUM SERVICE TIME= {0}\", lmaximumServiceTime);
numbersServedInFirstClass = ((lserviceStation1FirstClass.Count) / 3) + ((lserviceStation2FirstClass.Count) / 3);
Console.WriteLine(\"\ \ NUMBERS SERVED FOR FIRST CLASS= {0}\", numbersServedInFirstClass);
numbersServedInCouch = ((lserviceStation1Coach.Count) / 3) + ((lserviceStation1Coach.Count) / 3) + ((lserviceStation3Coach.Count) / 3);
Console.WriteLine(\"\ \ NUMBERS SERVED FOR COACH= {0}\", numbersServedInCouch);
Console.WriteLine(\"\ \ MAXIMUM QUEUE LENGTH FOR FIRST CLASS= {0}\", maximumQueueLengthFirstClassPassenger);
Console.WriteLine(\"\ \ MAXIMUM QUEUE LENGTH FOR COACH= {0}\", maximumQueueLenghtCouchPassesnger);
Console.WriteLine(\"\ \ \");
}
}
Sample Output:
sh-4.3$ mono main.exe
Enter experiment duration (in minutes): 20
Enter average arrival rate for First Class passengers: 18
Enter average arrival rate for Coach Passengers: 17
NOTE: First Class passengers has minimum service time of 1 minute
Enter maximum service time for First Class passenger 13
Coach passengers has minimum service time of 1 minute
Enter maximum (S2) SERVICE TIME for Coach passenger (in minutes): 12
STATISTICS GENERATED BY SIMULATION:
AVERAGE SERVICE TIME= 6
MAXIMUM SERVICE TIME= 13
NUMBERS SERVED FOR FIRST CLASS= 1
NUMBERS SERVED FOR COACH= 3
MAXIMUM QUEUE LENGTH FOR FIRST CLASS= 1
MAXIMUM QUEUE LENGTH FOR COACH= 3







