def agent_obstacle(agents, obstacles, mask): if is_model(agents, 'circular'): agent_circular_obstacle(agents, obstacles, mask) elif is_model(agents, 'three_circle'): agent_three_circle_obstacle(agents, obstacles, mask) else: raise InvalidType
def agents(self, agents): if is_model(agents, 'circular'): self.__agents = CircularAgents(agents) self.agents.addItem(self) self.agents.setData(agents) elif is_model(agents, 'three_circle'): self.__agents = ThreeCircleAgents(agents) self.agents.addItem(self) self.agents.setData(agents) else: raise FeatureNotImplemented('Wrong agents type: "{}"'.format( agents))
def agent_agent_block_list(agents, cell_size): points_indices, cells_count, cells_offset, grid_shape = add_to_cells( agents['position'], cell_size) cell_indices = np.arange(len(cells_count)) neigh_cells = neighboring_cells(grid_shape) if is_model(agents, 'circular'): agent_agent_circular(agents, cell_indices, neigh_cells, points_indices, cells_count, cells_offset) elif is_model(agents, 'three_circle'): agent_agent_three_circle(agents, cell_indices, neigh_cells, points_indices, cells_count, cells_offset) else: raise InvalidType
def update(self): agents = self.simulation.agents.array force = force_fluctuation(agents['mass'], agents['std_rand_force']) agents['force'] += force if is_model(agents, 'three_circle'): torque = torque_fluctuation(agents['inertia_rot'], agents['std_rand_torque']) agents['torque'] += torque
def update(self): agents = self.simulation.agents.array mask = agents['active'] agents['force'][mask] += force_fluctuation( agents['mass'][mask], agents['std_rand_force'][mask]) if is_model(agents, 'three_circle'): agents['torque'][mask] += torque_fluctuation( agents['inertia_rot'][mask], agents['std_rand_torque'][mask])
def velocity_verlet_integrator_init(agents, dt_min, dt_max): dt = adaptive_timestep(agents, dt_min, dt_max) translational_euler(agents, dt) for agent in agents: agent['force_prev'][:] = agent['force'][:] if is_model(agents, 'three_circle'): rotational_euler(agents, dt) for agent in agents: agent['torque_prev'] = agent['torque'] shoulders(agents) return dt
def velocity_verlet_integrator(agents, dt_min, dt_max): r"""Velocity verlet integrator algorithm Translational motion 1. .. math:: \mathbf{v}_{k+1/2} = \mathbf{v}_{k} + \frac{1}{2} a_{k} \Delta t 2. .. math:: \mathbf{x}_{k+1} = \mathbf{x}_{k} + \mathbf{v}_{k+1/2} \Delta t 3. .. math:: a_{k+1} = \mathbf{f}_{k+1} / m 4. .. math:: \mathbf{v}_{k+1} = \mathbf{v}_{k+1/2} + \frac{1}{2} a_{k+1} \Delta t .. Todo:: Rotational motion Args: agents (Agent): dt_min (float): Minimum timestep :math:`\Delta x_{min}` for adaptive integration. dt_max (float): Maximum timestep :math:`\Delta x_{max}` for adaptive integration. Yields: float: Timestep :math:`\Delta t` that was used for integration. References - https://en.wikipedia.org/wiki/Verlet_integration#Velocity_Verlet """ dt = adaptive_timestep(agents, dt_min, dt_max) translational_verlet(agents, dt) if is_model(agents, 'three_circle'): rotational_verlet(agents, dt) shoulders(agents) return dt
def update(self): agents = self.simulation.agents.array force_adjust_agents(agents) if is_model(agents, 'three_circle'): torque_adjust_agents(agents)
def update(self): agents = self.simulation.agents.array agents['force'] = 0 if is_model(agents, 'three_circle'): agents['torque'] = 0
def update(self): if is_model(self.simulation.agents.array, 'three_circle'): orient_towards_target_direction(self.simulation.agents.array)
def update(self): agents = self.simulation.agents.array mask = agents['active'] force_adjust_agents(agents, mask) if is_model(agents, 'three_circle'): torque_adjust_agents(agents, mask)
def __init__(self, agents): super().__init__() assert is_model(agents, 'three_circle'), \ 'Agent should the three_circle model'
def __init__(self, agents): super().__init__() assert is_model(agents, 'circular'), 'Agent should be circular model'