2022-03-06 22:11:30 +01:00
|
|
|
import random
|
|
|
|
|
|
|
|
from mesa import Agent, Model
|
|
|
|
from mesa.time import RandomActivation
|
|
|
|
from mesa.space import MultiGrid
|
|
|
|
from mesa.datacollection import DataCollector
|
|
|
|
|
2022-03-06 22:16:21 +01:00
|
|
|
from ForkliftAgent import ForkliftAgent
|
2022-03-06 22:11:30 +01:00
|
|
|
|
|
|
|
|
2022-03-06 22:16:21 +01:00
|
|
|
class ForkliftModel(Model):
|
2022-03-06 22:11:30 +01:00
|
|
|
|
2022-03-06 22:16:21 +01:00
|
|
|
def __init__(self, width, height):
|
|
|
|
self.num_agents = 1
|
2022-03-06 22:11:30 +01:00
|
|
|
self.running = True
|
|
|
|
self.grid = MultiGrid(height, width, True)
|
|
|
|
self.schedule = RandomActivation(self)
|
2022-03-06 22:16:21 +01:00
|
|
|
# self.datacollector = DataCollector(
|
|
|
|
# model_reporters={"Gini": compute_gini},
|
|
|
|
# agent_reporters={"Wealth": lambda a: a.wealth}
|
|
|
|
# )
|
|
|
|
|
2022-03-06 22:11:30 +01:00
|
|
|
# Create agents
|
|
|
|
for i in range(self.num_agents):
|
2022-03-06 22:16:21 +01:00
|
|
|
a = ForkliftAgent(1, self)
|
2022-03-06 22:11:30 +01:00
|
|
|
self.schedule.add(a)
|
|
|
|
# Add the agent to a random grid cell
|
|
|
|
x = random.randrange(self.grid.width)
|
|
|
|
y = random.randrange(self.grid.height)
|
|
|
|
self.grid.place_agent(a, (x, y))
|
|
|
|
|
|
|
|
def step(self):
|
2022-03-06 22:16:21 +01:00
|
|
|
# self.datacollector.collect(self)
|
2022-03-06 22:11:30 +01:00
|
|
|
self.schedule.step()
|