-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Bug: FixedAgent.remove Blocked by Setter #3466
Copy link
Copy link
Closed
Description
Problem: Conflict Between FixedCell and FixedAgent
The issue arises from a contradiction between how FixedCell enforces immobility and how FixedAgent performs cleanup.
Conflict in cell_agent.py
In FixedCell, the cell setter prevents movement:
@cell.setter
def cell(self, cell: Cell | None) -> None:
if self._mesa_cell is not None:
raise ValueError("Cannot move agent in FixedCell")
cell.add_agent(self) # Fails if cell is None
self._mesa_cell = cellBecause this setter blocks reassignment, FixedAgent.remove() bypasses the public API and modifies internal state directly:
def remove(self):
super().remove()
self.cell.remove_agent(self) # Manual cleanup
self._mesa_cell = None # Direct private state changeWhy This Is a Problem
- API Inconsistency
For aCellAgent, removing the agent is simple:
agent.cell = None
For a FixedAgent, the same operation raises:
ValueError("Cannot move agent in FixedCell")
- Fragility
The setter has an additional edge case:
agent.cell = None
If the agent is already None, the setter attempts:
None.add_agent(self)
which raises an error because None has no such method.
- Encapsulation Violation
FixedAgent.remove() modifies the private attribute:
self._mesa_cell = None
If a user performs the same action in their model code, they would be breaking encapsulation, yet the framework itself relies on this workaround.
Result
- Inconsistent agent removal behavior
- Fragile setter logic
- Internal reliance on private state manipulation
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels