//======================================================= file = tandem.c ===== //= Simulation model of a tandem queue = //============================================================================= //= Notes: This program is the solution for an in-class example for = //= Simulation Spring 2005. = //=---------------------------------------------------------------------------= //= Build: Standard SMPL build = //=---------------------------------------------------------------------------= //= History: KJC (03/01/05) - Genesis = //============================================================================= //----- Include files --------------------------------------------------------- #include "smpl.h" // Needed for SMPL #include // Needed for printf() #include // Needed for assert macro #include // Needed for atof() //===== Main program ========================================================== void main(int argc, char *argv[]) { real Ta; // Mean interarrival time real Ts_1 = 10; // Mean service time for server #1 real Ts_2 = 10; // Mean service time for server #2 real te; // Total simulation time int customer = 1; // Customer id (always '1' for this simulation) int event; // Event int server1; // Handle for server #1 facility int server2; // Handle for server #2 facility // Initialize SMPL subsystem smpl(0, "Tandem queue model"); // Output usage if (argc != 3) { printf("Usage: tandem Ta te \n"); printf(" where Ta is mean interarrival time \n"); printf(" te is the simulation time \n"); return; } // Parse input arguments and assert the values Ta = atof(argv[1]); te = atof(argv[2]); assert(Ta > 0.0); assert(te > 0.0); // Initialize server facilities server1 = facility("server #1", 1); server2 = facility("server #2", 1); // Schedule arrival event at time 0 to kick-off simulation schedule(1, 0.0, customer); // Loop while simulation time is less than te while (time() < te) { // "Cause" the next event on the event list cause(&event,&customer); // Process the event switch(event) { case 1: // *** Arrival schedule(1, expntl(Ta), customer); schedule(2, 0.0, customer); break; case 2: // *** Request server #1 if (request(server1, customer, 0) == 0) schedule(3, Ts_1, customer); break; case 3: // *** Release server #1 and schedule next queue arrival release(server1, customer); schedule(4, 0.0, customer); break; case 4: // *** Request server #2 if (request(server2, customer, 0) == 0) schedule(5, Ts_2, customer); break; case 5: // *** Release server #2 release(server2, customer); break; default: // *** This is the error case break; } } // Output custom report printf("---------------------------------------------------- \n"); printf("- Mean interarrival time = %f millisec \n", Ta); printf("---------------------------------------------------- \n"); printf("- Utilization for server #1 = %f %% \n", 100.0 * U(server1)); printf("- Mean number in system for server #1 = %f \n", Lq(server1) + U(server1)); printf("- Mean delay server #1 = %f millisec \n", Ta * (Lq(server1) + U(server1))); printf("- Utilization for server #2 = %f %% \n", 100.0 * U(server2)); printf("- Mean number in system for server #2 = %f \n", Lq(server2) + U(server2)); printf("- Mean delay server #2 = %f millisec \n", Ta * (Lq(server2) + U(server2))); printf("---------------------------------------------------- \n"); }