Commit c02e6ea2 authored by J. Fernando Sánchez's avatar J. Fernando Sánchez
Browse files

Fix die bug

parent 38f8a8d1
Pipeline #3492 passed with stage
in 1 minute and 16 seconds
......@@ -3,6 +3,9 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](, and this project adheres to [Semantic Versioning](
## [0.20.1]
### Fixed
* Agents would run another step after dying.
## [0.20.0]
### Added
* Integration with MESA
......@@ -4,20 +4,34 @@ Example of a fully programmatic simulation, without definition files.
from soil import Simulation, agents
from soil.time import Delta
from networkx import Graph
from random import expovariate
import logging
class MyAgent(agents.FSM):
An agent that first does a ping
defaults = {'pong_counts': 2}
def neutral(self):'I am running')
def ping(self):'Ping')
return self.pong, Delta(expovariate(1/16))
def pong(self):'Pong')
self.pong_counts -= 1
if self.pong_counts < 1:
return self.die()
return None, Delta(expovariate(1/16))
s = Simulation(name='Programmatic',
network_agents=[{'agent_type': MyAgent, 'id': 0}],
topology={'nodes': [{'id': 0}], 'links': []},
\ No newline at end of file
\ No newline at end of file
......@@ -20,6 +20,10 @@ def as_node(agent):
IGNORED_FIELDS = ('model', 'logger')
class DeadAgent(Exception):
class BaseAgent(Agent):
A special Agent that keeps track of its state history.
......@@ -129,13 +133,14 @@ class BaseAgent(Agent):
return None
def die(self, remove=False):'agent {self.unique_id} is dying')
self.alive = False
if remove:
def step(self):
if not self.alive:
return time.When('inf')
raise DeadAgent(self.unique_id)
return super().step() or time.Delta(self.interval)
def log(self, message, *args, level=logging.INFO, **kwargs):
......@@ -300,7 +305,10 @@ class FSM(NetworkAgent, metaclass=MetaFSM):
def step(self):
self.debug(f'Agent {self.unique_id} @ state {self.state_id}')
interval = super().step()
interval = super().step()
except DeadAgent:
return time.When('inf')
if 'id' not in self.state:
# if 'id' in self.state:
# self.set_state(self.state['id'])
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment