def main(): if len(sys.argv) != 11: print( "Input parameters must be: 'lambda mu theta C c0 Q L H simulation_time repeats'" ) else: start_time = time.time() lambd = float(sys.argv[1]) mu = float(sys.argv[2]) theta = float(sys.argv[3]) C = int(sys.argv[4]) c0 = int(sys.argv[5]) Q = int(sys.argv[6]) L = int(sys.argv[7]) H = int(sys.argv[8]) simulation_time = int(sys.argv[9]) repeats = int(sys.argv[10]) print("Test for M/M/C[c0]/R[L,H]: lambda =", lambd, ", mu =", mu, ", theta = ", theta, ", C =", C, ", c0=", c0, ", Q =", Q, ", sim time =", simulation_time, ", repeats =", repeats) B = 0 W = 0 N = 0 is_debug = False simulation = Simulation("m/m/c[c0]/r[l,h]", lambd, mu, theta, C, c0, L, H, simulation_time, Q, is_debug) for i in range(0, repeats): simulation = Simulation("m/m/c[c0]/r[l,h]", lambd, mu, theta, C, c0, L, H, simulation_time, Q, is_debug) simulation.start_requests(simulation_time) B += simulation.queue.blocked / (simulation.queue.blocked + simulation.served_count) w = 0 for request in simulation.served_requests: w += request.w for request in simulation.queue.blocked_requests: w += request.w W += w / (simulation.served_count + len(simulation.queue.blocked_requests)) N += (w / (simulation.served_count + len(simulation.queue.blocked_requests))) * lambd B /= repeats W /= repeats N /= repeats end_time = time.time() print("B =", B, "\nW =", W, "\nN =", N) print("Execution time = %s seconds" % (end_time - start_time))
def generate_statistics(self): generated_values = [] t1 = time.time() for lambd in self.range_dict[PARAM.LAMBDA]: for mu in self.range_dict[PARAM.MU]: for theta in self.range_dict[PARAM.THETA]: for C in self.range_dict[PARAM.C]: for c0 in self.range_dict[PARAM.c0]: for L in self.range_dict[PARAM.L]: for H in self.range_dict[PARAM.H]: for Q in self.range_dict[PARAM.Q]: if lambd <= 0: continue if mu <= 0: continue if theta <= 0: continue if C <= 0: continue if c0 <= 0: continue if L <= 0: continue if H <= 0: continue if Q <= 0: continue if c0 > C or c0 < 0: continue if H - L < 2: continue if Q - H <= 2: continue if H < L or H > Q: continue if L > Q: continue start_time = time.time() generated_values_storage = Generated_values_storage( ) for repeats in self.range_dict[ PARAM.REPEATS]: sim = Simulation( self.mode, lambd, mu, theta, C, c0, L, H, self.simulation_time, Q, self.is_debug) if (self.strategy == "time"): sim.start() else: sim.start_requests( self.simulation_time) generated_values_storage.add(sim) end_time = time.time() generated_values_storage.normalize( self.parameters[ PARAM.REPEATS].end_value) generated_values.append( generated_values_storage) self.log(lambd, mu, theta, C, c0, L, H, Q, start_time, end_time) t2 = time.time() print("Total simulation time = %.5f" % (t2 - t1)) return generated_values
def main(): if len(sys.argv) != 11: print("Input parameters must be: 'lambda mu theta C c0 Q L H simulation_time repeats'") else: start_time = time.time() lambd = float(sys.argv[1]) mu = float(sys.argv[2]) theta = float(sys.argv[3]) C = int(sys.argv[4]) c0 = int(sys.argv[5]) Q = int(sys.argv[6]) L = int(sys.argv[7]) H = int(sys.argv[8]) simulation_time = int(sys.argv[9]) repeats = int(sys.argv[10]) print("Difference test for M/M/C[c0]/R: lambda =", lambd, ", mu =", mu, ", C =", C, ", c0=", c0,", Q =", Q, ", theta = ", theta, ", sim time =", simulation_time, ", repeats =", repeats) print("c0 will be used for theoretical m/m/c/r calculation") ### theoretical theoretical_mmcr = MMCR(lambd, mu, c0, Q) theoretical_result = theoretical_mmcr.run() B = theoretical_result[0] W = theoretical_result[1] N = theoretical_result[2] ### sim B2 = 0 W2 = 0 N2 = 0 is_debug = False if is_debug: print("Q=",Q) simulation = Simulation("m/m/c[c0]/r", lambd, mu, theta, C, c0, L, H, simulation_time, Q, is_debug) for i in range(0, repeats): simulation = Simulation("m/m/c[c0]/r", lambd, mu, theta, C, c0, L, H, simulation_time, Q, is_debug) simulation.start_requests(10000) B2 += simulation.queue.blocked / (simulation.queue.blocked + simulation.served_count) w = 0 for request in simulation.served_requests: w += request.w for request in simulation.queue.blocked_requests: w += request.w W2 += w / (simulation.served_count + len(simulation.queue.blocked_requests)) N2 += (w / (simulation.served_count + len(simulation.queue.blocked_requests))) * lambd B2 /= repeats W2 /= repeats N2 /= repeats end_time = time.time() print("theoretical B =", B, ", simulation B=", B2, ", Difference = ", abs((B2 - B) / B), "\ntheoretical W =", W, ", simulation W=", W2, ", Difference = ", abs((W2 - W) / W), "\ntheoretical N =", N, ", simulation N=", N2, ", Difference = ", abs((N2 - N) / N)) print("Execution time = %s seconds" % (end_time - start_time))