Skip to content

Commit 058453d

Browse files
committed
added pre-commit suggestions
1 parent c850d5f commit 058453d

File tree

3 files changed

+33
-36
lines changed

3 files changed

+33
-36
lines changed

examples/city_walking_behaviour/app.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
from city_walking_behaviour.agents import (
2-
Human,
32
GroceryStore,
4-
SocialPlace,
3+
Human,
54
NonFoodShop,
65
Other,
6+
SocialPlace,
77
)
88
from city_walking_behaviour.model import WalkingModel
99
from mesa.experimental.devs import ABMSimulator
1010
from mesa.visualization import (
1111
SolaraViz,
12-
make_space_component,
1312
make_plot_component,
13+
make_space_component,
1414
)
1515

1616
# Define the scenarios
@@ -347,4 +347,4 @@ def post_process_buildings_legend(ax):
347347
name="Walking Model",
348348
simulator=simulator,
349349
)
350-
page
350+
page # noqa

examples/city_walking_behaviour/city_walking_behaviour/agents.py

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
from typing import Optional
2-
from mesa import Model
31
import math
4-
from mesa.agent import AgentSet
5-
from mesa.experimental.cell_space import CellAgent, FixedAgent
6-
from mesa.experimental.cell_space import Cell
72
from enum import Enum
3+
from typing import Optional
4+
85
import numpy as np
6+
from mesa import Model
7+
from mesa.agent import AgentSet
8+
from mesa.experimental.cell_space import Cell, CellAgent, FixedAgent
99

1010
# Constants for probability values
1111
FEMALE_PROBABILITY = 0.5
@@ -209,10 +209,12 @@ def simulate_daily_walks(self, human):
209209
self.model.agents_by_type[SocialPlace]
210210
)
211211
distance = self.calculate_distance(human.cell, social_place.cell)
212-
if distance <= self.get_max_walking_distance(human, ActivityType.SOCIAL):
213-
if self.model.random.random() <= human.walking_attitude:
214-
self.add_distance(distance)
215-
walks.append((ActivityType.SOCIAL, social_place))
212+
if (
213+
distance <= self.get_max_walking_distance(human, ActivityType.SOCIAL)
214+
and self.model.random.random() <= human.walking_attitude
215+
):
216+
self.add_distance(distance)
217+
walks.append((ActivityType.SOCIAL, social_place))
216218

217219
# Leisure walk
218220
leisure_destination = self.decide_leisure_walk(human)
@@ -354,10 +356,7 @@ def get_feedback(self, activity: ActivityType):
354356
density_feedback = 0
355357
if self.previous_walking_density == 0:
356358
# If previous density was zero, treat any current density as a positive change
357-
if self.current_walking_density > 0:
358-
density_feedback = 1
359-
else:
360-
density_feedback = 0
359+
density_feedback = 1 if self.current_walking_density > 0 else 0
361360
else:
362361
density_ratio = self.current_walking_density / self.previous_walking_density
363362
density_feedback = density_ratio - 1 # Centers the feedback around 0

examples/city_walking_behaviour/city_walking_behaviour/model.py

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,22 @@
11
import math
2-
from mesa import Model
2+
33
from city_walking_behaviour.agents import (
4-
Human,
4+
DOG_OWNER_PROBABILITY,
5+
FEMALE_PROBABILITY,
6+
MAX_AGE,
7+
MIN_AGE,
8+
SINGLE_HOUSEHOLD_PROBABILITY,
59
GroceryStore,
6-
SocialPlace,
10+
Human,
711
NonFoodShop,
812
Other,
13+
SocialPlace,
914
)
15+
from mesa import Model
16+
from mesa.datacollection import DataCollector
1017
from mesa.experimental.cell_space import OrthogonalVonNeumannGrid
1118
from mesa.experimental.cell_space.property_layer import PropertyLayer
1219
from mesa.experimental.devs import ABMSimulator
13-
from mesa.datacollection import DataCollector
14-
from .agents import (
15-
FEMALE_PROBABILITY,
16-
DOG_OWNER_PROBABILITY,
17-
SINGLE_HOUSEHOLD_PROBABILITY,
18-
MIN_AGE,
19-
MAX_AGE,
20-
)
2120

2221
SCENARIOS = {
2322
"random_random": "Random Land Use, Random Safety",
@@ -592,14 +591,13 @@ def add_initial_humans(self):
592591
# Place couples
593592
for _ in range(self.no_of_couples):
594593
ses = self.generate_ses()
595-
if cells_with_proximity[ses]:
596-
if len(cells_with_proximity[ses]) >= 2:
597-
cell = self.random.choice(cells_with_proximity[ses])
598-
cells_with_proximity[ses].remove(cell)
599-
# Create the couple
600-
for _ in range(2):
601-
Human(self, self.unique_id, cell, SES=ses)
602-
self.unique_id += 1
594+
if cells_with_proximity[ses] and len(cells_with_proximity[ses]) >= 2:
595+
cell = self.random.choice(cells_with_proximity[ses])
596+
cells_with_proximity[ses].remove(cell)
597+
# Create the couple
598+
for _ in range(2):
599+
Human(self, self.unique_id, cell, SES=ses)
600+
self.unique_id += 1
603601

604602
# Place singles
605603
for _ in range(self.no_of_singles):

0 commit comments

Comments
 (0)