Skip to content

Commit

Permalink
fix: occupied cells sorted by agent_order, assertion to verify best m…
Browse files Browse the repository at this point in the history
…oves aren't duplicated
  • Loading branch information
adamamer20 committed Sep 20, 2024
1 parent ec2437b commit 845aa61
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions examples/sugarscape_ig/ss_polars/agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,16 +200,20 @@ def get_best_moves(self, neighborhood: pl.DataFrame, agent_order):
)
.drop("agent_order")
)
assert best_moves.n_unique() == len(
best_moves
), "Duplicates found in best_moves"
return best_moves

def _prepare_cells(self, neighborhood: pl.DataFrame):
occupied_cells = (
neighborhood[["agent_id_center"]]
neighborhood[["agent_id_center", "agent_order"]]
.unique()
.join(self.pos, left_on="agent_id_center", right_on="unique_id")
.with_columns(
flattened=(pl.col("dim_0") * self.space.dimensions[1] + pl.col("dim_1"))
)["flattened"]
).sort("agent_order")
["flattened"]
.to_numpy()
)
free_cells = np.ones(
Expand Down

0 comments on commit 845aa61

Please sign in to comment.