Skip to content

Commit

Permalink
cell_space: Allow CellCollection to be empty
Browse files Browse the repository at this point in the history
Sometimes it's useful to have any empty cell collection in the cell space, which can happen after selection with no cells that meet the selection requirements.

However, self._capacity would give an error, because there were no cell to derive the capacity from. This PR resolves that error.
  • Loading branch information
EwoutH committed Nov 13, 2024
1 parent 54d7e28 commit ce391ca
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions mesa/experimental/cell_space/cell_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,10 @@ def __init__(
else:
self._cells = {cell: cell.agents for cell in cells}

#
self._capacity: int = next(iter(self._cells.keys())).capacity
# Get capacity from first cell if collection is not empty
self._capacity: int | None = (
next(iter(self._cells.keys())).capacity if self._cells else None
)

if random is None:
warnings.warn(
Expand Down

0 comments on commit ce391ca

Please sign in to comment.