1
0
mirror of https://github.com/gsi-upm/soil synced 2024-12-23 00:28:11 +00:00
soil/benchmarks/noop/mesa_simulation.py
2023-05-19 16:19:50 +02:00

38 lines
1.1 KiB
Python

from mesa import batch_run, DataCollector, Agent, Model
from mesa.time import RandomActivation
from soil import Simulation
from _config import *
class NoopAgent(Agent):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.num_calls = 0
def step(self):
self.num_calls += 1
class NoopModel(Model):
def __init__(self, num_agents, *args, **kwargs):
super().__init__()
self.schedule = RandomActivation(self)
for i in range(num_agents):
self.schedule.add(NoopAgent(self.next_id(), self))
self.datacollector = DataCollector(model_reporters={"num_agents": lambda m: m.schedule.get_agent_count(),
"time": lambda m: m.schedule.time},
agent_reporters={"num_calls": "num_calls"})
self.datacollector.collect(self)
def step(self):
self.schedule.step()
self.datacollector.collect(self)
def run():
run_sim(model=NoopModel)
if __name__ == "__main__":
run()