//====================================================== file = as3_1ec.c ===== //= Simulation of booting-up multiple server with failure probability = //============================================================================= //= Notes: 1) This is assignment #1 for CIS 4930 (Simulation) = //= - This is the extra credit solution = //= 2) The theoretical solution for 10 + 1 servers is: = //= Percent on time = 100.0 * = //= (Pr[0 of 10 fail] + Pr[1 of 10 fail] * (1 - Pr[boot fail)) = //= where Pr[0 of 10 fail] = (1 - Pr[boot fail])^10 and = //= Pr[1 of 10 fail] = 10*(1 - Pr[boot fail])^9 * Pr[boot fail] = //= for Pr[boot fail] = 0.01 the answer is, 99.482% = //=---------------------------------------------------------------------------= //= Build: bcc32 as3_1ec.c, gcc -o as3_1ec as3_1ec.c = //=---------------------------------------------------------------------------= //= Execute: as3_1ec = //=---------------------------------------------------------------------------= //= History: KJC (12/16/98) - Genesis = //= KJC (12/16/98) - Modified as3_1sol.c for the extra credit = //= requirement = //============================================================================= //----- Include files --------------------------------------------------------- #include // Needed for printf() #include // Needed for rand() and RAND_MAX //----- Constants ------------------------------------------------------------- #define FALSE 0 // Boolean false #define TRUE 1 // Boolean true #define NUM_DAYS 10000 // Number of days to simulate #define NUM_SERVERS 11 // Number of servers #define NUM_ALLOW_FAIL 1 // Number of allowed failures #define FAIL_PERCENT 1.0 // Percent of time a boot-up fails //----- Function prototypes --------------------------------------------------- double rand_val(void); // Generate random value between 0.0 and 1.0 //===== Main program ========================================================== void main(void) { int i, j; // Loop counters int sum_fail; // Counter for "opening late" days int fail; // Failure flag (set to TRUE or FALSE) int num_fail; // Number of failed servers in a given morning double on_time; // Percentage of days on which mall opens on time // Initialize sum_fail to zero sum_fail = 0; // Output a "running" banner printf(">>> The simulation is running for %d days... \n", NUM_DAYS); // Run the simulation for NUM_DAYS for (i=0; i NUM_ALLOW_FAIL) fail = TRUE; } } // Increment the number of days with a failure if (fail == TRUE) sum_fail++; } // Compute percent of days on which we open on time on_time = 100.0 * ((double) (NUM_DAYS - sum_fail) / NUM_DAYS); // Output results printf("============================================================= \n"); printf("== *** Results from server boot-up simulation *** == \n"); printf("============================================================= \n"); printf("= PROBLEM INPUT: \n"); printf("= Number of days simulated = %d days \n", NUM_DAYS); printf("= Number of servers = %d servers \n", NUM_SERVERS); printf("= Number of allowed fails = %d servers \n", NUM_ALLOW_FAIL); printf("= Boot-up failure percent = %6.3f %% \n", FAIL_PERCENT); printf("============================================================= \n"); printf("= PROBLEM OUTPUT: \n"); printf("= Days opening on time = %6.3f %% \n", on_time); printf("============================================================= \n"); } //============================================================================= //= Function to return a random value between 0.0 and 1.0 = //============================================================================= double rand_val(void) { double z; // Random value to be generated and returned // Use rand() and RAND_MAX defined in stdlib() z = (double) rand() / RAND_MAX; return(z); }