|
210 | 210 | "\n", |
211 | 211 | "**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", |
212 | 212 | "\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", |
214 | 214 | "\n", |
215 | 215 | "The `MoneyModel` class is created with the following code:" |
216 | 216 | ] |
|
225 | 225 | " \"\"\"A model with some number of agents.\"\"\"\n", |
226 | 226 | "\n", |
227 | 227 | " def __init__(self, N):\n", |
| 228 | + " super().__init__()\n", |
228 | 229 | " self.num_agents = N\n", |
229 | 230 | " # Create agents\n", |
230 | 231 | " for i in range(self.num_agents):\n", |
|
273 | 274 | " \"\"\"A model with some number of agents.\"\"\"\n", |
274 | 275 | "\n", |
275 | 276 | " def __init__(self, N):\n", |
| 277 | + " super().__init__()\n", |
276 | 278 | " self.num_agents = N\n", |
277 | 279 | " # Create scheduler and assign it to the model\n", |
278 | 280 | " self.schedule = mesa.time.RandomActivation(self)\n", |
|
561 | 563 | " \"\"\"A model with some number of agents.\"\"\"\n", |
562 | 564 | "\n", |
563 | 565 | " def __init__(self, N, width, height):\n", |
| 566 | + " super().__init__()\n", |
564 | 567 | " self.num_agents = N\n", |
565 | 568 | " self.grid = mesa.space.MultiGrid(width, height, True)\n", |
566 | 569 | " self.schedule = mesa.time.RandomActivation(self)\n", |
|
674 | 677 | " \"\"\"A model with some number of agents.\"\"\"\n", |
675 | 678 | "\n", |
676 | 679 | " def __init__(self, N, width, height):\n", |
| 680 | + " super().__init__()\n", |
677 | 681 | " self.num_agents = N\n", |
678 | 682 | " self.grid = mesa.space.MultiGrid(width, height, True)\n", |
679 | 683 | " self.schedule = mesa.time.RandomActivation(self)\n", |
|
796 | 800 | " \"\"\"A model with some number of agents.\"\"\"\n", |
797 | 801 | "\n", |
798 | 802 | " def __init__(self, N, width, height):\n", |
| 803 | + " super().__init__()\n", |
799 | 804 | " self.num_agents = N\n", |
800 | 805 | " self.grid = mesa.space.MultiGrid(width, height, True)\n", |
801 | 806 | " self.schedule = mesa.time.RandomActivation(self)\n", |
|
0 commit comments