Skip to content

capacity parameter in grid constructors not honored by most things #3505

@divilian

Description

@divilian

Describe the bug
When instantiating a grid object (e.g., OrthogonalVonNeumannGrid) there is a capacity parameter that ostensibly should limit the number of agents that each cell in that grid can accommodate. But this does not appear to be used, at least in many of the places where this limit could be exceeded.

Expected behavior
I expected an "overfull; move_to operation denied" error to arise when I did this:

m = Model()
grid = OrthogonalVonNeumannGrid((2,2),torus=False, capacity=1)
some_cell = grid.all_cells.cells[0]
bob = CellAgent(m)
julie = CellAgent(m)
bob.move_to(some_cell)
julie.move_to(some_cell)     <-- I expected this to throw an error.
print(some_cell)

output:
Cell((0, 0), [<mesa.discrete_space.cell_agent.CellAgent object at 0x7787172616d0>, 
<mesa.discrete_space.cell_agent.CellAgent object at 0x7787172611d0>])

Instead, the cell happily accepts two agents, even though it is in a grid whose capacity is set to 1.

To Reproduce
See code in previous section.

Additional context
If capacity isn't enforced, then why does it exist? One would think its sole purpose would be to act as a guardrail against attempts like in that sample code.

If this behavior is intended, then at the very least the docstring should have some "just kidding, it doesn't actually enforce this" language. At present it reads:

Type:           OrthogonalVonNeumannGrid
...
Args:
   ...
    capacity: capacity of the grid cell
  ...

Metadata

Metadata

Assignees

No one assigned

    Labels

    backport-candidatePRs we might want to backport to an earlier branchbugRelease notes label

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions