diff --git a/CHANGELOG.md b/CHANGELOG.md index b2599b3..fe425d0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [UNRELEASED] +## [0.20.7] +### Changed +* Creating a `time.When` from another `time.When` does not nest them anymore (it returns the argument) +### Fixed +* Bug with time.NEVER/time.INFINITY ## [0.20.6] ### Fixed * Agents now return `time.INFINITY` when dead, instead of 'inf' diff --git a/soil/VERSION b/soil/VERSION index 58d8f8d..f8d54d4 100644 --- a/soil/VERSION +++ b/soil/VERSION @@ -1 +1 @@ -0.20.5 \ No newline at end of file +0.20.7 \ No newline at end of file diff --git a/soil/agents/__init__.py b/soil/agents/__init__.py index c4e1023..7555207 100644 --- a/soil/agents/__init__.py +++ b/soil/agents/__init__.py @@ -145,7 +145,7 @@ class BaseAgent(Agent): self.alive = False if remove: self.remove_node(self.id) - return time.INFINITY + return time.NEVER def step(self): if not self.alive: diff --git a/soil/time.py b/soil/time.py index 29ae31f..90ec513 100644 --- a/soil/time.py +++ b/soil/time.py @@ -10,6 +10,8 @@ INFINITY = float('inf') class When: def __init__(self, time): + if isinstance(time, When): + return time self._time = time def abs(self, time): @@ -18,7 +20,7 @@ class When: NEVER = When(INFINITY) -class Delta: +class Delta(When): def __init__(self, delta): self._delta = delta @@ -60,7 +62,8 @@ class TimedActivation(BaseScheduler): (when, agent_id) = heappop(self._queue) logger.debug(f'Stepping agent {agent_id}') - when = (self._agents[agent_id].step() or Delta(1)).abs(self.time) + returned = self._agents[agent_id].step() + when = (returned or Delta(1)).abs(self.time) if when < self.time: raise Exception("Cannot schedule an agent for a time in the past ({} < {})".format(when, self.time)) diff --git a/tests/test_agents.py b/tests/test_agents.py index 76e0998..e95c11c 100644 --- a/tests/test_agents.py +++ b/tests/test_agents.py @@ -16,9 +16,7 @@ class TestMain(TestCase): d.step() with pytest.raises(agents.DeadAgent): d.step() + def test_die_returns_infinity(self): d = Dead(unique_id=0, model=environment.Environment()) assert d.step().abs(0) == stime.INFINITY - - -