Skip to content

Commit 7cadddb

Browse files
authored
Adding super().__init__() to MoneyModel tutorial (#2025)
* Adding super().__init__() to MoneyModel tutorial * Reverting metadata changes in intro_tutorial
1 parent 2dc485f commit 7cadddb

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

docs/tutorials/MoneyModel.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ class MoneyModel(mesa.Model):
4343
"""A model with some number of agents."""
4444

4545
def __init__(self, N, width, height):
46+
super().__init__()
4647
self.num_agents = N
4748
self.grid = mesa.space.MultiGrid(width, height, True)
4849
self.schedule = mesa.time.RandomActivation(self)

docs/tutorials/intro_tutorial.ipynb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@
210210
"\n",
211211
"**Model-specific information:** When a model is created the number of agents within the model is specified. The model then creates the agents and places them on the grid. The model also contains a scheduler which controls the order in which agents are activated. The scheduler is also responsible for advancing the model by one step. The model also contains a data collector which collects data from the model. These topics will be covered in more detail later in the tutorial.\n",
212212
"\n",
213-
"**Code implementation:** This is done by creating a new class (or object) that extends `mesa.Model` creating a subclass of the `Model` class from mesa. The new class is named `MoneyModel`. The technical details about the agent object can be found in the [mesa repo](https://github.com/projectmesa/mesa/blob/main/mesa/model.py).\n",
213+
"**Code implementation:** This is done by creating a new class (or object) that extends `mesa.Model` and calls `super().__init__()`, creating a subclass of the `Model` class from mesa. The new class is named `MoneyModel`. The technical details about the agent object can be found in the [mesa repo](https://github.com/projectmesa/mesa/blob/main/mesa/model.py).\n",
214214
"\n",
215215
"The `MoneyModel` class is created with the following code:"
216216
]
@@ -225,6 +225,7 @@
225225
" \"\"\"A model with some number of agents.\"\"\"\n",
226226
"\n",
227227
" def __init__(self, N):\n",
228+
" super().__init__()\n",
228229
" self.num_agents = N\n",
229230
" # Create agents\n",
230231
" for i in range(self.num_agents):\n",
@@ -273,6 +274,7 @@
273274
" \"\"\"A model with some number of agents.\"\"\"\n",
274275
"\n",
275276
" def __init__(self, N):\n",
277+
" super().__init__()\n",
276278
" self.num_agents = N\n",
277279
" # Create scheduler and assign it to the model\n",
278280
" self.schedule = mesa.time.RandomActivation(self)\n",
@@ -561,6 +563,7 @@
561563
" \"\"\"A model with some number of agents.\"\"\"\n",
562564
"\n",
563565
" def __init__(self, N, width, height):\n",
566+
" super().__init__()\n",
564567
" self.num_agents = N\n",
565568
" self.grid = mesa.space.MultiGrid(width, height, True)\n",
566569
" self.schedule = mesa.time.RandomActivation(self)\n",
@@ -674,6 +677,7 @@
674677
" \"\"\"A model with some number of agents.\"\"\"\n",
675678
"\n",
676679
" def __init__(self, N, width, height):\n",
680+
" super().__init__()\n",
677681
" self.num_agents = N\n",
678682
" self.grid = mesa.space.MultiGrid(width, height, True)\n",
679683
" self.schedule = mesa.time.RandomActivation(self)\n",
@@ -796,6 +800,7 @@
796800
" \"\"\"A model with some number of agents.\"\"\"\n",
797801
"\n",
798802
" def __init__(self, N, width, height):\n",
803+
" super().__init__()\n",
799804
" self.num_agents = N\n",
800805
" self.grid = mesa.space.MultiGrid(width, height, True)\n",
801806
" self.schedule = mesa.time.RandomActivation(self)\n",

0 commit comments

Comments
 (0)