Skip to content

Commit d4d2b61

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent 7abe79b commit d4d2b61

3 files changed

Lines changed: 208 additions & 132 deletions

File tree

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
"""ML optimization demo - Gaussian Process regression for finding good parameters."""
2+
3+
from .agents import SimpleAgent
24
from .model import (
35
MLDemoModel,
6+
run_full_analysis,
47
run_optimization,
58
run_statistical_validation,
6-
run_full_analysis,
7-
visualize_optimization
9+
visualize_optimization,
810
)
9-
from .agents import SimpleAgent
10-
__all__=[
11+
12+
__all__ = [
1113
"MLDemoModel",
1214
"SimpleAgent",
15+
"run_full_analysis",
1316
"run_optimization",
1417
"run_statistical_validation",
15-
"run_full_analysis",
16-
"visualize_optimization"
17-
]
18+
"visualize_optimization",
19+
]
Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,22 @@
11
"""Agent class for the segregation model."""
2+
23
import mesa
34
import numpy as np
5+
6+
47
class SimpleAgent(mesa.Agent):
58
"""Agent that moves around randomly. Has a type (A or B) which is used to calculate segregation."""
6-
def __init__(self,unique_id,model):
7-
super().__init__(unique_id,model)
8-
self.type=np.random.choice(["A","B"])
9+
10+
def __init__(self, unique_id, model):
11+
super().__init__(unique_id, model)
12+
self.type = np.random.choice(["A", "B"])
13+
914
def step(self):
1015
"""Move to a random neighboring cell."""
11-
dx=self.random.randint(-1,2)
12-
dy=self.random.randint(-1,2)
13-
new_x=self.pos[0]+dx
14-
new_y=self.pos[1]+dy
15-
new_x=max(0,min(self.model.grid.width-1,new_x))
16-
new_y=max(0,min(self.model.grid.height-1,new_y))
17-
self.model.grid.move_agent(self,(new_x,new_y))
16+
dx = self.random.randint(-1, 2)
17+
dy = self.random.randint(-1, 2)
18+
new_x = self.pos[0] + dx
19+
new_y = self.pos[1] + dy
20+
new_x = max(0, min(self.model.grid.width - 1, new_x))
21+
new_y = max(0, min(self.model.grid.height - 1, new_y))
22+
self.model.grid.move_agent(self, (new_x, new_y))

0 commit comments

Comments
 (0)