Skip to content

Commit

Permalink
added pre-commit suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
Sahil-Chhoker committed Dec 27, 2024
1 parent c850d5f commit 058453d
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 36 deletions.
8 changes: 4 additions & 4 deletions examples/city_walking_behaviour/app.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -347,4 +347,4 @@ def post_process_buildings_legend(ax):
name="Walking Model",
simulator=simulator,
)
page
page # noqa
25 changes: 12 additions & 13 deletions examples/city_walking_behaviour/city_walking_behaviour/agents.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
36 changes: 17 additions & 19 deletions examples/city_walking_behaviour/city_walking_behaviour/model.py
Original file line number Diff line number Diff line change
@@ -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",
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 058453d

Please sign in to comment.