Why simulation?
provide predictable and quantifiable results for "what if" scenarios
What's needed for simulation?
identify what kind of data we want to get
understand the variables that we want to change
derive an "operational model" for writing simulation program
A typical customer checkout scenario
customers with items wait in a queue
servers services customer
Typical questions for managers (i.e. simulation conclusion)
Given a customer pattern (arrival time, # of items),
what is the waiting time, average, max, etc?
what is server efficiency? (how busy is the server?)
how many servers do we need to keep customers happy?
Data structure
Main Simulation Routine
// set up data structure
queue<customerType> customerQueue;
serverListType serverList(numberOfServers);
// loop the whole simulation
for (clock = 1; clock <= simulationTime; clock++) {
// update transaction time in server (if busy)
// update waiting time in customer
QserverList.updateServers(cout);
if (!customerQueue.empty()) updateCustQueue(customerQueue);
// see if any new customer arrives during this clock period
// if it does, queue it up
if (isCustomerArrived(timeBetweenCustomerArrival))
{
custNumber++;
customer.setCustomerInfo(custNumber,clock,0, transactionTime);
customerQueue.push(customer);
}
// see if any server is free
// if there is, assign a customer
serverID = serverList.getFreeServerID();
if (serverID != -1 && !customerQueue.empty())
{
customer = customerQueue.front();
customerQueue.pop();
serverList.setServerBusy(serverID, customer);
}
}
Discussions
What if we have multiple customer queue? Quick checkout in supermarket, or first class in airline?
How about reading customers arrival record from file? This is, in my opinion, the most flexible way of doing simulation. It provides "repeatability" which is important in collecting consistent data.
So, what if we still want to do mathematically generated customer pattern? Well, we can generate it mathematically and write it to a file....