// Simulation of the Hertz airport shuttle bus, which picks up passengers // from the airport terminal building going to the Hertz rental car lot. #include "cpp.h" #include #define NUM_SEATS 6 // number of seats available on shuttle #define TINY 1.e-20 // a very small time period #define TERMNL 0 // named constants for labelling event set #define CARLOT 1 qtable termnl ("termnl"); // customer queue at airport terminal qtable carlot ("carlot"); // customer queue at rental car lot qtable rest ("rest"); // dummy facility indicating an idle shuttle mailbox on_termnl("terminal boarding pass"); mailbox on_carlot("carlot boarding pass"); event get_off_now ("get_off_now"); // all customers can get off shuttle event_set shuttle_called ("call button", 2); // call buttons at terminal and car lot void arrivals(); // function declarations void arr_cust(); void departures(); void dep_cust(); void shuttle(); long group_size(); extern "C" void sim(int argc, char* argv[]) // main process { long new_seed_val; if (argc>1) reseed(NIL, atoi(argv[1])); create("sim"); arrivals(); // start a stream of arriving customers departures(); // start a stream of departing customers shuttle(); // create a single shuttle hold (1440); // wait for a whole day (in minutes) to pass report(); } // Model segment 1a: generate groups of customers arriving at the airport void arrivals() { create("arrivals"); while(clock < 1440.) // { hold(expntl(10)); // exponential interarrivals, mean 10 minutes long group = group_size(); for (long i=0;i 0)) { on_carlot.send(my_ID);// one person gets a ticket seats_used++; hold(TINY); } if (on_carlot.queue_cnt() == 0) // nobody left behind shuttle_called[CARLOT].clear(); hold (uniform(3,5)); // drive to airport terminal //trace_on(); // drop off any passengers on board if(seats_used > 0) { get_off_now.set(); // open door and let them off seats_used = 0; } // ready to load customers at airport terminal // invite them in, one by one, till all seats are full while((seats_used < NUM_SEATS) && (on_termnl.queue_cnt() > 0)) { on_termnl.send(my_ID);// one person gets a ticket seats_used++; hold(TINY); } if (on_termnl.queue_cnt() == 0) // nobody left behind shuttle_called[TERMNL].clear(); //trace_off(); hold (uniform(3,5)); // drive to Hertz car lot // drop off any passengers on board if(seats_used > 0) { get_off_now.set(); // open door and let them off seats_used = 0; } } } } long group_size() // function gives the number of customers in a group { double x = prob(); if (x < 0.3) return 1; else { if (x < 0.7) return 2; else return 4; } }