beautypg.com

HP Integrity NonStop H-Series User Manual

Page 117

background image

free = true;
return free;
}

void addCustomer(Customer c) // start serving new customer
{ customer = c;
free = false;
}

private:
bool free;
Customer customer;
};

The main program is then a large loop, cycling once each simulated minute. Each minute a new
customer is, with probability 0.9, entered into the queue of waiting customers. Each teller is polled,
and if any are free they take the next customer from the queue. Counts are maintained of the number
of customers serviced and the total time they spent in queue. From these two values we can
determine, following the simulation, the average time a customer spent waiting in the line.

void main() {
int numberOfTellers = 5;
int numberOfMinutes = 60;
double totalWait = 0;
int numberOfCustomers = 0;
vector teller(numberOfTellers);
queue< Customer, deque > line;

for (int time = 0; time < numberOfMinutes; time++) {
if (randomInteger(10) < 9)
line.push(Customer(time));
for (int i = 0; i < numberOfTellers; i++) {
if (teller[i].isFree() & ! line.empty()) {
Customer & frontCustomer = line.front();
numberOfCustomers++;
totalWait += (time - frontCustomer.arrival_Time);
teller[i].addCustomer(frontCustomer);
line.pop();
}
}
}
cout << "average wait:" <<
(totalWait / numberOfCustomers) << endl;
}

By executing the program several times, using various values for the number of tellers, the manager
can determine the smallest number of tellers that can service the customers while maintaining the
average waiting time at an acceptable amount.

This manual is related to the following products: