def task_1_7_3(queue_size): """ Execute bonus task 1.7.3. """ # TODO Bonus Task 1.7.3: Your code goes here (if necessary) sim_param = SimParam() random.seed(sim_param.SEED) sim = Simulation(sim_param) sim.sim_param.S=queue_size result_set=[] for i in range(sim.sim_param.NO_OF_RUNS): sim.reset() sim_result=sim.do_simulation() result_set.append(sim_result.blocking_probability) result_length=len(result_set) n, bins, patches = pylab.hist(result_set) nc=np.cumsum(n/result_length) cdf=[0.0] for i in nc: cdf.append(i) sim_param = SimParam() random.seed(sim_param.SEED) sim_param.SIM_TIME = 1000000 sim_param.MAX_DROPPED = 100 sim_param.NO_OF_RUNS = 100 sim = Simulation(sim_param) sim.sim_param.S=queue_size result_set=[] for i in range(sim.sim_param.NO_OF_RUNS): sim.reset() sim_result=sim.do_simulation() result_set.append(sim_result.blocking_probability) result_length=len(result_set) n1, bins1, patches1 = pylab.hist(result_set) nc1=np.cumsum(n/result_length) cdf1=[0.0] for i in nc: cdf1.append(i) pylab.figure(1) pylab.xlabel('blocking_probability') pylab.ylabel('density') pylab.title('Histogram of the probability density function') pylab.hist(n, bins) pylab.hist(n1, bins1) pylab.figure(2) pylab.xlim(0.0,1.0) pylab.ylim(0.0,1.0) pylab.xlabel('blocking_probability') pylab.ylabel('CDF') pylab.title('CDF function') line1, = pylab.plot(bins,cdf, marker='o', label='100000 ms, 10 MAX_DROPPED, 1000 runs') line2, = pylab.plot(bins1,cdf1, marker='o', label='1000000 ms, 100 MAX_DROPPED, 100 runs') pylab.legend(handler_map={line1: HandlerLine2D(numpoints=4)}) pylab.show()
def task_1_7_2(): """ Execute task 1.7.2 and perform a simulation study according to the task assignment. :return: Minimum number of buffer spaces to meet requirements. """ sim_param = SimParam() random.seed(sim_param.SEED) sim_param.SIM_TIME = 1000000 sim_param.MAX_DROPPED = 100 sim_param.NO_OF_RUNS = 100 sim = Simulation(sim_param) return do_simulation_study(sim)