Please use c++ to write this program Objectives Design and implement a discrete
ID: 3712425 • Letter: P
Question
Please use c++ to write this program
Objectives
Design and implement a discrete event simulation
Choose and implement appropriate data structures
Adapt standard algorithms to a specific problem
Task
Consider the scenario of a license service center. Suppose two services are provided: applying for a new license (Service 1) and renewing an existing license (Service 2). There are three counters (1-3) for Service 1 and three counters (4-6) for Service 2. The customers are categorized based on the type of service they are asking for and each customer is given a ticket number. Each counter serves the customers asking for that particular service, following the order of their ticket numbers. If at the moment there is no customer for that service, the corresponding counter will help serve the customers asking for the other service. For example, Counters 1-3 serve the available customers asking for Service 1; if there is no customer for Service 1, Counter 1-3 help serve the customers asking for Service 2; and vice versa.
Please write a single program which simulates the queuing and service of the customers in this license service center.
Program
Your program should choose theproperqueuestrategyandrun discrete event simulation. The simulation should start at time 0 and run until all customers have been served. Your program should be readable and well commented.
Data Structures and Algorithms
Part of the purpose of this subject is to gain an in-depth understanding of data structures and algorithms. As
such, all programming tasks in this subject require you to choose appropriate data structures and algorithms, and to implement them yourself. You may not take advantage of any built in data structures more complex than an array, but instead should provide your own implementation. The use of STL, Java Collection, or any collection framework in your language of choice, is disallowed. If you use any references other than the lecture notes, ensure you cite them or you may receive 0 for plagiarism. A clear comment in your code is sufficient.
Readme
Write a text file named readme. Include clear instructions on how to compile and run your algorithm. Ensure that your program compiles and runs correctly . If your program does not compile, it will receive 0 marks. If it doesn’t run according to the specification, you will receive very few marks. You may also include a makefile if you wish.
Analysis
Write a file named analysis.pdf explaining the queue strategy and the data structures that you use in your code.
Input
Your program should read a file name from standard input, and run the simulation using the named file as the input file.
The input file has the following format:
The number of servers.
A set of lines each consisting of a customer arrival time followed by the corresponding service time, followed by the service type (1 or 2).
Times are in seconds, from the start of the simulation. Although a sample input file has been provided, your program should still run successfully on substantially larger inputs.
Output
Output should be to standard output.
The output should consist of the following data, clearly labelled:
Number of people served for each server.
Time that the last customer finished being served (total simulation time) for each server.
Average time a customer spends in queue.
Maximum time a customer spends in queue.
Maximum Length of queue.
Total idle time for each server.
the input.txt sample
6
0 351 1
128 511 2
351 309 1
457 383 2
510 313 2
567 329 2
1002 547 2
1412 508 2
1518 395 1
1747 585 1
1968 310 1
2276 431 2
2359 414 1
2360 529 2
2443 538 2
2675 356 2
2727 446 2
2851 433 2
2881 493 2
2933 512 2
3056 526 1
3260 382 1
3288 503 2
3296 496 2
3362 348 2
3445 335 2
3447 449 1
3454 587 2
3473 402 2
3494 475 1
Explanation / Answer
To write the program, we need to proceed as follows.
#include<iostream.h>
#include<cmath.h>
#include<conio.h>
#include <lcgrand.h>
// to define the initial size of the Queue for initial parameter.
const int Queu_Limit=100;
const int BUSY=1;
const int IDLE=0;
int choice, Num_Completed_Customers, Number_of_Events, Number_in_Queue, Server_Status;
double End_Time, Type_Next_Event, Mean_interArrival_Time, Mean_service_Time, Clock, Time_Arrival[Queu_Limit + 1], Service_Time[Queu_Limit + 1], Next_Arrival_Time, Next_Completion_Time, Next_Service_Time, Total_Flow_Time, Progres_Arrival_Time, Progres_Completion_Time, Waiting_Time;
// Prototype of the given system of the System Function
void initialize();
void Timing();
void Arrival();
void Completition();
float expon(float mean);
void Search_Min(double[],double[]);
// Starting of function
int main()
{
initialize(); // Intialization of the System
cout<<" * Single-server queueing system with fixed run * ";
cout<<" _________________________________________________"<<endl;
cout<<" 1.First In First Out"<<endl;
cout<<" 2.Minimum Processing Time"<<endl<<endl;
do
{
cout<<" Enter your Policy: ";
cin>>choice;
}while(choice>2||choice<1);
cout<<" Mean Inter arrival Time: "<<Mean_interArrival_Time;
cout<<" Mean Service Time: "<<Mean_service_Time<<endl;
cout<<"The End of Simulation Time: "<<End_Time<<endl<<endl;
while(true)
{
Timing(); // Timing Routine To Determine The Next Event
if(Clock>End_Time)
break;
switch (int(Type_Next_Event))
{
case 1:
Arrival();
break;
case 2:
Completition();
break;
}
}
// Print Summary result of the above cases.
cout<<" Total Flow Time: "<<Total_Flow_Time;
cout<<" Total Waiting Time in Queue: "<<Waiting_Time;
cout<<" Average Waiting Time in Queue: "<<Waiting_Time / Num_Completed_Customers;
cout<<" Average Flow Time: "<<Total_Flow_Time / Num_Completed_Customers;
cout<<" Number of Completed Customers: "<<Num_Completed_Customers;
cout<<" Average Number of Customers In System / Unit Time: "<<Num_Completed_Customers / Clock<<endl<<endl;
return 0;
}
void initialize()
{
Number_of_Events = 2;
Mean_interArrival_Time=1.0;
Mean_service_Time=0.5;
End_Time=100.0;
Clock = 0.0;
Server_Status = IDLE;
Number_in_Queue = 0;
Num_Completed_Customers = 0;
Total_Flow_Time = 0.0;
Waiting_Time = 0.0;
Next_Arrival_Time = Clock + expon(Mean_interArrival_Time);
Next_Service_Time = expon(Mean_service_Time);
Next_Completion_Time = 1.0e+10; // Completing Guarantening that the first event is arriving
Progres_Arrival_Time=0.0;
Progres_Completion_Time = 0.0;
}
void Timing()
{
Type_Next_Event = 0;
if(Next_Arrival_Time < Next_Completion_Time)
{
Type_Next_Event = 1;
Clock=Next_Arrival_Time;
}
else
{
Type_Next_Event = 2;
Clock = Next_Completion_Time;
}
if (Type_Next_Event == 0)
{
cout<<" Event List Empty at Time: "<<Clock;
exit(1);
}
}
// code for Customer function
void Arrival()
{
if (Server_Status == BUSY)
{
++Number_in_Queue;
if (Number_in_Queue > Queu_Limit)
{
cout<<" Overflow of the array time_arrival at";
cout<<"time: "<<Clock;
exit(2);
}
Time_Arrival[Number_in_Queue] = Clock;
Service_Time[Number_in_Queue] = Next_Service_Time;
}
else
{
Server_Status = BUSY;
Next_Completion_Time = Clock + Next_Service_Time;
Progres_Arrival_Time = Next_Arrival_Time;
Progres_Completion_Time = Next_Completion_Time;
}
Next_Arrival_Time = Clock + expon(Mean_interArrival_Time);
Next_Service_Time = expon(Mean_service_Time);
}
// When the Customer comlete the task then we use the Function
void Completition()
{
double Delay;
++Num_Completed_Customers;
Total_Flow_Time+= ( Progres_Completion_Time - Progres_Arrival_Time );
if (Number_in_Queue == 0)
{
Server_Status= IDLE;
Next_Completion_Time = 1.0e+10; // High Value
}
else
{
if(choice==2)
Search_Min(Time_Arrival,Service_Time); // Minimum Processing Time
Delay= Clock - Time_Arrival[1];
Waiting_Time+= Delay;
Next_Completion_Time = Clock + Service_Time[1];
Progres_Arrival_Time = Time_Arrival[1];
Progres_Completion_Time = Next_Completion_Time;
--Number_in_Queue;
for (int i=1;i<=Number_in_Queue;i++)
{
Time_Arrival[i] = Time_Arrival[i + 1];
Service_Time[i] = Service_Time[i + 1];
}
}
}
//Sort Function to finalize the output.
void Search_Min(double A_time[],double S_time[])
{
int Min=1;
double temp;
for(int i=1;i<Number_in_Queue;i++)
if(S_time[Min]>S_time[i+1])
Min=i+1;
temp=S_time[1];
S_time[1]=S_time[Min];
S_time[Min]=temp;
temp=A_time[1];
A_time[1]=A_time[Min];
A_time[Min]=temp;
}