This is a single queue program:
#include <iostream>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include "Simulation.h"
#include "queueAsArray.h"
using namespace std;
void setSimulationParameters(int& sTime, int& numOfServers,
int& transTime,
int& tBetweenCArrival);
bool isCustomerArrived(double arvTimeDiff);
void generateStatistics(serverListType& serverList,
waitingCustomerQueueType& CQueue,
int numOfCustArrived,
int waitTimeServedCustomers);
void runSimulation();
int main()
{
runSimulation();
system("pause");
return 0;
}
void setSimulationParameters(int& sTime, int& numOfServers,
int& transTime,
int& tBetweenCArrival)
{
cout<<"Enter the simulation time: "<<flush;
cin>>sTime;
cout<<endl;
cout<<"Enter the number of servers: "<<flush;
cin>>numOfServers;
cout<<endl;
cout<<"Enter the transaction time: "<<flush;
cin>>transTime;
cout<<endl;
cout<<"Enter the time between customer arrivals: "<<flush;
cin>>tBetweenCArrival;
cout<<endl;
}
bool isCustomerArrived(double arvTimeDiff)
{
double value;
value = static_cast<double> (rand()) / static_cast<double>(RAND_MAX);
return (value > exp(- 1.0/arvTimeDiff));
}
void runSimulation()
{
int simulationTime;
int numberOfServers;
int transactionTime;
int timeBetweenCustomerArrival;
waitingCustomerQueueType customerQueue;
customerType customer;
int custNumber = 0;
int totalWaitTimeServedCustomers = 0;
int totalWaitTime = 0;
int numberOfCustomersServed = 0;
int customersLeftInServers = 0;
int clock = 0;
int serverID;
setSimulationParameters(simulationTime, numberOfServers,
transactionTime, timeBetweenCustomerArrival);
serverListType serverList(numberOfServers);
for(clock = 1; clock <= simulationTime; clock++)
{
serverList.updateServers();
if(!customerQueue.isEmptyQueue())
customerQueue.updateWaitingQueue();
if(isCustomerArrived(timeBetweenCustomerArrival))
{
custNumber++;
customer.setCustomerInfo(custNumber,clock,0,
transactionTime);
customerQueue.addQueue(customer);
cout<<"Customer number "<<custNumber
<<" arrived at time unit "<<clock<<endl;
}
serverID = serverList.getFreeServerID();
if(serverID != -1 && !customerQueue.isEmptyQueue())
{
customer = customerQueue.front();
customerQueue.deleteQueue();
totalWaitTimeServedCustomers = totalWaitTimeServedCustomers
+ customer.getWaitingTime();
serverList.setServerBusy(serverID, customer);
}
}
cout<<endl;
cout<<"Simulation ran for "<<simulationTime
<<" time units"<<endl;
cout<<"Number of servers: "<<numberOfServers<<endl;
cout<<"Average transaction time: "
<<transactionTime<<endl;
cout<<"Average arrival time difference between customers: "
<<timeBetweenCustomerArrival<<endl;
generateStatistics(serverList, customerQueue,
custNumber, totalWaitTimeServedCustomers);
}
void generateStatistics(serverListType& serverList,
waitingCustomerQueueType& CQueue,
int numOfCustArrived,
int waitTimeServedCustomers)
{
int customersLeftInQueue = 0;
int totalWaitTime = waitTimeServedCustomers;
customerType customer;
while(!CQueue.isEmptyQueue())
{
customer = CQueue.front();
CQueue.deleteQueue();
totalWaitTime = totalWaitTime + customer.getWaitingTime();
customersLeftInQueue++;
}
//Find number of customers left in servers
int customersLeftInServers = serverList.getNumberOfBusyServers();
//Find number of customers completely served
int numberOfCustomersServed = numOfCustArrived - customersLeftInServers -
customersLeftInQueue;
double averageWaitTime = 0;
cout<<"Total wait time: "<<totalWaitTime<<endl;
cout<<"Number of customers who completed a transaction: "
<<numberOfCustomersServed<<endl;
cout<<"Number of customers left in the servers: "
<<customersLeftInServers<<endl;
cout<<"Number of customers left in the queue: "<<customersLeftInQueue
<<endl;
if(numOfCustArrived > 0) // If number of customers arrived is > 0
averageWaitTime = (static_cast<double>(totalWaitTime)) / numOfCustArrived;
cout<<fixed<<showpoint;
cout<<setprecision(2);
cout<<"Average wait time: "<<averageWaitTime<<endl;
cout<< endl;
cout<<"************** END SIMULATION *************"<<endl;
cout<< endl;
}
I want to add a second queue so that, when run, a user-input percentage of the customers will go into the second queue while the remainder of them will go into the first (original) queue. PLEASE tell me what I have to do in order to make this code work with two queues. (I have a code I've been working on, integrating the second array, but was told that it wasn't any good...) If you'd like to see that, let me know and I'll post it.
ASKER
#include <iostream>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include "Simulation.h"
#include "queueAsArray.h"
using namespace std;
void setSimulationParameters(in
int& transTime,
int& tBetweenCArrival);
bool isCustomerArrived(double arvTimeDiff);
void generateStatistics(serverL
waitingCustomerQueueType& CQueue,
waitingCustomerQueueType& SQueue,
int numOfCustArrived,
int numOfSpecCustArrived,
int waitTimeServedCustomers,
int waitTimeServedSpecialCusto
void runSimulation();
int main()
{
runSimulation();
system("pause");
return 0;
}
void setSimulationParameters(in
int& transTime,
int& tBetweenCArrival,
int& pSpecCust)
{
cout<<"Enter the simulation time: "<<flush;
cin>>sTime;
cout<<endl;
cout<<"Enter the number of servers: "<<flush;
cin>>numOfServers;
cout<<endl;
cout<<"Enter the transaction time: "<<flush;
cin>>transTime;
cout<<endl;
cout<<"Enter the time between customer arrivals: "<<flush;
cin>>tBetweenCArrival;
cout<<endl;
cout<<"Enter the percentage of special customers: "<<flush;
cin>>pSpecCust;
cout<<endl;
}
bool isCustomerArrived(double arvTimeDiff)
{
double value;
value = static_cast<double> (rand()) / static_cast<double>(RAND_M
return (value > exp(- 1.0/arvTimeDiff));
}
void runSimulation()
{
int simulationTime;
int numberOfServers;
int transactionTime;
int timeBetweenCustomerArrival
int percentageSpecialCustomers
waitingCustomerQueueType customerQueue;
waitingCustomerQueueType specCustQueue;
customerType customer;
int custNumber = 0;
int specCustNumber = custNumber;
int totalWaitTimeServedCustome
int totalWaitTimeServedSpecial
int totalWaitTime = 0;
int numberOfCustomersServed = 0;
int numberOfSpecialCustomersSe
int customersLeftInServers = 0;
int clock = 0;
int serverID;
setSimulationParameters(si
transactionTime, timeBetweenCustomerArrival
serverListType serverList(numberOfServers
for(clock = 1; clock <= simulationTime; clock++)
{
serverList.updateServers()
if(!customerQueue.isEmptyQ
customerQueue.updateWaitin
if(!specCustQueue.isEmptyQ
specCustQueue.updateWaitin
while(isCustomerArrived(ti
if ((static_cast<double> (rand()) / static_cast<double>(RAND_M
{
custNumber++;
customer.setCustomerInfo(c
transactionTime);
specCustQueue.addQueue(cus
cout<<"Customer number "<<custNumber
<<" arrived at time unit "<<clock<<endl;
}
else
{
custNumber++;
customer.setCustomerInfo(c
transactionTime);
customerQueue.addQueue(cus
cout<<"Customer number "<<custNumber
<<" arrived at time unit "<<clock<<endl;
}
serverID = serverList.getFreeServerID
while (serverID != -1 && !specCustQueue.isEmptyQueu
{
customer = specCustQueue.front();
specCustQueue.deleteQueue(
totalWaitTimeServedCustome
+ customer.getWaitingTime();
serverList.setServerBusy(s
}
if(serverID != -1 && !customerQueue.isEmptyQueu
{
customer = customerQueue.front();
customerQueue.deleteQueue(
totalWaitTimeServedCustome
+ customer.getWaitingTime();
serverList.setServerBusy(s
}
}
cout<<endl;
cout<<"Simulation ran for "<<simulationTime
<<" time units"<<endl;
cout<<"Number of servers: "<<numberOfServers<<endl;
cout<<"Average transaction time: "
<<transactionTime<<endl;
cout<<"Average arrival time difference between customers: "
<<timeBetweenCustomerArriv
generateStatistics(serverL
custNumber, specCustNumber,
totalWaitTimeServedCustome
totalWaitTimeServedSpecial
}
void generateStatistics(serverL
waitingCustomerQueueType& CQueue,
waitingCustomerQueueType& SQueue,
int numOfCustArrived,
int numOfSpecCustArrived,
int waitTimeServedCustomers,
int waitTimeServedSpecialCusto
{
int customersLeftInQueue = 0;
int specialCustomersLeftInQueu
int totalWaitTime = waitTimeServedCustomers;
int totalWaitTimeSpecial = waitTimeServedSpecialCusto
customerType customer;
while(!SQueue.isEmptyQueue
{
customer = SQueue.front();
SQueue.deleteQueue();
totalWaitTimeSpecial = totalWaitTimeSpecial + customer.getWaitingTime();
specialCustomersLeftInQueu
}
if(!CQueue.isEmptyQueue())
{
customer = CQueue.front();
CQueue.deleteQueue();
totalWaitTime = totalWaitTime + customer.getWaitingTime();
customersLeftInQueue++;
}
//Find number of customers left in servers
int customersLeftInServers = serverList.getNumberOfBusy
//Find number of customers completely served
int numberOfCustomersServed = numOfCustArrived - customersLeftInServers -
customersLeftInQueue;
int numberOfSpecialCustomersSe
specialCustomersLeftInQueu
double averageWaitTime = 0;
double averageWaitTimeSpecial = 0;
cout<<"Number of customers who completed a transaction: "
<<numberOfCustomersServed<
cout<<"Number of customers left in the servers: "
<<customersLeftInServers<<
cout<<"Number of customers left in the queue: "<<customersLeftInQueue
<<endl;
cout<<"Number of special customers left in the queue: "<<specialCustomersLeftInQ
<<endl;
cout<<endl;
cout<<endl;
cout<<"Total wait time - Regular Customers: "<<totalWaitTime<<endl;
if(numOfCustArrived > 0) // If number of customers arrived is > 0
averageWaitTime = (static_cast<double>(total
cout<<fixed<<showpoint;
cout<<setprecision(2);
cout<<"Average wait time - Regular Customers: "<<averageWaitTime<<endl;
cout<< endl;
cout<<"Total wait time - Special Customers: "<<totalWaitTimeSpecial<<e
if(numOfSpecCustArrived > 0) // If number of special customers arrived is > 0
averageWaitTimeSpecial = (static_cast<double>(total
cout<<fixed<<showpoint;
cout<<setprecision(2);
cout<<"Average wait time - Special Customers: "<<averageWaitTimeSpecial<
cout<< endl;
cout<< endl;
cout<<"************** END SIMULATION *************"<<endl;
cout<< endl;
}