-
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
fix: Ensure schedule.steps is always incremented before data collection #93
Conversation
Could you describe the problem and why this solution fixed it, for clarity? |
The problem is when trade is disabled, the steps never get incremented because the code exits early in this code branch. Needs a manual |
Would this work? If so, I think it's more elegant: def step(self):
"""
Unique step function that does staged activation of sugar and spice
and then randomly activates traders
"""
# Step Resource agents
for resource in self.schedule.agents_by_type[Resource]:
resource.step()
# Step trader agents
trader_shuffle = self.randomize_traders()
for agent in trader_shuffle:
agent.prices = []
agent.trade_partners = []
agent.move()
agent.eat()
agent.maybe_die()
if self.enable_trade:
# If trade is enabled, shuffle and proceed with trading
trader_shuffle = self.randomize_traders()
for agent in trader_shuffle:
agent.trade_with_neighbors()
# Update step count and collect data
self.schedule.steps += 1
self.datacollector.collect(self) |
No it doesn't, because there are more lines of code beyond mesa-examples/examples/sugarscape_g1mt/sugarscape_g1mt/model.py Lines 188 to 205 in cf38477
|
We can optimize the code clarity later. This PR's scope is to fix the test issue with a very localized patch. |
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.
Indeed, this PR fixes the issue. We can refactor later.
This replaces #92.