-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodel.py
More file actions
29 lines (19 loc) · 729 Bytes
/
Copy pathmodel.py
File metadata and controls
29 lines (19 loc) · 729 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
from mesa import Model
from mesa.space import MultiGrid
from mesa.time import RandomActivation
from agent import RandomWalker
import random
class GridModel(Model):
def __init__(self, width, height, num_agents):
super().__init__()
self.num_agents=num_agents
self.grid=MultiGrid(width, height, torus=True)
self.schedule=RandomActivation(self)
for i in range(num_agents):
agent=RandomWalker(i, self)
self.schedule.add(agent)
x=self.random.randrange(self.grid.width)
y=self.random.randrange(self.grid.height)
self.grid.place_agent(agent,(x, y))
def step(self):
self.schedule.step()