-
Notifications
You must be signed in to change notification settings - Fork 877
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: register agent after creating unique_id and pos attributes #2368
fix: register agent after creating unique_id and pos attributes #2368
Conversation
Performance benchmarks:
|
This code change seems fine to me. There is no particular reason for the ordering in Why do you use a custom hash function in the example? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds smart to first assign all the variables to the agent, and then register with the model. Especially if it helps the hash problem!
Just to clarify, I am fine with the fix, but I think you don't need the hash function in your example anyway, avoiding the need for the fix. Hashing on custom classes is available by default already via |
Initially there was only a However now I looked at the example, |
It's only if you want to to do a custom hash and base this on But go ahead and merge this. |
Merging now. Thanks! |
One gis example uses agent's
unique_id
to compare and hash agents: https://github.com/projectmesa/mesa-examples/blob/5758b6504fb26a2af05d861f29d32a81a07200f6/gis/agents_and_networks/src/agent/building.py#L34-L40It was working until #2328, in which the call to
self.model.register_agent(self)
inAgent.__init__()
was moved from belowself.unique_id = next(self._ids[model])
to above it.As a result, in the gis example we now have the following error message:
This PR should fix it. But I'm not very sure whether this will cause any trouble.