In many cases solving even a simple looking problem analytic

In many cases, solving even a simple looking problem analytically will prove tedious if not impossible. In such cases, a numerical simulation relying on random combinations of the independent variables may prove satisfactory. Such simulations are often called Monte Carlo simulations after the European principality famous for its casinos. The most important part of such a simulation is an accurate model of the system being simulated. A bank typically has a number of teller windows staffed with say between 3 and 6 tellers. The customers arrive and wait in a single line for the next available teller. The customer at the head of the line walks to the first free teller window and initiates a transaction of some duration. Obviously, the bank management would like to know how many tellers to employ to keep the line to a reasonable length and the customers\' wait times tolerable. Please create a model for this system by creating individual classes for the Bank, Teller and Customer. The Bank model should include a list of the Tellers. Each Teller should contain a reference to the Customer being serviced. The Customer should include the arrival time, the time of the initiation of the transaction and the time required for the transaction. The customers will be assumed to arrive at random times, with a given mean number of customers arriving per minute. They wait in line until they are at the head of the line and then they proceed to the first available teller. The time required for their transaction is also randomly chosen. For the random e- ! distributions, please use a Poisson distribution: p(k)- integer value k. Fortunately, C++ provides a suitable function for generating integer values according to this distribution. For the random distributions, feel free to use the class below if you do not wish to write your own. _ where is the mean value for the Supplied with your model, you can now predict the operation of the bank. Please determine as functions of the number of tellers between 3 and 6, the average arrival rate and the average transaction duration: 1. 2. 3. 4. the maximum length of the waiting line, its average length of the waiting line the maximum wait time the average wait time You may find the following procedure illustrative. Step forward in time for some number- typically quite a large number!-of minutes 1. At the beginning of each minute, you determine how many customers have arrived. Create an instance of Customer for each. Place each into the waiting line. a. b.

Solution

ifndef QUEUE2_H_
#define QUEUE2_H_

#include <iostream>
#include \"Teller.h\"
#include \"Queue.h\"
#include \"Customer.h\"
#include \"QueueNode.h\"

template <typename T>
class Queue
{
private:
   const static int Q_SIZE = 10;
   QueueNode<T>*front;                                               // pointer to front of Queue
   QueueNode<T>*rear;                                               // pointer to rear of Queue
   int count;                                                   // current number of items in Queue
   const int qsize;                                           // maximum number of items in Queue
   // preemptive definitions to prevent public copying
   Queue(T C)
   {
       qsize = 0;
       rear = NULL;
       front = NULL;
       count = 0;
   }
   Queue & operator=(const T & q) {return *this;};

public:

   ~Queue()
   {
       QueueNode<T> * temp;                       // create temporary address store
       while(front != (void *) 0)           // while the queue is not empty
       {
           temp = front;
           front =front->next;           // advance the front object to the next
           delete temp;                   // delete the temporary data
       }
   }
   bool isempty() const
   {
       return count == 0;
   }

   bool isfull() const
   {
       return count == qsize;
   }

   int queuecount() const
   {
       return count;
   }

   bool enqueue(const T &data)     // add item to end
   {
       if(isfull())                       // if queue is full halt queuing
           return false;
       QueueNode<T> *add = new QueueNode<T>;               // create node
       add->customer = data;                   // set node pointers
       add->next = (void *) 0;               // or nullptr;
       count++;
       if (front == (void *) 0)           // if queue is empty,
           front = add;                   // place item at front
       else
           rear->next = add;               // else place at rear
       rear = add;                           // have rear point to new node
       return true;
   }

   bool dequeue(T &data)           // remove item from front
   {
       if(front == (void *) 0)               // front node is empty, queue is empty
           return false;

       data = front->customer;                   // set data to first item in queue
       count--;                           // decrement item count
       QueueNode<T>* temp = front;                // save location of first item
       front = front->next;                // reset front to next item
       delete temp;                       // delete former first item

       if (count == 0)                       // if the queue is now empty set rear to point to nothing
           rear = (void *)0;

       return true;
   }
};


#endif /* QUEUE_H_ */


#ifndef QUEUENODE_H_
#define QUEUENODE_H_

#include <iostream>
#include \"Queue.h\"
#include \"Customer.h\"

using namespace std;
class Customer;
template<class T>
class Queue;

template<class T>
class QueueNode
{
private:
   T customer;
   QueueNode *next;

public:
   QueueNode(T C)
   {
       C = customer;
       next = NULL;
   }
   friend class Queue<T>;
   friend class Customer;
};

#endif /* QUEUENODE_


#ifndef CUSTOMER_H_
#define CUSTOMER_H_

#include <iostream>
#include \"QueueNode.h\"
#include \"Queue.h\"
#include \"Teller.h\"
#include <cstdlib>

using namespace std;

class Customer
{
private:
   int serviceTime;
   int arrivalTime;
public:
   Customer()
   {
       serviceTime = 0;
       arrivalTime = 0;
   }
   /*
   void setServiceTime()
   {
       serviceTime = 1 + rand() % maxService;
   }
   */


   Customer(int arrival, int maxService)
   {
       arrivalTime = arrival;
       serviceTime = 1 + rand() % maxService;
   }

   int getServiceTime()
   {
       return serviceTime;
   }
   bool isDone()
   {
       return (serviceTime-- <= 0);
   }

   int getArrivalTime()
   {
       return arrivalTime;
   }
};

#ifndef TELLER_H_
#define TELLER_H_

#include <iostream>
#include \"Customer.h\"
#include \"QueueNode.h\"
#include \"Queue.h\"

using namespace std;

class Teller
{
private:
   bool isOccupied;
   Customer customer;
public:
   Teller()
   {
       isOccupied = true;
       customer = NULL;
   }
   bool isFree()
   {
       if(isOccupied)
       {
           return true;
       }
       else if(customer.isDone())
       {
           isOccupied = true;
       }
       return isOccupied;
   }
   void addCustomer(Customer C)
   {
       customer = C;
       isOccupied = false;
   }
};

#include <iostream>
#include <vector>
#include \"Queue.h\"
#include \"Customer.h\"
#include \"QueueNode.h\"
#include \"Teller.h\"

using namespace std;


int main(int argc, char *argv[])
{
   srand(time(NULL)); //seeds the random time generator

   if(argc != 5)
   {
       cout << \"You must enter at least 5 command line arguments \" << endl;
       exit(1);
   }

   double p = atoi(argv[1]);
   int numTellers = atoi(argv[2]); //number of the tellers (M)
   int maxService = atoi(argv[3]);
   int maxClock = atoi(argv[4]); //simulation time (N)

   Queue<Customer> customerQueue;
   vector<Teller> tellers(numTellers);

   int totalWait = 0;
   int numCustServed = 1;
   cout<<\"Customer No. Arrival time Waiting time in queue\"<<endl;
   cout<<\"------------ ------------ ---------------------\"<<endl;

   //////////////////////////////////////////////////////////////////
   for(int i = 1; i < maxClock; i++) //loop begins at 1 and counts up
   {
       if(1 + rand()%10 <= maxService)
       {
           Customer customer(i, maxService);
           customerQueue.enqueue(customer);
           cout << \" \" << numCustServed << \" \" << i << \" \" << totalWait/numCustServed <<endl;
       }
       for(int t = 0; t < numTellers; t++)
       {
           if(tellers[t].isFree() && (!customerQueue.isempty()))
           {
               Customer customer = customerQueue.front();
               tellers[t].addCustomer(customer);
               totalWait = totalWait + (i - customer.getArrivalTime());
               customerQueue.remove(); //dont know about this
               numCustServed++;
           }
       }

       cout << \"Total waiting time: \" << totalWait << endl;
       cout << \"Number of Customers served: \" << numCustServed << endl;
       cout << \"Average waiting time: \" << totalWait/numCustServed<<endl;
       cout << \"After service the number of customers left in queue: \" <<endl;
       cout << customerQueue.queuecount() << endl;

       cout << \"=====================================================\" <<endl;

       cout << \"\ \ \ Customer No. Arrival time Waiting time in queue\" <<endl;
       cout << \"------------------------------------------------------\" <<endl;

       /*
       while(customerQueue.queuecount() > 0)
       {
           if(1 + rand()%10 <= maxService)
           {
               int currentTime;
               i = currentTime;
               Customer customer(i);
               cout << \" \" << numCustServed << \" \" << i << \" \" << totalWait/numCustServed << endl;
           }
       }
       */
       while(customerQueue.queuecount() > 0)
       {
           for(int m = 0; m < maxService; m++)
           {
               if(tellers[m].isFree() && (!customerQueue.isempty()))
               {
                   Customer customer = customerQueue.front();
                   customerQueue.remove();
                   cout << \" \" << numCustServed << \" \" << i << \" \" << totalWait/numCustServed <<endl;
               }
           }
       }
       cout << \"Total waiting time: \" << totalWait << endl;
       cout << \"Number of Customers served: \" << numCustServed << endl;
       cout << \"Average waiting time: \" << totalWait/numCustServed<<endl;
       cout << \"After service the number of customers left in queue: \" <<endl;
       cout << customerQueue.queuecount() << endl;

       return 0;
   }
}

 In many cases, solving even a simple looking problem analytically will prove tedious if not impossible. In such cases, a numerical simulation relying on random
 In many cases, solving even a simple looking problem analytically will prove tedious if not impossible. In such cases, a numerical simulation relying on random
 In many cases, solving even a simple looking problem analytically will prove tedious if not impossible. In such cases, a numerical simulation relying on random
 In many cases, solving even a simple looking problem analytically will prove tedious if not impossible. In such cases, a numerical simulation relying on random
 In many cases, solving even a simple looking problem analytically will prove tedious if not impossible. In such cases, a numerical simulation relying on random
 In many cases, solving even a simple looking problem analytically will prove tedious if not impossible. In such cases, a numerical simulation relying on random

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site