diff --git a/examples/city_walking_behaviour/app.py b/examples/city_walking_behaviour/app.py index 9673b40c..2037206a 100644 --- a/examples/city_walking_behaviour/app.py +++ b/examples/city_walking_behaviour/app.py @@ -1,16 +1,16 @@ from city_walking_behaviour.agents import ( - Human, GroceryStore, - SocialPlace, + Human, NonFoodShop, Other, + SocialPlace, ) from city_walking_behaviour.model import WalkingModel from mesa.experimental.devs import ABMSimulator from mesa.visualization import ( SolaraViz, - make_space_component, make_plot_component, + make_space_component, ) # Define the scenarios @@ -347,4 +347,4 @@ def post_process_buildings_legend(ax): name="Walking Model", simulator=simulator, ) -page +page # noqa diff --git a/examples/city_walking_behaviour/city_walking_behaviour/agents.py b/examples/city_walking_behaviour/city_walking_behaviour/agents.py index 344a33b6..d9397c8a 100644 --- a/examples/city_walking_behaviour/city_walking_behaviour/agents.py +++ b/examples/city_walking_behaviour/city_walking_behaviour/agents.py @@ -1,11 +1,11 @@ -from typing import Optional -from mesa import Model import math -from mesa.agent import AgentSet -from mesa.experimental.cell_space import CellAgent, FixedAgent -from mesa.experimental.cell_space import Cell from enum import Enum +from typing import Optional + import numpy as np +from mesa import Model +from mesa.agent import AgentSet +from mesa.experimental.cell_space import Cell, CellAgent, FixedAgent # Constants for probability values FEMALE_PROBABILITY = 0.5 @@ -209,10 +209,12 @@ def simulate_daily_walks(self, human): self.model.agents_by_type[SocialPlace] ) distance = self.calculate_distance(human.cell, social_place.cell) - if distance <= self.get_max_walking_distance(human, ActivityType.SOCIAL): - if self.model.random.random() <= human.walking_attitude: - self.add_distance(distance) - walks.append((ActivityType.SOCIAL, social_place)) + if ( + distance <= self.get_max_walking_distance(human, ActivityType.SOCIAL) + and self.model.random.random() <= human.walking_attitude + ): + self.add_distance(distance) + walks.append((ActivityType.SOCIAL, social_place)) # Leisure walk leisure_destination = self.decide_leisure_walk(human) @@ -354,10 +356,7 @@ def get_feedback(self, activity: ActivityType): density_feedback = 0 if self.previous_walking_density == 0: # If previous density was zero, treat any current density as a positive change - if self.current_walking_density > 0: - density_feedback = 1 - else: - density_feedback = 0 + density_feedback = 1 if self.current_walking_density > 0 else 0 else: density_ratio = self.current_walking_density / self.previous_walking_density density_feedback = density_ratio - 1 # Centers the feedback around 0 diff --git a/examples/city_walking_behaviour/city_walking_behaviour/model.py b/examples/city_walking_behaviour/city_walking_behaviour/model.py index 1aa0642c..0cdd3dd6 100644 --- a/examples/city_walking_behaviour/city_walking_behaviour/model.py +++ b/examples/city_walking_behaviour/city_walking_behaviour/model.py @@ -1,23 +1,22 @@ import math -from mesa import Model + from city_walking_behaviour.agents import ( - Human, + DOG_OWNER_PROBABILITY, + FEMALE_PROBABILITY, + MAX_AGE, + MIN_AGE, + SINGLE_HOUSEHOLD_PROBABILITY, GroceryStore, - SocialPlace, + Human, NonFoodShop, Other, + SocialPlace, ) +from mesa import Model +from mesa.datacollection import DataCollector from mesa.experimental.cell_space import OrthogonalVonNeumannGrid from mesa.experimental.cell_space.property_layer import PropertyLayer from mesa.experimental.devs import ABMSimulator -from mesa.datacollection import DataCollector -from .agents import ( - FEMALE_PROBABILITY, - DOG_OWNER_PROBABILITY, - SINGLE_HOUSEHOLD_PROBABILITY, - MIN_AGE, - MAX_AGE, -) SCENARIOS = { "random_random": "Random Land Use, Random Safety", @@ -592,14 +591,13 @@ def add_initial_humans(self): # Place couples for _ in range(self.no_of_couples): ses = self.generate_ses() - if cells_with_proximity[ses]: - if len(cells_with_proximity[ses]) >= 2: - cell = self.random.choice(cells_with_proximity[ses]) - cells_with_proximity[ses].remove(cell) - # Create the couple - for _ in range(2): - Human(self, self.unique_id, cell, SES=ses) - self.unique_id += 1 + if cells_with_proximity[ses] and len(cells_with_proximity[ses]) >= 2: + cell = self.random.choice(cells_with_proximity[ses]) + cells_with_proximity[ses].remove(cell) + # Create the couple + for _ in range(2): + Human(self, self.unique_id, cell, SES=ses) + self.unique_id += 1 # Place singles for _ in range(self.no_of_singles):