Exemplo n.º 1
0
 def assign_agents(cls, particle_num: int, state: np.array, model: Model):
     """
     Assign the state of the particles to the
     locations of the agents.
     :param particle_num
     :param state: The state of the particle to be assigned
     :param model: The model to assign the state to
     :type model: Return the model after having the agents assigned according to the state.
     """
     model.set_state(state, sensor='location')
     return model
Exemplo n.º 2
0
    def step_particle(cls, particle_num: int, model: Model, num_iter: int, particle_std: float, particle_shape: tuple):
        """
        Step a particle, assign the locations of the
        agents to the particle state with some noise, and
        then use the new particle state to set the location
        of the agents.

        :param particle_num: The particle number to step
        :param model: A pointer to the model object associated with the particle that needs to be stepped
        :param num_iter: The number of iterations to step
        :param particle_std: the particle noise standard deviation
        :param particle_shape: the shape of the particle array
        """
        # Force the model to re-seed its random number generator (otherwise each child process
        # has the same generator https://stackoverflow.com/questions/14504866/python-multiprocessing-numpy-random
        model.set_random_seed()
        for i in range(num_iter):
            model.step()

        noise = np.random.normal(0, particle_std ** 2, size=particle_shape)
        state = model.get_state(sensor='location') + noise
        model.set_state(state, sensor='location')
        return model, state