Skip to content

SingleGrid position_agent very slow for large grids #1052

@timjdavey

Description

@timjdavey

It's fine for square widths of around 20 cells, but when you 200 it slows right down.

It appears to be caused by the line agent.random.choice(sorted(self.empties)) where it sorts the empties first. I guess it does this so you can replicate the results using random seed?

If you don't care about replication however, it's unreasonably slow and can be fixed by using agent.random.choice(list(self.empties)) instead (speeding it enormously).

I'm not sure of the design decisions here, but maybe it's worth having two functions to make it clear or passing some sort of bool?

https://mesa.readthedocs.io/en/stable/mesa.html#mesa.space.SingleGrid.position_agent

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions