From c850d5f9df9bee4751aad47e8c7012d8f260910a Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 27 Dec 2024 17:12:42 +0000 Subject: [PATCH] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- examples/city_walking_behaviour/app.py | 66 ++++++++++++++++--- .../city_walking_behaviour/model.py | 10 ++- 2 files changed, 66 insertions(+), 10 deletions(-) diff --git a/examples/city_walking_behaviour/app.py b/examples/city_walking_behaviour/app.py index 104c2ffd..9673b40c 100644 --- a/examples/city_walking_behaviour/app.py +++ b/examples/city_walking_behaviour/app.py @@ -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 ( @@ -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 ) @@ -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() diff --git a/examples/city_walking_behaviour/city_walking_behaviour/model.py b/examples/city_walking_behaviour/city_walking_behaviour/model.py index 2fa694ac..1aa0642c 100644 --- a/examples/city_walking_behaviour/city_walking_behaviour/model.py +++ b/examples/city_walking_behaviour/city_walking_behaviour/model.py @@ -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 @@ -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