//================================================== file = measureUtil.c ===== //= A CSIM simulation of an M/D/1 with explicit utilization measurement = //============================================================================= //= Notes: 1) Values for lambda and mu are set in the main program = //= 2) Determines utilization in three different ways = //=---------------------------------------------------------------------------= //= Example execution: = //= = //= *** BEGIN SIMULATION *** = //= ============================================================= = //= == *** CSIM M/D/1 queueing system simulation *** == = //= ============================================================= = //= = Lambda = 1.000000 cust/sec = //= = Mu = 3.000000 cust/sec = //= ============================================================= = //= = Total CPU time = 0.967000 sec = //= = Total sim time = 1000000.000000 sec = //= = Total completions = 1001211 cust = //= =------------------------------------------------------------ = //= = >>> Simulation results - = //= =------------------------------------------------------------ = //= = Utilization #1 = 33.333333 % = //= = Utilization #2 = 33.373700 % = //= = Utilization #3 = 33.373700 % = //= = Mean num in system = 0.417360 cust = //= = Mean response time = 0.416855 sec = //= = Mean service time = 0.333333 sec = //= = Mean throughput = 1.001211 cust/sec = //= ============================================================= = //= *** END SIMULATION *** = //=---------------------------------------------------------------------------= //= Build: standard CSIM build = //=---------------------------------------------------------------------------= //= Execute: measureUtil = //=---------------------------------------------------------------------------= //= Author: Ken Christensen = //= University of South Florida = //= WWW: http://www.csee.usf.edu/~christen = //= Email: christen@csee.usf.edu = //=---------------------------------------------------------------------------= //= History: KJC (07/01/13) - Genesis (from mm1_csim.c) = //============================================================================= //----- Includes -------------------------------------------------------------- #include // Needed for printf() #include "csim.h" // Needed for CSIM stuff //----- Defines --------------------------------------------------------------- #define SIM_TIME 1.0e6 // Total simulation time in seconds //----- Globals --------------------------------------------------------------- FACILITY Server; // Declaration of CSIM Server facility int DepartCount; // Departures counter //----- Prototypes ------------------------------------------------------------ void generate(double lambda, double mu); // Customer generator void queue1(double service_time); // Single server queue //============================================================================= //== Main program == //============================================================================= void sim(void) { double lambda; // Mean arrival rate (cust/sec) double mu; // Mean service rate (cust/sec) double util1; // Utilization #1 double util2; // Utilization #2 double util3; // Utilization #3 // Create the simulation create("sim"); // CSIM and variable initializations Server = facility("Server"); DepartCount = 0; // Parameter initializations lambda = 1.0; mu = 3.0; // Output begin-of-simulation banner printf("*** BEGIN SIMULATION *** \n"); // Initiate generate function and hold for SIM_TIME generate(lambda, mu); hold(SIM_TIME); // Compute the utilization in three ways util1 = lambda / mu; util2 = util(Server); util3 = DepartCount * (1.0 / mu) / clock; // Output results printf("============================================================= \n"); printf("== *** CSIM M/D/1 queueing system simulation *** == \n"); printf("============================================================= \n"); printf("= Lambda = %f cust/sec \n", lambda); printf("= Mu = %f cust/sec \n", mu); printf("============================================================= \n"); printf("= Total CPU time = %f sec \n", cputime()); printf("= Total sim time = %f sec \n", clock); printf("= Total completions = %d cust \n", completions(Server)); printf("=------------------------------------------------------------ \n"); printf("= >>> Simulation results - \n"); printf("=------------------------------------------------------------ \n"); printf("= Utilization #1 = %f %% \n", 100.0 * util1); printf("= Utilization #2 = %f %% \n", 100.0 * util2); printf("= Utilization #3 = %f %% \n", 100.0 * util3); printf("= Mean num in system = %f cust \n", qlen(Server)); printf("= Mean response time = %f sec \n", resp(Server)); printf("= Mean service time = %f sec \n", serv(Server)); printf("= Mean throughput = %f cust/sec \n", tput(Server)); printf("============================================================= \n"); // Output end-of-simulation banner printf("*** END SIMULATION *** \n"); } //============================================================================= //== Function to generate Poisson customers == //============================================================================= void generate(double lambda, double mu) { double interarrival_time; // Interarrival time to next send double service_time; // Service time for this customer create("generate"); // Loop forever to create customers while(1) { // Pull an interarrival time and hold for it interarrival_time = exponential(1.0 / lambda); hold(interarrival_time); // Pull a service time and then send the customer to the queue service_time = 1.0 / mu; queue1(service_time); } } //============================================================================= //== Function for single server queue == //============================================================================= void queue1(double service_time) { create("queue1"); // Reserve, hold, and release server reserve(Server); hold(service_time); release(Server); // Increment the departure counter DepartCount++; }