diff --git a/mesa/examples/basic/boid_flockers/agents.py b/mesa/examples/basic/boid_flockers/agents.py index 96f12b4a585..58151d442a0 100644 --- a/mesa/examples/basic/boid_flockers/agents.py +++ b/mesa/examples/basic/boid_flockers/agents.py @@ -71,9 +71,7 @@ def step(self): self.position += self.direction * self.speed return - delta = self.space.calculate_difference_vector( - self.position, agents=neighbors - ) + delta = self.space.calculate_difference_vector(self.position, agents=neighbors) cohere_vector = np.sum(delta, axis=0) * self.cohere_factor separation_vector = ( @@ -87,7 +85,9 @@ def step(self): ) # Update direction based on the three behaviors - self.direction += (cohere_vector + separation_vector + match_vector) / len(neighbors) + self.direction += (cohere_vector + separation_vector + match_vector) / len( + neighbors + ) # Normalize direction vector self.direction /= np.linalg.norm(self.direction) diff --git a/mesa/experimental/continuous_space/continuous_space.py b/mesa/experimental/continuous_space/continuous_space.py index 094a81c88bc..8dc78b1037e 100644 --- a/mesa/experimental/continuous_space/continuous_space.py +++ b/mesa/experimental/continuous_space/continuous_space.py @@ -9,7 +9,6 @@ from mesa.agent import Agent, AgentSet -from line_profiler_pycharm import profile class ContinuousSpace: """Continuous space where each agent can have an arbitrary position.""" @@ -17,22 +16,22 @@ class ContinuousSpace: @property def x_min(self): # compatability with solara_viz - return self.dimensions[0,0] + return self.dimensions[0, 0] @property def x_max(self): # compatability with solara_viz - return self.dimensions[0,1] + return self.dimensions[0, 1] @property def y_min(self): # compatability with solara_viz - return self.dimensions[1,0] + return self.dimensions[1, 0] @property def y_max(self): # compatability with solara_viz - return self.dimensions[1,1] + return self.dimensions[1, 1] @property def width(self): @@ -139,12 +138,14 @@ def _remove_agent(self, agent: Agent) -> None: self._positions_in_use[index] = False self._agents[index] = None - def calculate_difference_vector( - self, point: np.ndarray, agents=None - ) -> np.ndarray: + def calculate_difference_vector(self, point: np.ndarray, agents=None) -> np.ndarray: """Calculate the difference vector between the point and all agents.""" point = np.asanyarray(point) - positions = self.agent_positions if agents is None else self._agent_positions[[self._agent_to_index[a] for a in agents]] + positions = ( + self.agent_positions + if agents is None + else self._agent_positions[[self._agent_to_index[a] for a in agents]] + ) delta = positions - point[np.newaxis, :]