1
0
mirror of https://github.com/gsi-upm/soil synced 2025-07-01 19:12:20 +00:00
soil/soil/agents/CounterModel.py
J. Fernando Sánchez e1be3a730e WIP soil
* Pandas integration
* Improved environment
* Logging and data dumps
* Tests
* Added Finite State Machine models
* Rewritten ipython notebook and documentation
2017-07-03 18:17:52 +02:00

32 lines
1016 B
Python

from . import NetworkAgent
class CounterModel(NetworkAgent):
"""
Dummy behaviour. It counts the number of nodes in the network and neighbors
in each step and adds it to its state.
"""
def step(self):
# Outside effects
total = len(self.get_all_agents())
neighbors = len(self.get_neighboring_agents())
self.state['times'] = self.state.get('times', 0) + 1
self.state['neighbors'] = neighbors
self.state['total'] = total
class AggregatedCounter(NetworkAgent):
"""
Dummy behaviour. It counts the number of nodes in the network and neighbors
in each step and adds it to its state.
"""
def step(self):
# Outside effects
total = len(self.get_all_agents())
neighbors = len(self.get_neighboring_agents())
self.state['times'] = self.state.get('times', 0) + 1
self.state['neighbors'] = self.state.get('neighbors', 0) + neighbors
self.state['total'] = self.state.get('total', 0) + total