Skip to content

Commit

Permalink
agent positions can be read from cobe generated json file
Browse files Browse the repository at this point in the history
  • Loading branch information
mezdahun committed Jan 18, 2024
1 parent 2cbe2fd commit bb95bc5
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions abm/simulation/sims.py
Original file line number Diff line number Diff line change
Expand Up @@ -718,8 +718,11 @@ def find_closest_agent(self, pos):
if not ag.cobe_updated:
distances.append(np.linalg.norm(np.array(pos) - np.array(ag.rect.center)))
ids.append(ag.id)
closest_agent_id = ids[np.argmin(distances)]
return closest_agent_id
if len(distances) > 0:
closest_agent_id = ids[np.argmin(distances)]
return closest_agent_id
else:
return None

def update_agent_positions_with_cobe(self, position_list):
"""Updating agent positions with the positions passed from the COBE system
Expand All @@ -731,12 +734,12 @@ def update_agent_positions_with_cobe(self, position_list):
agent_pos = np.array([agent_dict["x0"], agent_dict["x1"]])
agent_state = agent_dict["MODE"]
target_agent_id = self.find_closest_agent(agent_pos)

target_agent = self.agents.sprites()[target_agent_id]
target_agent.position = agent_pos
target_agent.set_mode(agent_state)
target_agent.draw_update()
target_agent.cobe_updated = True
if target_agent_id is not None:
target_agent = self.agents.sprites()[target_agent_id]
target_agent.position = agent_pos
target_agent.set_mode(agent_state)
target_agent.draw_update()
target_agent.cobe_updated = True

def start(self):

Expand Down

0 comments on commit bb95bc5

Please sign in to comment.