-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Bug: Inconsistency Cell State Management #3068
Copy link
Copy link
Closed
Description
Describe the bug
The Cell class mesa/discrete_space/cell.py maintains redundant state using both cell.empty and cell.is_empty.
This leads to:
- Possible state inconsistency
cell.empty != cell.is_empty - Unnecessary
O(n)list copying during remove_agent() - Use of a generic Exception when cell capacity is exceeded
Expected behavior
- Cell emptiness should have a single source of truth
- Checking whether a cell is empty should not copy the agent list
- Capacity overflow should raise a specific exception type
To Reproduce
from mesa import Model
from mesa.discrete_space import OrthogonalMooreGrid
from mesa.discrete_space.cell_agent import CellAgent
model = Model()
grid = OrthogonalMooreGrid((3, 3), random=model.random)
cell = grid[(0, 0)]
cell._agents.append(CellAgent(model)) # bypass API
assert cell.is_empty
assert cell.empty == True # inconsistent stateAdditional context
remove_agent()triggersself.empty = self.is_emptyis_empty → agents → _agents.copy()causes O(n) overhead- Adding beyond capacity raises generic
Exception
@EwoutH @quaquel I would like to know you thoughts on this particular issue. Can I raise a PR resolving the issue.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels