def run(self, aseed): """ PEM """ seed(aseed) self.counter = Resource(1, name="Clerk", sim=self) self.Mon = Monitor('Time in the Bank', sim=self) source = Source(sim=self) self.activate(source, source.generate(number=20, rate=0.1), at=0.0) self.simulate(until=maxTime)
def run(self, aseed): self.initialize() seed(aseed) self.k = Resource(capacity=Nc, name="Clerk", sim=self) self.wM = Monitor(sim=self) s = Source('Source', sim=self) self.activate(s, s.generate(number=maxNumber, interval=ARRint), at=0.0) self.simulate(until=maxTime) return (self.wM.count(), self.wM.mean())
def __init__(self, model, proc_info): Process.__init__(self, name=proc_info.name, sim=model) self._model = model self._internal_id = Processor._identifier Processor._identifier += 1 self.identifier = proc_info.identifier self._running = None self.was_running = None self._evts = deque([]) self.sched = model.scheduler self.monitor = Monitor(name="Monitor" + proc_info.name, sim=model) self._caches = [] self._penalty = proc_info.penalty self._cs_overhead = proc_info.cs_overhead self._cl_overhead = proc_info.cl_overhead self._migration_overhead = proc_info.migration_overhead self.set_caches(proc_info.caches) self.timer_monitor = Monitor(name="Monitor Timer" + proc_info.name, sim=model) self._speed = proc_info.speed
def __init__(self, registry_type=Registry, broker_means=dists.normal(0.05), **kw): super(MdsModel, self).__init__(**kw) regions = self.graph.regions self.regions = [i for i in range(regions[0] * regions[1])] self.brokers = dict() for r in self.regions: node = self.random_region_node(r) node.server.service_time = self.service_dist(broker_means()) broker = Broker(r, node, registry_type(), 60, self.brokers) # give them an intitial picture of the grid for node in self.graph.nodes_in_region(r): state = ResourceState(node.resource_agent, node.resource.free) broker.registry.update_state(state) self.brokers[r] = broker for node in self.graph.nodes_iter(): node.broker = self.brokers[node.region] # this nodes resource agent node.resource_agent = MdsResourceAgent(node, 30) # mapping of jobagents at this node # make a link to fast comms to the broker self.graph.make_link(node, node.broker.node) # ensure brokers have fast links to each other for i, broker in enumerate(self.brokers.itervalues()): for other in self.brokers.values()[i:]: self.graph.make_link(broker.node, other.node) self.mons["broker_util"] = Monitor("broker_util") self.mons["broker_queue"] = Monitor("broker_queue")
def __init__(self, sim, task_info): """ Args: - `sim`: :class:`Model <simso.core.Model>` instance. - `task_info`: A :class:`TaskInfo` representing the Task. :type sim: Model :type task_info: TaskInfo """ Process.__init__(self, name=task_info.name, sim=sim) self.name = task_info.name self._task_info = task_info self._monitor = Monitor(name="Monitor" + self.name + "_states", sim=sim) self._activations_fifo = deque([]) self._sim = sim self.cpu = None self._etm = sim.etm self._job_count = 0 self._last_cpu = None self._cpi_alone = {} self._jobs = [] self.job = None
def __init__(self, epidemic_params): """The constructor of the class. Full params' list: - nr_individuals: number of individuals in the population - initial_infects: number of infects at the start of the simulation - initial_immunes: number of immunes at the start of the simulation - infect_prob: probability of getting infected after a contact with an infect - contact_rate: rate of the contact between individuals - recover_rate: rate of recover from infection - immune_after_recovery: if true, individuals becomes immunes after recovery - immunization_vanish_rate: if not zero, immunization is temporary with given rate - death_rate: rate of death caused by epidemic - newborn_can_be_infect: if true, newborn can be infect - newborn_can_be_immune: if true, newborn can be immune - newborn_prob: probability that a new individual born after a contact - natural_death_prob: probability of death not caused by epidemic - run_time: time duration of the simulation - debug: show more info about the running simulation - process_debug: show more info about SimPy processes during the simulation - progress: show a progress indicator during the simulation - stats: show some stats at the end of the simulation - plot: show a plot representing the evolution of the population at the end of the simulation """ # setting up the epidemic's parameters with metaprogramming for param in epidemic_params: self.__dict__[param] = epidemic_params.get(param) # setting the uninitialized parameters to their default values self.check_and_set_default_value(['initial_immunes', 'recover_rate', 'death_rate', 'immunization_vanish_rate', 'newborn_prob', 'natural_death_prob'], ['immune_after_recovery', 'newborn_can_be_immune', 'newborn_can_be_infect', 'debug', 'process_debug', 'progress', 'stats', 'plot']) # setting the random number generator using the python standard one self.rng = random.Random() # checking some features of the model from parameters passed to the constructor self.model_has_immunization = self.model_has_immunization() self.model_immunization_is_permanent = self.model_immunization_is_permanent() self.model_has_recovering = self.model_has_recovering() self.model_has_death = self.model_has_death() self.model_has_vital_dynamics = self.model_has_vital_dynamics() self.model_newborns_always_susceptibles = self.model_newborns_always_susceptibles() self.model_has_new_susceptibles = self.model_has_new_susceptibles() self.model_has_new_infects = self.model_has_new_infects() # initialize the population counters self.total_infects = self.initial_infects self.total_immunes = self.initial_immunes self.total_susceptibles = self.nr_individuals - self.initial_infects - self.initial_immunes self.total_newborns = 0 self.total_natural_deaths = 0 self.total_deaths = 0 # setting up the monitors for watching interesting variables self.m_suscettibili = Monitor(name="Suscettibili", ylab="suscettibili") self.m_suscettibili.append([0, self.total_susceptibles]) self.m_infetti = Monitor(name="Infetti", ylab='infetti') self.m_infetti.append([0, self.initial_infects]) if self.model_has_immunization: self.m_immuni = Monitor(name="Immuni", ylab='immuni') self.m_immuni.append([0, self.initial_immunes]) # setting up the array of all the individuals partecipating to the simulation self.all_individuals = [] # initialize the simulation environment (time, events, ...) initialize() for i in range(self.nr_individuals): # add individuals to the simulation with the specified health_status if i >= (self.nr_individuals - self.initial_infects): ind = self.Individual(self, ind_id=i, health_status='infect') elif i >= (self.nr_individuals - self.initial_infects - self.initial_immunes): ind = self.Individual(self, ind_id=i, health_status='immune') else: ind = self.Individual(self, ind_id=i) # activate it with function live() activate(ind, ind.live(), at=0.0) self.start_time = time.time() if self.process_debug: self.show_processes_status() # start the simulation simulate(until=self.run_time) self.stop_time = time.time() if self.process_debug: self.show_processes_status() # show final stats if required by params if self.stats: self.show_stats() # show plot if required by params if self.plot: self.show_plot()
from SimPy.Simulation import Monitor from random import expovariate m = Monitor() # define the Monitor object, m for i in range(1000): # make the observations y = expovariate(0.1) m.observe(y) # set up and return the completed histogram h = m.histogram(low=0.0, high=20, nbins=30)