Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Dec 27, 2024
1 parent 0142b18 commit c850d5f
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 10 deletions.
66 changes: 58 additions & 8 deletions examples/city_walking_behaviour/app.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
from city_walking_behaviour.agents import Human, GroceryStore, SocialPlace, NonFoodShop, Other
from city_walking_behaviour.agents import (
Human,
GroceryStore,
SocialPlace,
NonFoodShop,
Other,
)
from city_walking_behaviour.model import WalkingModel
from mesa.experimental.devs import ABMSimulator
from mesa.visualization import (
Expand Down Expand Up @@ -208,20 +214,62 @@ def post_process_lines_leisure(ax):

def post_process_buildings_legend(ax):
import matplotlib.lines as mlines

# Create legend entries for each building/agent
grocery_store = mlines.Line2D([], [], color="tab:green", marker="s", linestyle="None", markersize=10, label="Grocery Store")
social_place = mlines.Line2D([], [], color="tab:purple", marker="s", linestyle="None", markersize=10, label="Social Place")
non_food_shop = mlines.Line2D([], [], color="tab:olive", marker="s", linestyle="None", markersize=10, label="Non-Food Shop")
other_building = mlines.Line2D([], [], color="tab:brown", marker="s", linestyle="None", markersize=10, label="Other")
human = mlines.Line2D([], [], color="tab:red", marker="v", linestyle="None", markersize=10, label="Human")
grocery_store = mlines.Line2D(
[],
[],
color="tab:green",
marker="s",
linestyle="None",
markersize=10,
label="Grocery Store",
)
social_place = mlines.Line2D(
[],
[],
color="tab:purple",
marker="s",
linestyle="None",
markersize=10,
label="Social Place",
)
non_food_shop = mlines.Line2D(
[],
[],
color="tab:olive",
marker="s",
linestyle="None",
markersize=10,
label="Non-Food Shop",
)
other_building = mlines.Line2D(
[],
[],
color="tab:brown",
marker="s",
linestyle="None",
markersize=10,
label="Other",
)
human = mlines.Line2D(
[],
[],
color="tab:red",
marker="v",
linestyle="None",
markersize=10,
label="Human",
)

ax.legend(
handles=[grocery_store, social_place, non_food_shop, other_building, human],
loc="center",
bbox_to_anchor=(0.5, 0.5)
bbox_to_anchor=(0.5, 0.5),
)
ax.axis("off")


space_component = make_space_component(
agent_portrayal, draw_grid=True, post_process=post_process_space
)
Expand Down Expand Up @@ -270,7 +318,9 @@ def post_process_buildings_legend(ax):
post_process=post_process_lines_leisure,
)

plot_component_legend = make_plot_component({}, post_process=post_process_buildings_legend)
plot_component_legend = make_plot_component(
{}, post_process=post_process_buildings_legend
)

# Initialize and run the model
simulator = ABMSimulator()
Expand Down
10 changes: 8 additions & 2 deletions examples/city_walking_behaviour/city_walking_behaviour/model.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import math
from mesa import Model
from city_walking_behaviour.agents import Human, GroceryStore, SocialPlace, NonFoodShop, Other
from city_walking_behaviour.agents import (
Human,
GroceryStore,
SocialPlace,
NonFoodShop,
Other,
)
from mesa.experimental.cell_space import OrthogonalVonNeumannGrid
from mesa.experimental.cell_space.property_layer import PropertyLayer
from mesa.experimental.devs import ABMSimulator
Expand Down Expand Up @@ -521,7 +527,7 @@ def calculate_safety(i, j):
base_safety = min_distance * 0.8 # Maximum safety of 0.8

# Add some local variation
local_variation = self.random.random() * 0.2
local_variation = self.random.random() * 0.2

# Add some urban-like patterns
if min_distance < 0.3: # Near centers
Expand Down

0 comments on commit c850d5f

Please sign in to comment.