/*
    bookstore.c
    
    Created by NJG on Wed, Apr 4, 2007
    Updated by NJG on Monday, January 2, 2017

    PDQ model using 2 MSQ nodes in tandem.
    
    Big book stores like Barnes & Noble or Borders allow customers to
    enter, browse and read books, have coffee, eat, listen to CDs and
    finally head to the checkout area. The checkout consists of a single
    waiting line serviced by multiple cashiers. Such a big book store can
    be modeled as M/M/inf (browsing) and M/M/m (checkout).

    The PDQ model parameters are taken from Example 4.1 (p.170) in Gross
    and Harris, "Fundamentals of Queueing Theory," 3rd edn. (1998) which
    discusses a grocery store with a "lounge". (??)
    
    Currently, only 3 employees are paid to act as cashiers.
    Input parameters:
        Arrival rate = 40 per hr
        Lounge time  = 3/4 hr
        Service time = 4 mins
 
    The capacity planning questions are:
        If the store mgr pays a 4th cashier, what happens to the:
        1. waiting time at the checkout? (G&H: 1.14 mins)
        2. queue length at the checkout? (G&H: 3.44 cust)
        3. mean number of people in the store (G&H: 30 + 3.44 = 33.44 cust)
 
        The only only parameter that might be made more realistic for this
        bookstore example, is the browsing time, e.g., increase to 65 mins.
 
 */

#include <stdio.h>
#include <string.h>
#include <math.h>
#include "PDQ_Lib.h"

int main(void) {

    int              nodes;
    int              streams;
    
    double           arrivalRate    = 40.0/60;  // cust per min
    double           browseTime     = 45.0;     // mins 
    double           buyingTime     = 4.0;      // mins
    int              cashiers       = 4;
        
    PDQ_Init("Big Book Store Model");
        
    streams = PDQ_CreateOpen("Customers"arrivalRate);
    
    PDQ_SetWUnit("Cust");
    PDQ_SetTUnit("Min");    // timebase for PDQ report
    
    /*** New MSQ flag tells PDQ the following are multiserver nodes ***/

    // M/M/inf queue defined as 100 times the number of Erlangs = lambda * S
    nodes = PDQ_CreateNode("Browsing", (intceil(arrivalRate * browseTime) * 100MSQ); 
    
    // M/M/m where m is the number of cashiers  
    nodes = PDQ_CreateNode("Checkout"cashiersMSQ); 
    
    // Set service times ...
    PDQ_SetDemand("Browsing""Customers"browseTime);
    PDQ_SetDemand("Checkout""Customers"buyingTime);
    
    PDQ_Solve(CANON);
    PDQ_Report();
   
}  // main