Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Jan 3, 2025
1 parent 8f04312 commit 416455a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
8 changes: 4 additions & 4 deletions mesa/examples/basic/boid_flockers/agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (
Expand All @@ -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)
Expand Down
19 changes: 10 additions & 9 deletions mesa/experimental/continuous_space/continuous_space.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,29 @@

from mesa.agent import Agent, AgentSet

from line_profiler_pycharm import profile

class ContinuousSpace:
"""Continuous space where each agent can have an arbitrary position."""

@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):
Expand Down Expand Up @@ -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, :]

Expand Down

0 comments on commit 416455a

Please sign in to comment.