Skip to content

Commit

Permalink
Replace schedule.steps, .agents, .agents_by_type and .get_agent_count
Browse files Browse the repository at this point in the history
  • Loading branch information
EwoutH committed Sep 21, 2024
1 parent c521c5d commit 0b09f5c
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion examples/pd_grid/analysis.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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}\")"
]
},
{
Expand Down
8 changes: 4 additions & 4 deletions examples/schelling/analysis.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
]
},
{
Expand Down Expand Up @@ -328,15 +328,15 @@
" 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",
" segregated = False\n",
" break\n",
" if segregated:\n",
" segregated_agents += 1\n",
" return segregated_agents / model.schedule.get_agent_count()"
" return segregated_agents / len(model.agents)"
]
},
{
Expand Down
8 changes: 4 additions & 4 deletions examples/schelling_experimental/analysis.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
]
},
{
Expand Down Expand Up @@ -328,15 +328,15 @@
" 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",
" segregated = False\n",
" break\n",
" if segregated:\n",
" segregated_agents += 1\n",
" return segregated_agents / model.schedule.get_agent_count()"
" return segregated_agents / len(model.agents)"
]
},
{
Expand Down
4 changes: 2 additions & 2 deletions examples/sugarscape_g1mt/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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).
Expand Down

0 comments on commit 0b09f5c

Please sign in to comment.