1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
|
#include<iostream>
#include <cstdio>
#include <fstream>
#include <queue>
#include "Servers.h"
using namespace std;
//define all functions
int main (){
queue<Customer> custQ1;//queue1 of customers
queue<Customer> custQ2;//queue2 of customers
Customer cust;//a customer
Server server;//servers
ifstream rFile;
int custInfo[3]={0};
Server previous;
rFile.open("C:\\Users\\rahman-pc\\Desktop\\arrivals.txt");
do/*(!rFile.eof() && server.serverBusy==0)*/{
readData(rFile,cust);
cout<<"ID "<<cust.id<<endl;
cout<<"Service customer "<<cust.id<<" \n"<<"Qsize "<<custQ1.size()<<"\n"<<"total service time? "<<server.total_time_to_serve<<endl;
if(server.serverBusy==1){
if(server.total_time_to_serve<cust.arrival_time){
processServiceCMP(custQ1,custQ2,cust,server);
}
else{
processArrival(custQ1,custQ2,cust,server);
}
}
else{
//process arrival
processArrival(custQ1,custQ2,cust,server);
}
}while(!rFile.eof()&& server.serverBusy==1);
rFile.close();
return 0;
}
//define processArrivale()
int processArrival(queue<Customer>& cstQ1,std::queue<Customer>&cstQ2,Customer& cst, Server& srv)
{
//***process arrival***//
//if server busy enQ customer
if(srv.serverBusy==1){
cstQ1.push(cst);
}
else{
//set busy to true
srv.serverBusy=1;
//set service_end_time=arrival_time+service_time
srv.total_time_to_serve=cst.arrival_time+cst.serving_time;
}
//readData(rFile, cst);
}
//define processServiceCMP
int processServiceCMP(queue<Customer>& cstQ1,queue<Customer>&cstQ2,Customer& cst,Server&srv)
{
//***process service***//
//if Q empty set busy to false
if (cstQ1.empty())
srv.serverBusy=0;
//else service_end_time=service_end_time+deQ which must return the service end time of this job
else{
srv.total_time_to_serve=cstQ1.front().arrival_time+cstQ1.front().serving_time;
cstQ1.pop();
}
}
int readData(ifstream& rFile, Customer& cst) //will get the next id, service time and arrival time
{
(rFile>>cst.id>>cst.arrival_time>>cst.serving_time);
}
|