Skip to content

Commit 39a6ccc

Browse files
committed
refactor: Remove dependence on model.schedule
1 parent 0bd4429 commit 39a6ccc

File tree

2 files changed

+7
-9
lines changed

2 files changed

+7
-9
lines changed

mesa/datacollection.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@
1414
1515
When the collect() method is called, each model-level function is called, with
1616
the model as the argument, and the results associated with the relevant
17-
variable. Then the agent-level functions are called on each agent in the model
18-
scheduler.
17+
variable. Then the agent-level functions are called on each agent.
1918
2019
Additionally, other objects can write directly to tables by passing in an
2120
appropriate dictionary object for a table row.
@@ -30,8 +29,7 @@
3029
Finally, DataCollector can create a pandas DataFrame from each collection.
3130
3231
The default DataCollector here makes several assumptions:
33-
* The model has a schedule object called 'schedule'
34-
* The schedule has an agent list called agents
32+
* The model has an agent list called agents
3533
* For collecting agent-level variables, agents must have a unique_id
3634
"""
3735
import itertools
@@ -65,7 +63,7 @@ def __init__(
6563
6664
Model reporters can take four types of arguments:
6765
1. Lambda function:
68-
{"agent_count": lambda m: m.schedule.get_agent_count()}
66+
{"agent_count": lambda m: len(m.agents)}
6967
2. Method of a class/instance:
7068
{"agent_count": self.get_agent_count} # self here is a class instance
7169
{"agent_count": Model.get_agent_count} # Model here is a class
@@ -178,11 +176,11 @@ def _record_agents(self, model):
178176
rep_funcs = self.agent_reporters.values()
179177

180178
def get_reports(agent):
181-
_prefix = (agent.model.schedule.steps, agent.unique_id)
179+
_prefix = (agent.model.steps, agent.unique_id)
182180
reports = tuple(rep(agent) for rep in rep_funcs)
183181
return _prefix + reports
184182

185-
agent_records = map(get_reports, model.schedule.agents)
183+
agent_records = map(get_reports, model.agents)
186184
return agent_records
187185

188186
def collect(self, model):
@@ -205,7 +203,7 @@ def collect(self, model):
205203

206204
if self.agent_reporters:
207205
agent_records = self._record_agents(model)
208-
self._agent_records[model.schedule.steps] = list(agent_records)
206+
self._agent_records[model.steps] = list(agent_records)
209207

210208
def add_table_row(self, table_name, row, ignore_missing=False):
211209
"""Add a row dictionary to a specific table.

mesa/experimental/jupyter_viz.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ def on_value_play(change):
182182
def do_step():
183183
model.step()
184184
previous_step.value = current_step.value
185-
current_step.value = model.schedule.steps
185+
current_step.value = model.steps
186186

187187
def do_play():
188188
model.running = True

0 commit comments

Comments
 (0)