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-07 22:27:34 +01:00
|
|
|
from PatchType import PatchType
|
2022-03-06 22:16:21 +01:00
|
|
|
from ForkliftAgent import ForkliftAgent
|
2022-03-07 22:27:34 +01:00
|
|
|
from PatchAgent import PatchAgent
|
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):
|
2022-03-07 22:27:34 +01:00
|
|
|
# self.num_agents = 5
|
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-07 22:27:34 +01:00
|
|
|
agent = ForkliftAgent(0, self)
|
|
|
|
self.schedule.add(agent)
|
|
|
|
# Add the agent to a random grid cell
|
2022-03-24 20:43:53 +01:00
|
|
|
x = 5
|
|
|
|
y = 5
|
2022-03-07 22:27:34 +01:00
|
|
|
self.grid.place_agent(agent, (x, y))
|
|
|
|
|
|
|
|
agent = PatchAgent(1, self, PatchType.pickUp)
|
|
|
|
self.schedule.add(agent)
|
2022-03-24 20:43:53 +01:00
|
|
|
self.grid.place_agent(agent, (self.grid.width-1, self.grid.height-1))
|
2022-03-07 22:27:34 +01:00
|
|
|
|
|
|
|
agent = PatchAgent(2, self, PatchType.dropOff)
|
|
|
|
self.schedule.add(agent)
|
2022-03-24 20:43:53 +01:00
|
|
|
self.grid.place_agent(agent, (0, self.grid.height-1))
|
2022-03-07 22:27:34 +01:00
|
|
|
|
|
|
|
for i in range(3):
|
|
|
|
a = PatchAgent(i+3, self, PatchType.item)
|
2022-03-06 22:11:30 +01:00
|
|
|
self.schedule.add(a)
|
2022-03-07 22:27:34 +01:00
|
|
|
self.grid.place_agent(a, (i, 0))
|
|
|
|
|
|
|
|
# Create patch agents
|
|
|
|
# for i in range(self.num_agents):
|
|
|
|
# a = PatchAgent(i, self)
|
|
|
|
# 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))
|
|
|
|
|
|
|
|
|
2022-03-06 22:11:30 +01:00
|
|
|
|
|
|
|
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()
|