class Environment(object): def __init__(self, verbose=False, output_file=sys.stdout): self.verbose = verbose self.output_file = output_file def populate(self,components): self.simulator = Simulator(components, self.verbose, self.output_file) self.components = self.simulator.components def simulate(self, untill=0, run_untill_queue_not_empty=False): self.simulator.run(untill, run_untill_queue_not_empty)
from t100.core.simulator import Simulator from t100.core.base_components import * def creation_tax_expression(timestamp): # 2 events each five minuts return 2.0/(60*5) def execution_time_expression(timestamp): # execution takes 60 seconds +- 30 return 60+random.randint(-30,+30) if __name__=='__main__': acc = 0 for i in range(100): q = Queue() s = Source(output=q, creation_tax_expression=creation_tax_expression, execution_time_expression=execution_time_expression) p = Process(inputs=[q]) steps_number = 60*60 #1 second each timestamp, running for 60 minuts simul = Simulator(components=[q,s,p], verbose=True) simul.run(untill=steps_number) q_size = len(simul.components['queue'][0]) acc += q_size print acc/100.
from t100.core.simulator import Simulator from t100.core.components import * """ Example inter_03 for informations about this examples, see docs/examples/inter_03 """ if __name__ == "__main__": steps_number = 60 * 60 execution_time_expression = lambda: 60 + random.randint(-30, +30) delta_t_expression = lambda: 30 + random.randint(1, 10) s = Source(output=q, creation_tax=2.0 / (60 * 5), execution_time_expression=execution_time_expression) ps = ProcessSource( output=q, # process source execution_time_expression=execution_time_expression, delta_t_expression=delta_t_expression, verbose=True, ) p = Process(inputs=[q], source=ps, output_ratio=0.1) p.output = p simul = Simulator(components=[q, s, p], verbose=True) simul.run(untill=steps_number, run_untill_queue_not_empty=True)
from t100.core.simulator import Simulator from t100.core.base_components import * if __name__=='__main__': acc = 0 for i in range(100): q = Queue() s = Source(output=q) p = Process(inputs=[q]) simul = Simulator(components=[q,s,p]) simul.run(untill=1000) q_size = len(simul.components['queue'][0]) acc += q_size print acc/100.0
[01] from t100.core.simulator import Simulator [02] from t100.core.base_components import * [03] [04] [05] if __name__=='__main__': [06] [07] execution_time_expression = \ lambda _ : 60+random.randint(-30,+30) [08] creation_tax_expression = lambda _ : 2.0/(60*5) [09] [10] acc = 0 [11] q = Queue() [12] s = Source(output=q, [13] creation_tax_expression=creation_tax_expression, [14] execution_time_expression=execution_time_expression) [15] [16] p = Process(inputs=[q]) [17] [18] steps_number = 60*60 [19] [20] simul = Simulator(components=[q,s,p]) [21] simul.run(untill=steps_number) [22] q_size = len(simul.components['queue'][0]) [23] [24] print q_size [25]