cpsc 242 Mostly in elassa Blackboard Resource Queues package
Solution
please provide the exact question for which answer is needed.
here i provide the sample program which will calculate the time based on first in first out order and Minimum Processing Time
#include<iostream>
#include <cmath>
#include <cstdlib>
#include <ctime>
using namespace std;
const int Queue_lim=100;
const int BUSY=1;
const int IDLE=0;
int choice, Comp_cust, No_events, Completed, No_queue, Server_Status;
double End_Time, Type_Next_Event, Mean_interArrival_Time, Mean_service_Time, clock,
Time_Arrival[Queue_lim + 1],
Service_Time[Queue_lim + 1],
Flow_time,
Progres_Arrival_Time,
Progres_Completed_Time,
Wait_time;
Next_Arrival_Time,
Next_Completed_Time,
Next_Service_Time,
//functions in simulation
void start();
void Timing();
void Arrival();
void Completion();
float expon(float mean);
void Min_search(double[],double[]);
int main()
{
start(); // Intialization of the System
cout<<\" fixed run theater ticket simulation *\ \";
cout<<\"\ 1.FIFO order\"<<endl;
cout<<\" 2.with Minimum Processing Time\"<<endl<<endl;
do
{
cout<<\"\\tEnter your choice: \"; // to simulate based on above policies
cin>>choice;
} while(choice>2||choice<1);
cout<<\"\ Mean InterArrival Time is: \"<<Mean_interArrival_Time;
cout<<\"\ Mean Service Time is: \"<<Mean_service_Time<<endl;
cout<<\"The End of Simulation Time: \"<<End_Time<<endl<<endl;
while(true)
{
Timing(); // Routine To check next event
if(Clock > End_Time)
break;
switch (int(Type_Next_Event))
{
case 1:
Arrival(); //customer arrival time
break;
case 2:
Completition(); //completion of task
break;
}
}
// Print Summary
cout<<\"\ Total Flow Time: \"<<Flow_time;
cout<<\"\ Total Waiting Time in Queue: \"<<Wait_time;
cout<<\"\ Average Waiting Time in Queue: \"<<Wait_time / Comp_cust;
cout<<\"\ Average Flow Time: \"<<Flow_time / Comp_cust;
cout<<\"\ Number of Completed Customers: \"<<Comp_cust;
cout<<\"\ Average Number of Customers In System / Unit Time: \"<<Comp_cust / Clock<<endl<<endl;
return 0;
}
//start function
void start()
{
No_events = 2; // Arrival and Completion
Mean_service_Time=1.0;
Mean_interArrival_Time=0.7* Mean_service_Time;
End_Time=100.0;
Clock = 0.0;
Server_Status = IDLE;
No_queue = 3; //pre filling the queue
Comp_cust = 0;
Flow_time = 0.0;
Wait_time = 0.0;
Next_Arrival_Time = Clock + expon(Mean_interArrival_Time);//Arriving
Next_Service_Time = expon(Mean_service_Time);
Nxt_Comp_Time = 1.0e+10; // Completing Guarantening that the first event is arriving
Progres_Arrival_Time=0.0;
Progres_Completed_Time = 0.0;
}
// Timing Routine Function
void Timing()
{
Type_Next_Event = 0;
if(Next_Arrival_Time < Next_Completed_Time)
{
Type_Next_Event = 1;
Clock=Next_Arrival_Time;
}
else
{
Type_Next_Event = 2;
Clock = Next_Completed_Time;
}
if (Type_Next_Event == 0)
{
cout<<\"\ List Empty at Time: \"<<Clock;
exit(1);
}
}
// customer Arriving function
void Arrival()
{
if (Server_Status == BUSY)
{
++No_queue;
if (No_queue > Queue_lim)
{
cout<<\"\ Overflow of the array time_arrival at\";
cout<<\"time: \"<<Clock;
exit(2);
}
Time_Arrival[No_queue] = Clock;
Service_Time[No_queue] = Next_Service_Time;
}
else
{
Server_Status = BUSY;
Nxt_Comp_Time = Clock + Next_Service_Time;
Progres_Arrival_Time = Next_Arrival_Time;
Progres_Completed_Time = Next_Completed_Time;
}
Next_Arrival_Time = Clock + expon(Mean_interArrival_Time);
Next_Service_Time = expon(Mean_service_Time);
}
// Completed Customer Function
void Completition()
{
double Delay;
++Comp_cust;
Flow_time+= ( Progres_Completed_Time - Progres_Arrival_Time );
if (No_queue == 0)
{
Server_Status= IDLE;
Nxt_Comp_Time = 1.0e+10; // Max Value
}
else
{
if(choice==2)
Min_search(Time_Arrival,Service_Time); // Minimum Processing Time
Delay= Clock - Time_Arrival[1];
Wait_time+= Delay;
Nxt_Comp_Time = Clock + Service_Time[1];
Progres_Arrival_Time = Time_Arrival[1];
Progres_Completed_Time = Next_Completed_Time;
--No_queue; //decrement queue after completion of service
for (int i=1;i<=No_queue;i++)
{
Time_Arrival [i] = Time_Arrival[i + 1];
Service_Time[i] = Service_Time[i + 1];
}
}
}
//Sorting Functtion
void Min_search(double Arr_time[],double Ser_time[])
{
int Min=1;
double temp;
for(int i=1;i<No_queue;i++)
if(Ser_time[Min]>Ser_time[i+1])
Min=i+1;
temp=Ser_time[1];
Ser_time[1]=Ser_time[Min];
Ser_time[Min]=temp;
temp=Arr_time[1];
Arr_time[1]=Arr_time[Min];
Arr_time[Min]=temp;
}
// Generate The Rondom Number
float expon(float mean)
{
srand((unsigned)time(0));
typedef float random_integer = rand(); //calculates random number
return random_integer;
}






