2017-10-18 18:28:42 +00:00
|
|
|
from . import BaseAgent
|
2017-06-20 15:45:43 +00:00
|
|
|
|
|
|
|
|
2017-10-18 18:28:42 +00:00
|
|
|
class CounterModel(BaseAgent):
|
2017-06-20 15:45:43 +00:00
|
|
|
"""
|
|
|
|
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()))
|
2018-05-04 08:01:49 +00:00
|
|
|
self['times'] = self.get('times', 0) + 1
|
|
|
|
self['neighbors'] = neighbors
|
|
|
|
self['total'] = total
|
2017-06-20 15:45:43 +00:00
|
|
|
|
|
|
|
|
2017-10-18 18:28:42 +00:00
|
|
|
class AggregatedCounter(BaseAgent):
|
2017-06-20 15:45:43 +00:00
|
|
|
"""
|
|
|
|
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()))
|
2018-05-04 08:01:49 +00:00
|
|
|
self['times'] = self.get('times', 0) + 1
|
|
|
|
self['neighbors'] = self.get('neighbors', 0) + neighbors
|
|
|
|
self['total'] = total = self.get('total', 0) + total
|
2017-10-18 18:28:42 +00:00
|
|
|
self.debug('Running for step: {}. Total: {}'.format(self.now, total))
|