From dfb6d13649ad70d7dc44af43ba7efb76fad51fb4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=2E=20Fernando=20S=C3=A1nchez?= Date: Wed, 18 May 2022 16:13:53 +0200 Subject: [PATCH] version 0.20.5 --- CHANGELOG.md | 3 +++ soil/VERSION | 2 +- soil/agents/__init__.py | 5 +++++ soil/environment.py | 4 ---- 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9023162..ad22c8c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,9 @@ 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). +## [0.20.5] +### Changed +* Defaults are now set in the agent __init__, not in the environment. This decouples both classes a bit more, and it is more intuitive ## [0.20.4] ### Added * Agents can now be given any kwargs, which will be used to set their state diff --git a/soil/VERSION b/soil/VERSION index a4e543e..58d8f8d 100644 --- a/soil/VERSION +++ b/soil/VERSION @@ -1 +1 @@ -0.20.4 \ No newline at end of file +0.20.5 \ No newline at end of file diff --git a/soil/agents/__init__.py b/soil/agents/__init__.py index 0602d32..c9bcd23 100644 --- a/soil/agents/__init__.py +++ b/soil/agents/__init__.py @@ -54,9 +54,14 @@ class BaseAgent(Agent): if hasattr(self, 'level'): self.logger.setLevel(self.level) + for (k, v) in self.defaults.items(): + if not hasattr(self, k) or getattr(self, k) is None: + setattr(self, k, deepcopy(v)) + for (k, v) in kwargs.items(): setattr(self, k, v) + # TODO: refactor to clean up mesa compatibility @property def id(self): diff --git a/soil/environment.py b/soil/environment.py index 25d8338..45453fc 100644 --- a/soil/environment.py +++ b/soil/environment.py @@ -175,10 +175,6 @@ class Environment(Model): unique_id=agent_id ) - for (k, v) in getattr(a, 'defaults', {}).items(): - if not hasattr(a, k) or getattr(a, k) is None: - setattr(a, k, deepcopy(v)) - for (k, v) in state.items(): setattr(a, k, v)