Skip to content
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

intro_tutorial: Don't initialize agents with an unique_id #2315

Merged
merged 3 commits into from
Sep 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/tutorials/MoneyModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ def __init__(self, N, width, height):
self.schedule = mesa.time.RandomActivation(self)

# Create agents
for i in range(self.num_agents):
a = MoneyAgent(i, self)
for _ in range(self.num_agents):
a = MoneyAgent(self)
self.schedule.add(a)
# Add the agent to a random grid cell
x = self.random.randrange(self.grid.width)
Expand Down
62 changes: 31 additions & 31 deletions docs/tutorials/intro_tutorial.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,9 @@
"class MoneyAgent(mesa.Agent):\n",
" \"\"\"An agent with fixed initial wealth.\"\"\"\n",
"\n",
" def __init__(self, unique_id, model):\n",
" def __init__(self, model):\n",
" # Pass the parameters to the parent class.\n",
" super().__init__(unique_id, model)\n",
" super().__init__(model)\n",
"\n",
" # Create the agent's variable and set the initial values.\n",
" self.wealth = 1"
Expand Down Expand Up @@ -232,8 +232,8 @@
" super().__init__()\n",
" self.num_agents = N\n",
" # Create agents\n",
" for i in range(self.num_agents):\n",
" a = MoneyAgent(i, self)"
" for _ in range(self.num_agents):\n",
" a = MoneyAgent(self)"
]
},
{
Expand Down Expand Up @@ -261,9 +261,9 @@
"class MoneyAgent(mesa.Agent):\n",
" \"\"\"An agent with fixed initial wealth.\"\"\"\n",
"\n",
" def __init__(self, unique_id, model):\n",
" def __init__(self, model):\n",
" # Pass the parameters to the parent class.\n",
" super().__init__(unique_id, model)\n",
" super().__init__(model)\n",
"\n",
" # Create the agent's attribute and set the initial values.\n",
" self.wealth = 1\n",
Expand All @@ -284,8 +284,8 @@
" self.schedule = mesa.time.RandomActivation(self)\n",
"\n",
" # Create agents\n",
" for i in range(self.num_agents):\n",
" a = MoneyAgent(i, self)\n",
" for _ in range(self.num_agents):\n",
" a = MoneyAgent(self)\n",
" # Add the agent to the scheduler\n",
" self.schedule.add(a)\n",
"\n",
Expand Down Expand Up @@ -357,9 +357,9 @@
"class MoneyAgent(mesa.Agent):\n",
" \"\"\"An agent with fixed initial wealth.\"\"\"\n",
"\n",
" def __init__(self, unique_id, model):\n",
" def __init__(self, model):\n",
" # Pass the parameters to the parent class.\n",
" super().__init__(unique_id, model)\n",
" super().__init__(model)\n",
"\n",
" # Create the agent's variable and set the initial values.\n",
" self.wealth = 1\n",
Expand Down Expand Up @@ -424,9 +424,9 @@
"class MoneyAgent(mesa.Agent):\n",
" \"\"\"An agent with fixed initial wealth.\"\"\"\n",
"\n",
" def __init__(self, unique_id, model):\n",
" def __init__(self, model):\n",
" # Pass the parameters to the parent class.\n",
" super().__init__(unique_id, model)\n",
" super().__init__(model)\n",
"\n",
" # Create the agent's variable and set the initial values.\n",
" self.wealth = 1\n",
Expand Down Expand Up @@ -464,7 +464,7 @@
"outputs": [],
"source": [
"model = MoneyModel(10)\n",
"for i in range(10):\n",
"for _ in range(10):\n",
" model.step()"
]
},
Expand Down Expand Up @@ -511,10 +511,10 @@
"source": [
"all_wealth = []\n",
"# This runs the model 100 times, each model executing 10 steps.\n",
"for j in range(100):\n",
"for _ in range(100):\n",
" # Run the model\n",
" model = MoneyModel(10)\n",
" for i in range(10):\n",
" for _ in range(10):\n",
" model.step()\n",
"\n",
" # Store the results\n",
Expand Down Expand Up @@ -573,8 +573,8 @@
" self.schedule = mesa.time.RandomActivation(self)\n",
"\n",
" # Create agents\n",
" for i in range(self.num_agents):\n",
" a = MoneyAgent(i, self)\n",
" for _ in range(self.num_agents):\n",
" a = MoneyAgent(self)\n",
" self.schedule.add(a)\n",
"\n",
" # Add the agent to a random grid cell\n",
Expand Down Expand Up @@ -653,8 +653,8 @@
"class MoneyAgent(mesa.Agent):\n",
" \"\"\"An agent with fixed initial wealth.\"\"\"\n",
"\n",
" def __init__(self, unique_id, model):\n",
" super().__init__(unique_id, model)\n",
" def __init__(self, model):\n",
" super().__init__(model)\n",
" self.wealth = 1\n",
"\n",
" def move(self):\n",
Expand Down Expand Up @@ -686,8 +686,8 @@
" self.grid = mesa.space.MultiGrid(width, height, True)\n",
" self.schedule = mesa.time.RandomActivation(self)\n",
" # Create agents\n",
" for i in range(self.num_agents):\n",
" a = MoneyAgent(i, self)\n",
" for _ in range(self.num_agents):\n",
" a = MoneyAgent(self)\n",
" self.schedule.add(a)\n",
" # Add the agent to a random grid cell\n",
" x = self.random.randrange(self.grid.width)\n",
Expand All @@ -712,7 +712,7 @@
"outputs": [],
"source": [
"model = MoneyModel(100, 10, 10)\n",
"for i in range(20):\n",
"for _ in range(20):\n",
" model.step()"
]
},
Expand Down Expand Up @@ -771,8 +771,8 @@
"class MoneyAgent(mesa.Agent):\n",
" \"\"\"An agent with fixed initial wealth.\"\"\"\n",
"\n",
" def __init__(self, unique_id, model):\n",
" super().__init__(unique_id, model)\n",
" def __init__(self, model):\n",
" super().__init__(model)\n",
" self.wealth = 1\n",
"\n",
" def move(self):\n",
Expand Down Expand Up @@ -810,8 +810,8 @@
" self.schedule = mesa.time.RandomActivation(self)\n",
"\n",
" # Create agents\n",
" for i in range(self.num_agents):\n",
" a = MoneyAgent(i, self)\n",
" for _ in range(self.num_agents):\n",
" a = MoneyAgent(self)\n",
" self.schedule.add(a)\n",
" # Add the agent to a random grid cell\n",
" x = self.random.randrange(self.grid.width)\n",
Expand Down Expand Up @@ -845,7 +845,7 @@
"outputs": [],
"source": [
"model = MoneyModel(100, 10, 10)\n",
"for i in range(100):\n",
"for _ in range(100):\n",
" model.step()"
]
},
Expand Down Expand Up @@ -1052,8 +1052,8 @@
" self.running = True\n",
"\n",
" # Create agents\n",
" for i in range(self.num_agents):\n",
" a = MoneyAgent(i, self)\n",
" for _ in range(self.num_agents):\n",
" a = MoneyAgent(self)\n",
" self.schedule.add(a)\n",
" # Add the agent to a random grid cell\n",
" x = self.random.randrange(self.grid.width)\n",
Expand All @@ -1073,8 +1073,8 @@
"class MoneyAgent(mesa.Agent):\n",
" \"\"\"An agent with fixed initial wealth.\"\"\"\n",
"\n",
" def __init__(self, unique_id, model):\n",
" super().__init__(unique_id, model)\n",
" def __init__(self, model):\n",
" super().__init__(model)\n",
" self.wealth = 1\n",
" self.steps_not_given = 0\n",
"\n",
Expand Down
Loading