Skip to content

Conversation

@pgervila
Copy link
Contributor

This addresses both #352 and #302, basically the same issue
If agents are deleted while looping over agents list in the model schedule,
looping becomes unpredictable and agents step methods for some agents may not be called for a given model step
A simple solution seems to be to iterate over a shallow copy of the agent list by using [:]
A shallow copy constructs a new compound object and then (to the extent possible) inserts references into it to the objects found in the original. So the objects we get from iteration are referencing the originals, but the copied list is not modified if agents are removed

A dict implementation could still be a preferable solution in terms of performance ( see #305) , but this one should have less impact

If agents are deleted while looping over agents list in the model schedule,
looping becomes unpredictable and agents step methods for some agents may not be called for a given model step
@coveralls
Copy link

coveralls commented Feb 17, 2017

Coverage Status

Coverage remained the same at 76.408% when pulling 3c87997 on pgervila:schedule-agents-loop into bda9333 on projectmesa:master.

@dmasad
Copy link
Member

dmasad commented Mar 5, 2017

This definitely seems like a solid placeholder solution. As a longer-term thing, we do need to decide what the correct / desired behavior is when an agent is removed mid-step -- should they still potentially be activated one last time (which I believe is the case here), or removed immediately even if they're still in the queue.

Will merge as soon as the Travis issue is figured out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants