Skip to content

Commit 130d3d5

Browse files
committed
fix ruff errors
1 parent df6ac48 commit 130d3d5

File tree

12 files changed

+38
-28
lines changed

12 files changed

+38
-28
lines changed

gis/agents_and_networks/references/GMU-Social.nlogo

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ vertices-own [
5454
entrance? ;;if it is an entrance to a building
5555
test ;;used to delete in test
5656

57-
;;the follwoing variables are used and renewed in each path-selection
57+
;;the following variables are used and renewed in each path-selection
5858
dist ;;distance from original point to here
5959
done ;;1 if has calculated the shortest path through this point, 0 otherwise
6060
lastnode ;;last node to this point in shortest path
@@ -108,7 +108,7 @@ to setup
108108

109109
;;ask patches with [ centroid? = true][sprout 1 [set size 2 set color red]] ;;use this line to verify
110110

111-
;;create turtles representing the nodes. create links to conect them.
111+
;;create turtles representing the nodes. create links to connect them.
112112
foreach gis:feature-list-of gmu-walkway [ road-feature ->
113113
foreach gis:vertex-lists-of road-feature [ v -> ; for the road feature, get the list of vertices
114114
let previous-node-pt nobody
@@ -813,7 +813,7 @@ PLOT
813813
456
814814
739
815815
672
816-
Firends at Home
816+
Friends at Home
817817
No. of friends at home
818818
Count of people
819819
0.0
@@ -852,15 +852,15 @@ You may want to turn off some layers for a clear display.
852852

853853
## THINGS TO TRY
854854

855-
Change the switches for different dispalys. Try different number of coimmuters. Try the verification.
855+
Change the switches for different displays. Try different number of coimmuters. Try the verification.
856856

857857
## EXTENDING THE MODEL
858858

859859
What if the commuters move with a speed (some distance per tick) instead of one node per tick?
860860

861861
## NETLOGO FEATURES
862862

863-
For faster compuation, this model simplifies the original data by reducing the number of nodes. To do that, the walkway data is loaded to the 20 x 20 grid in Netlogo, which is small, and therefore, many nodes fall on the same patch. In each patch, we only want to keep one node, and duplicate nodes are removed, while their neighbors are connected to the one node left.
863+
For faster computation, this model simplifies the original data by reducing the number of nodes. To do that, the walkway data is loaded to the 20 x 20 grid in Netlogo, which is small, and therefore, many nodes fall on the same patch. In each patch, we only want to keep one node, and duplicate nodes are removed, while their neighbors are connected to the one node left.
864864

865865
Also, links are created in this model to represent raods. This is so far the best way I can find to deal with road related problems in Netlogo. However, because the way I create links is to link nodes one by one (see code for more details), so some roads are likely to be left behind. But again there is no better way I can find. Therefore, I also used a loop in setup to delete nodes that are not connected to the whole network.
866866

rl/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ To test the code, simply execute `example.py`:
5050
python example.py
5151
```
5252

53-
*Note: Pre-trained models might not work in some cases because of differnce in versions of libraries used to train and test.*
53+
*Note: Pre-trained models might not work in some cases because of difference in versions of libraries used to train and test.*
5454

5555
To learn about individual implementations, please refer to the README files of specific environments.
5656

rl/boltzmann_money/server.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99

1010
# Modify the MoneyModel class to take actions from the RL model
1111
class MoneyModelRL(BoltzmannWealthModelRL):
12-
def __init__(self, N, width, height):
13-
super().__init__(N, width, height)
12+
def __init__(self, n, width, height):
13+
super().__init__(n, width, height)
1414
model_path = os.path.join(
1515
os.path.dirname(__file__), "..", "model", "boltzmann_money.zip"
1616
)

rl/epstein_civil_violence/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ This project demonstrates the use of the RLlib library to implement Multi-Agent
88
- **Library Utilized**: The project leverages the RLlib library to concurrently train two independent PPO (Proximal Policy Optimization) agents.
99
- **Agents**:
1010
- **Police**: Aims to control violence (Reduce active agent)
11-
- **Citizen**: Aims to show resistence (be active) without getting arrested
11+
- **Citizen**: Aims to show resistance (be active) without getting arrested
1212

1313
**Input and Observation Space**:
1414
- **Observation Grid**: Each agent's policy receives a 4 radius grid centered on itself as input.

rl/epstein_civil_violence/agent.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from mesa.examples.advanced.epstein_civil_violence.agents import Citizen, Cop
2-
from utility import move
2+
3+
from .utility import move
34

45

56
class CitizenRL(Citizen):
@@ -11,7 +12,7 @@ def step(self):
1112
self.jail_sentence -= 1
1213
else:
1314
# RL Logic
14-
# Update condition and postion based on action
15+
# Update condition and position based on action
1516
self.condition = "Active" if action_tuple[0] == 1 else "Quiescent"
1617
# Update neighbors for updated empty neighbors
1718
self.update_neighbors()

rl/epstein_civil_violence/model.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
from agent import CitizenRL, CopRL
55
from mesa.examples.advanced.epstein_civil_violence.model import EpsteinCivilViolence
66
from ray.rllib.env import MultiAgentEnv
7-
from utility import create_intial_agents, grid_to_observation
7+
8+
from .utility import create_initial_agents, grid_to_observation
89

910

1011
class EpsteinCivilViolenceRL(EpsteinCivilViolence, MultiAgentEnv):
@@ -143,8 +144,8 @@ def reset(self, *, seed=None, options=None):
143144
"""
144145
super().reset()
145146
self.grid = mesa.space.SingleGrid(self.width, self.height, torus=True)
146-
create_intial_agents(self, CitizenRL, CopRL)
147-
grid_to_observation(self, CitizenRL)
147+
create_initial_agents(self)
148+
grid_to_observation(self)
148149
# Initialize action dictionary with no action
149150
self.action_dict = {a.unique_id: (0, 0) for a in self.agents}
150151
# Update neighbors for observation space

rl/epstein_civil_violence/utility.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1-
def create_intial_agents(self, CitizenRL, CopRL):
1+
from .agent import CitizenRL, CopRL
2+
3+
4+
def create_initial_agents(self):
25
# Create agents
36
unique_id = 0
47
if self.cop_density + self.citizen_density > 1:
58
raise ValueError("CopRL density + citizen density must be less than 1")
69
cops = []
710
citizens = []
8-
for contents, (x, y) in self.grid.coord_iter():
11+
for _, (x, y) in self.grid.coord_iter():
912
if self.random.random() < self.cop_density:
1013
unique_id_str = f"cop_{unique_id}"
1114
cop = CopRL(unique_id_str, self, (x, y), vision=self.cop_vision)
@@ -35,7 +38,7 @@ def create_intial_agents(self, CitizenRL, CopRL):
3538
self.add(citizen)
3639

3740

38-
def grid_to_observation(self, CitizenRL):
41+
def grid_to_observation(self):
3942
# Convert neighborhood to observation grid
4043
self.obs_grid = []
4144
for i in self.grid._grid:

rl/train.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def train_model(
3636
algo_config = get_config(config)
3737
algo = algo_config.build()
3838

39-
for i in range(num_iterations):
39+
for _ in range(num_iterations):
4040
result = algo.train()
4141
print(pretty_print(result))
4242

rl/wolf_sheep/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ This project demonstrates the use of the RLlib library to implement Multi-Agent
77
**RLlib and Multi-Agent Learning**:
88
- **Library Utilized**: The project leverages the RLlib library to concurrently train two independent PPO (Proximal Policy Optimization) agents.
99
- **Agents**:
10-
- **Wolf**: Predatory agent survives by eating sheeps
10+
- **Wolf**: Predatory agent survives by eating sheep
1111
- **Sheep**: Prey agent survives by eating grass
1212
- **Grass**: Grass is eaten by sheep and regrows with time
1313

rl/wolf_sheep/agents.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from mesa.examples.advanced.wolf_sheep.agents import GrassPatch, Sheep, Wolf
2-
from utility import move
2+
3+
from .utility import move
34

45

56
class SheepRL(Sheep):

0 commit comments

Comments
 (0)