Ok, can anyone give me any ideas on how to implement this program correctly. I need to basically do a client / server relationship. I use the gsl library to generate customers randomly, then after that I need a "server", which is just an if statement, to service the customer for the specified amount of time. I just am unsure of how to do this.
Code:
#include <stdio.h>
#include <iostream.h>
#include <gsl/gsl_rng.h>
#include <gsl/gsl_randist.h>
#include <vector>
int main (int argc, char *argv[])
{
const gsl_rng_type * T;
gsl_rng * r;
float N, R, alpha, M;
int closeTime;
cout<<"N: "; // number of lines
cin>>N;
cout<<"R: "; // rate of entry
cin>>R;
cout<<"alpha: "; //amount of bsy time
cin>>alpha;
cout<<"M: "; // output capacity
cin>>M;
cout<<"closeTime: ";
cin>>closeTime;
double mu = N * R * alpha; // arrival rate (N, R and alpha)
int maxSize = (int)mu * closeTime;
float S = 1/M;
float waitList[maxSize], customerList[maxSize], server[1];
gsl_rng_env_setup();
T = gsl_rng_default;
r = gsl_rng_alloc (T);
int counter = 0;
float arrivalTime = 0;
double expRandom = gsl_ran_exponential (r, 1/mu);
arrivalTime = arrivalTime + expRandom;
server[0] = 0;
float serviceTime;
int custDone = 0;
float currentTime = 0.00;
while(1)
{
if(currentTime > arrivalTime) //maybe use rate?
{
expRandom = gsl_ran_exponential (r, 1/mu);
arrivalTime = arrivalTime + expRandom;
if(server[0] == 0)
{
server[0] = arrivalTime;
cout << "Customer arrived at: " << arrivalTime << " and put into service." << endl;
}
else
{
waitList[counter] = arrivalTime;
counter++;
cout << "Customer arrived at: " << arrivalTime << " and put into queue." << endl;
}
}
//serviceTime = arrivalTime + S;
if(server[0] != 0)
{
cout << "Customer: " << server[0] << " is being served." << endl;
if(counter > 0 && custDone == 1)
{
server[0] = waitList[0];
for(int x = 0; x < counter; x++)
waitList[x] = waitList[x + 1];
}
}
currentTime += 1;
}
return 0;
}