-
Notifications
You must be signed in to change notification settings - Fork 165
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
refactor: Simplify Schelling code #222
Conversation
e488ab1
to
fc943ed
Compare
1. Remove unused model attributes 2. Make `similar` calculation more natural language readable
fc943ed
to
68ff95e
Compare
@@ -6,24 +6,21 @@ class SchellingAgent(mesa.Agent): | |||
Schelling segregation agent | |||
""" | |||
|
|||
def __init__(self, model, agent_type): | |||
def __init__(self, model: mesa.Model, agent_type: int) -> None: | |||
""" | |||
Create a new Schelling agent. |
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.
This docstring is self explanatory for anyone knowing what __init__
does, and should be considered a superfluous documentation.
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.
I have read several articles about superfluous documentation, but couldn't find a good reference that explains it. Maybe this SO thread does it.
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.
Thanks, especially the step simplification is really nice.
One comment, otherwise good. Maybe check with @quaquel if it doesn’t conflict his work.
@@ -95,5 +88,4 @@ def step(self): | |||
|
|||
self.datacollector.collect(self) | |||
|
|||
if self.happy == len(self.agents): | |||
self.running = False | |||
self.running = self.happy != len(self.agents) |
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.
While this is fully correct, I find it less readable. Maybe this could also be resolved with a comment.
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.
My experience is the other way around. I found this very clear.
* refactor: Simplify Schelling code Ported from projectmesa/mesa-examples#222. * Update benchmarks/Schelling/schelling.py Co-authored-by: Ewout ter Hoeven <[email protected]> * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: Jan Kwakkel <[email protected]> Co-authored-by: Ewout ter Hoeven <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
* refactor: Simplify Schelling code Ported from projectmesa/mesa-examples#222. * Update benchmarks/Schelling/schelling.py Co-authored-by: Ewout ter Hoeven <[email protected]> * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: Jan Kwakkel <[email protected]> Co-authored-by: Ewout ter Hoeven <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
similar
calculation more natural language readableWith these changes and
shuffle_do
, the Schelling code in https://github.com/JuliaDynamics/ABMFrameworksComparison should go down from 44 to ~33, closer to Agents.jl's 28.