Skip to content

Commit 7a54654

Browse files
Migrate from 'MultiGrid' to 'OrthogonalMooreGrid'
2 parents d676002 + 0eaa400 commit 7a54654

File tree

4 files changed

+9
-6
lines changed

4 files changed

+9
-6
lines changed

examples/traffic_flow/app.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,4 @@ def car_portrayal(agent):
5656
model_params=model_params,
5757
name="Traffic Flow",
5858
)
59-
page # noqa
59+
page # noqa

examples/traffic_flow/run.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from traffic_flow.model import TraficFlow
22

3+
34
def render_grid(model):
45
lines = []
56
for y in reversed(range(model.grid.height)):
@@ -10,11 +11,12 @@ def render_grid(model):
1011
lines.append("".join(row))
1112
return "\n".join(lines)
1213

14+
1315
if __name__ == "__main__":
1416
model = TraficFlow(width=20, height=5, n_cars=20, seed=1)
1517

1618
for t in range(10):
1719
print(f"tick {t}")
1820
print(render_grid(model))
1921
print()
20-
model.step()
22+
model.step()

examples/traffic_flow/traffic_flow/agent.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
from mesa import Agent
22

3+
34
class CarAgent(Agent):
45
def __init__(self, model):
56
super().__init__(model)
6-
7+
78
def move(self):
89
x,y = self.pos
910
new_pos = ((x + 1) % self.model.grid.dimensions[0], y)
@@ -17,4 +18,3 @@ def move(self):
1718

1819
def step(self):
1920
self.move()
20-

examples/traffic_flow/traffic_flow/model.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
from mesa.discrete_space import OrthogonalMooreGrid
33

44
from .agent import CarAgent
5-
5+
6+
67
class TraficFlow(Model):
78
def __init__(self, width=20, height=5, n_cars=10, seed=None):
89
super().__init__(seed=seed)
@@ -21,4 +22,4 @@ def __init__(self, width=20, height=5, n_cars=10, seed=None):
2122
car.pos = (x, y)
2223

2324
def step(self):
24-
self.agents.shuffle_do("step")
25+
self.agents.shuffle_do("step")

0 commit comments

Comments
 (0)