Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The simulation should pause after each minute\'s summary is outputted, enabling

ID: 3805991 • Letter: T

Question

The simulation should pause after each minute's summary is outputted, enabling the user to press ENTER to continue to the next minute. The simulation should end automatically after new arrivals stop arriving and the wait queue has been emptied and all servers become idle Here are the specs: struct customer: (1) an ID tag, (2) arrival time, (3) service end time. The ID tag for the customer is a single letter of the alphabet, A-Z, recursively Customers arrive at the specified average arrival rate from the beginning of the simulation until the specified clock time at which new arrivals stop. After that time there are no new arrivals, but the simulation continues, allowing the wait queue to empty and the servers to become idle Create the nowServing array of customer objects to represent the customers being served. (removed from the wait queue). Another corresponding array of boolean values, whose value is true if the server at that index position is busy serving a customer, false if the server is idle. (There's more than one way to accomplish this, so use a different way if you

Explanation / Answer

#include<iostream>

#include <cmath>

using namespace std;

const int Queu_Limit=100;

const int BUSY=1;

const int IDLE=0;

int choice, Num_Comp_Customers,Number_of_Events, Number_in_Queue,Server_Status;

double End_Time,Type_Next_Event,Mean_Arrival_Time,Mean_serv_Time,Clock,Time_Arrival[Queu_Limit + 1],Serv_Time[Queu_Limit + 1], Next_Arrival_Time,Next_Compl_Time,Next_Serv_Time, Total_Flow_Time,Progres_Arrival_Time,Progres_Comp_Time,Waiting_Time;

void initialize();

void Timing();

void Arrival();

void Comp();

float expon(float mean);

void Search_Min(double[],double[]);

int main()

{

initialize();           // System Intialization

cout<<" 1.FIFO"<<endl;

cout<<" 2.Min Processing Time"<<endl;

do

    {

    cout<<" Enter your CHOICE: ";

cin>>choice;

}while(choice>2||choice<1);

cout<<" Mean Inter arrival Time: "<<Mean_Arrival_Time;

cout<<" Mean Service Time: "<<Mean_serv_Time<<endl;

cout<<"The End of Simulation Time: "<<End_Time<<endl;

while(true)

    {

Timing(); // To Determine The Next Event

if(Clock>End_Time)

           break;

switch (int(Type_Next_Event))

        {

         

        case 1:Arrival();

            break;

case 2: Comp();

            break;

        }

    }

    cout<<" Total Flow Time: "<<Total_Flow_Time;

cout<<" Total Waiting Time in Queue: "<<Wait_Time;

cout<<" Average Waiting Time in Queue: "<<Wait_Time / Num_Comp_Customers;

cout<<" Average Flow Time: "<<Total_Flow_Time / Num_Comp_Customers;

cout<<" Number of Completed Customers: "<<Num_Comp_Customers;

cout<<" Average Number of Customers In System / Unit Time: "<<Num_Comp_Customers / Clock<<endl<<endl;

return 0;

}

void initialize()

{

Number_of_Events = 2;

    Mean_Arrival_Time=1.0;

Mean_serv_Time=0.5;

End_Time=100.0;

Clock = 0.0;

Server_Status = IDLE;

Number_in_Queue = 0;

Num_Comp_Customers = 0;

Total_Flow_Time = 0.0;

Wait_Time = 0.0;

Next_Arrival_Time = Clock + expon(Mean_Arrival_Time);

Next_Serv_Time = expon(Mean_serv_Time);

Next_Comp_Time = 1.0e+10;

Progres_Arrival_Time=0.0;

Progres_Comp_Time = 0.0;

}

void Timing()

{

    Type_Next_Event = 0;

if(Next_Arrival_Time < Next_Comp_Time)

    {

Type_Next_Event = 1;

Clock=Next_Arrival_Time;

}

else

    {

        Type_Next_Event = 2;

Clock = Next_Compl_Time;

}

if (Type_Next_Event == 0)

    {

        cout<<" Event List empty time "<<Clock;

exit(1);

    }      

}

void Arrival() {

    if (Server_Status == BUSY)

    {

        ++Number_in_Queue;

if (Number_in_Queue > Queu_Limit)

        {

            cout<<" Overflow of the array timearrival at" <<Clock;

exit(2);

        }

Time_Arrival[Number_in_Queue] = Clock;

Serv_Time[Number_in_Queue] = Next_Serv_Time;

}

else

    {

        Server_Status = BUSY;

Next_Comp_Time = Clock + Next_Serv_Time;

Progres_Arrival_Time = Next_Arrival_Time;

Progres_Comp_Time = Next_Comp_Time;

}

Next_Arrival_Time = Clock + expon(Mean_Arrival_Time);

Next_Serv_Time = expon(Mean_serv_Time);

}

void Comp()

{

double Delay;

++Num_Completed_Customers;

Total_Flow_Time+= ( Progres_Completion_Time - Progres_Arrival_Time );

if (Number_in_Queue == 0)

    {

        Server_Status= IDLE;

Next_Comp_Time = 1.0e+10;

    }

else

    {

if(choice==2)

            Search_Min(Time_Arrival,Serv_Time);   

Delay= Clock - Time_Arrival[1];

Waiting_Time+= Delay;

Next_Comp_Time = Clock + Serv_Time[1];

Progres_Arrival_Time = Time_Arrival[1];

Progres_Comp_Time = Next_Comp_Time;

--Number_in_Queue;

for (int i=1;i<=Number_in_Queue;i++)

        {

            Time_Arrival[i] = Time_Arrival[i + 1];

Serv_Time[i] = Serv_Time[i + 1];

        }

}

}

//Sorting

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;

}

float expon(float mean)

{

    return (-mean * log(lcgrand(1)));

}

#include<iostream>

#include <cmath>

using namespace std;

const int Queu_Limit=100;

const int BUSY=1;

const int IDLE=0;

int choice, Num_Comp_Customers,Number_of_Events, Number_in_Queue,Server_Status;

double End_Time,Type_Next_Event,Mean_Arrival_Time,Mean_serv_Time,Clock,Time_Arrival[Queu_Limit + 1],Serv_Time[Queu_Limit + 1], Next_Arrival_Time,Next_Compl_Time,Next_Serv_Time, Total_Flow_Time,Progres_Arrival_Time,Progres_Comp_Time,Waiting_Time;

void initialize();

void Timing();

void Arrival();

void Comp();

float expon(float mean);

void Search_Min(double[],double[]);

int main()

{

initialize();           // System Intialization

cout<<" 1.FIFO"<<endl;

cout<<" 2.Min Processing Time"<<endl;

do

    {

    cout<<" Enter your CHOICE: ";

cin>>choice;

}while(choice>2||choice<1);

cout<<" Mean Inter arrival Time: "<<Mean_Arrival_Time;

cout<<" Mean Service Time: "<<Mean_serv_Time<<endl;

cout<<"The End of Simulation Time: "<<End_Time<<endl;

while(true)

    {

Timing(); // To Determine The Next Event

if(Clock>End_Time)

           break;

switch (int(Type_Next_Event))

        {

         

        case 1:Arrival();

            break;

case 2: Comp();

            break;

        }

    }

    cout<<" Total Flow Time: "<<Total_Flow_Time;

cout<<" Total Waiting Time in Queue: "<<Wait_Time;

cout<<" Average Waiting Time in Queue: "<<Wait_Time / Num_Comp_Customers;

cout<<" Average Flow Time: "<<Total_Flow_Time / Num_Comp_Customers;

cout<<" Number of Completed Customers: "<<Num_Comp_Customers;

cout<<" Average Number of Customers In System / Unit Time: "<<Num_Comp_Customers / Clock<<endl<<endl;

return 0;

}

void initialize()

{

Number_of_Events = 2;

    Mean_Arrival_Time=1.0;

Mean_serv_Time=0.5;

End_Time=100.0;

Clock = 0.0;

Server_Status = IDLE;

Number_in_Queue = 0;

Num_Comp_Customers = 0;

Total_Flow_Time = 0.0;

Wait_Time = 0.0;

Next_Arrival_Time = Clock + expon(Mean_Arrival_Time);

Next_Serv_Time = expon(Mean_serv_Time);

Next_Comp_Time = 1.0e+10;

Progres_Arrival_Time=0.0;

Progres_Comp_Time = 0.0;

}

void Timing()

{

    Type_Next_Event = 0;

if(Next_Arrival_Time < Next_Comp_Time)

    {

Type_Next_Event = 1;

Clock=Next_Arrival_Time;

}

else

    {

        Type_Next_Event = 2;

Clock = Next_Compl_Time;

}

if (Type_Next_Event == 0)

    {

        cout<<" Event List empty time "<<Clock;

exit(1);

    }      

}

void Arrival() {

    if (Server_Status == BUSY)

    {

        ++Number_in_Queue;

if (Number_in_Queue > Queu_Limit)

        {

            cout<<" Overflow of the array timearrival at" <<Clock;

exit(2);

        }

Time_Arrival[Number_in_Queue] = Clock;

Serv_Time[Number_in_Queue] = Next_Serv_Time;

}

else

    {

        Server_Status = BUSY;

Next_Comp_Time = Clock + Next_Serv_Time;

Progres_Arrival_Time = Next_Arrival_Time;

Progres_Comp_Time = Next_Comp_Time;

}

Next_Arrival_Time = Clock + expon(Mean_Arrival_Time);

Next_Serv_Time = expon(Mean_serv_Time);

}

void Comp()

{

double Delay;

++Num_Completed_Customers;

Total_Flow_Time+= ( Progres_Completion_Time - Progres_Arrival_Time );

if (Number_in_Queue == 0)

    {

        Server_Status= IDLE;

Next_Comp_Time = 1.0e+10;

    }

else

    {

if(choice==2)

            Search_Min(Time_Arrival,Serv_Time);   

Delay= Clock - Time_Arrival[1];

Waiting_Time+= Delay;

Next_Comp_Time = Clock + Serv_Time[1];

Progres_Arrival_Time = Time_Arrival[1];

Progres_Comp_Time = Next_Comp_Time;

--Number_in_Queue;

for (int i=1;i<=Number_in_Queue;i++)

        {

            Time_Arrival[i] = Time_Arrival[i + 1];

Serv_Time[i] = Serv_Time[i + 1];

        }

}

}

//Sorting

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;

}

float expon(float mean)

{

    return (-mean * log(lcgrand(1)));

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote