// 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 facility termnl ("termnl"); // customer queue at airport terminal facility carlot ("carlot"); // customer queue at rental car lot facility rest ("rest"); // dummy facility indicating an idle shuttle event get_off_now ("get_off_now"); // all customers can get off shuttle event on_termnl ("on_termnl"); // one customer can get on shuttle at terminal event on_carlot ("on_carlot"); // one customer can get on shuttle at car lot event boarded ("boarded"); // one customer has gotten on and taken a seat 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() // main process { 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.set();// invite one person to board boarded.wait(); // that person is now on board seats_used++; hold(TINY); } hold (uniform(3,5)); // drive to airport terminal // 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) && (termnl.num_busy() + termnl.qlength() > 0)) { on_termnl.set();// invite one person to board boarded.wait(); // that person is now on board seats_used++; hold(TINY); } 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; } }