1
0
mirror of https://github.com/gsi-upm/soil synced 2024-09-28 18:41:43 +00:00
soil/soil/agents/CounterModel.py

33 lines
1.0 KiB
Python
Raw Normal View History

from . import BaseAgent
class CounterModel(BaseAgent):
"""
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
2017-10-17 17:48:56 +00:00
total = len(list(self.get_all_agents()))
neighbors = len(list(self.get_neighboring_agents()))
self['times'] = self.get('times', 0) + 1
self['neighbors'] = neighbors
self['total'] = total
class AggregatedCounter(BaseAgent):
"""
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
2017-10-17 17:48:56 +00:00
total = len(list(self.get_all_agents()))
neighbors = len(list(self.get_neighboring_agents()))
self['times'] = self.get('times', 0) + 1
self['neighbors'] = self.get('neighbors', 0) + neighbors
self['total'] = total = self.get('total', 0) + total
self.debug('Running for step: {}. Total: {}'.format(self.now, total))