From 0b09f5c54331b903788cb77af560de3cd6bbb802 Mon Sep 17 00:00:00 2001 From: Ewout ter Hoeven Date: Sat, 21 Sep 2024 14:10:08 +0200 Subject: [PATCH] Replace schedule.steps, .agents, .agents_by_type and .get_agent_count See https://mesa.readthedocs.io/en/latest/migration_guide.html --- examples/pd_grid/analysis.ipynb | 2 +- examples/schelling/analysis.ipynb | 8 ++++---- examples/schelling_experimental/analysis.ipynb | 8 ++++---- examples/sugarscape_g1mt/tests.py | 4 ++-- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/examples/pd_grid/analysis.ipynb b/examples/pd_grid/analysis.ipynb index 1fe69759..e3f52170 100644 --- a/examples/pd_grid/analysis.ipynb +++ b/examples/pd_grid/analysis.ipynb @@ -72,7 +72,7 @@ " grid[y][x] = 0\n", " ax.pcolormesh(grid, cmap=bwr, vmin=0, vmax=1)\n", " ax.axis(\"off\")\n", - " ax.set_title(f\"Steps: {model.schedule.steps}\")" + " ax.set_title(f\"Steps: {model.steps}\")" ] }, { diff --git a/examples/schelling/analysis.ipynb b/examples/schelling/analysis.ipynb index 50f382c6..71d925c1 100644 --- a/examples/schelling/analysis.ipynb +++ b/examples/schelling/analysis.ipynb @@ -65,9 +65,9 @@ } ], "source": [ - "while model.running and model.schedule.steps < 100:\n", + "while model.running and model.steps < 100:\n", " model.step()\n", - "print(model.schedule.steps) # Show how many steps have actually run" + "print(model.steps) # Show how many steps have actually run" ] }, { @@ -328,7 +328,7 @@ " Find the % of agents that only have neighbors of their same type.\n", " \"\"\"\n", " segregated_agents = 0\n", - " for agent in model.schedule.agents:\n", + " for agent in model.agents:\n", " segregated = True\n", " for neighbor in model.grid.iter_neighbors(agent.pos, True):\n", " if neighbor.type != agent.type:\n", @@ -336,7 +336,7 @@ " break\n", " if segregated:\n", " segregated_agents += 1\n", - " return segregated_agents / model.schedule.get_agent_count()" + " return segregated_agents / len(model.agents)" ] }, { diff --git a/examples/schelling_experimental/analysis.ipynb b/examples/schelling_experimental/analysis.ipynb index 50f382c6..71d925c1 100644 --- a/examples/schelling_experimental/analysis.ipynb +++ b/examples/schelling_experimental/analysis.ipynb @@ -65,9 +65,9 @@ } ], "source": [ - "while model.running and model.schedule.steps < 100:\n", + "while model.running and model.steps < 100:\n", " model.step()\n", - "print(model.schedule.steps) # Show how many steps have actually run" + "print(model.steps) # Show how many steps have actually run" ] }, { @@ -328,7 +328,7 @@ " Find the % of agents that only have neighbors of their same type.\n", " \"\"\"\n", " segregated_agents = 0\n", - " for agent in model.schedule.agents:\n", + " for agent in model.agents:\n", " segregated = True\n", " for neighbor in model.grid.iter_neighbors(agent.pos, True):\n", " if neighbor.type != agent.type:\n", @@ -336,7 +336,7 @@ " break\n", " if segregated:\n", " segregated_agents += 1\n", - " return segregated_agents / model.schedule.get_agent_count()" + " return segregated_agents / len(model.agents)" ] }, { diff --git a/examples/sugarscape_g1mt/tests.py b/examples/sugarscape_g1mt/tests.py index bcfcf739..274afa6b 100644 --- a/examples/sugarscape_g1mt/tests.py +++ b/examples/sugarscape_g1mt/tests.py @@ -23,7 +23,7 @@ def test_decreasing_price_variance(): model.datacollector._new_model_reporter( "price_variance", lambda m: np.var( - flatten([a.prices for a in m.schedule.agents_by_type[Trader].values()]) + flatten([a.prices for a in m.agents_by_type[Trader].values()]) ), ) model.run_model(step_count=50) @@ -40,7 +40,7 @@ def calculate_carrying_capacities(enable_trade): for vision_max in visions: model = SugarscapeG1mt(vision_max=vision_max, enable_trade=enable_trade) model.run_model(step_count=50) - carrying_capacities.append(len(model.schedule.agents_by_type[Trader])) + carrying_capacities.append(len(model.agents_by_type[Trader])) return carrying_capacities # Carrying capacity should increase over mean vision (figure IV-6).