1
0
mirror of https://github.com/gsi-upm/soil synced 2024-11-22 03:02:28 +00:00

version 0.20.4

This commit is contained in:
J. Fernando Sánchez 2022-05-18 15:20:58 +02:00
parent 2116fe6f38
commit 5559d37e57
4 changed files with 25 additions and 3 deletions

View File

@ -3,6 +3,10 @@ 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.4]
### Added
* Agents can now be given any kwargs, which will be used to set their state
* Environments have a default logger `self.logger` and a log method, just like agents
## [0.20.3]
### Fixed
* Default state values are now deepcopied again.

View File

@ -1 +1 @@
0.20.3
0.20.4

View File

@ -35,7 +35,9 @@ class BaseAgent(Agent):
unique_id,
model,
name=None,
interval=None):
interval=None,
**kwargs
):
# Check for REQUIRED arguments
# Initialize agent parameters
if isinstance(unique_id, Agent):
@ -52,7 +54,8 @@ class BaseAgent(Agent):
if hasattr(self, 'level'):
self.logger.setLevel(self.level)
for (k, v) in kwargs.items():
setattr(self, k, v)
# TODO: refactor to clean up mesa compatibility
@property

View File

@ -5,6 +5,7 @@ import math
import random
import yaml
import tempfile
import logging
import pandas as pd
from time import time as current_time
from copy import deepcopy
@ -101,6 +102,8 @@ class Environment(Model):
environment_agents = agents._convert_agent_types(distro)
self.environment_agents = environment_agents
self.logger = utils.logger.getChild(self.name)
@property
def now(self):
if self.schedule:
@ -198,6 +201,18 @@ class Environment(Model):
start = start or self.now
return self.G.add_edge(agent1, agent2, **attrs)
def log(self, message, *args, level=logging.INFO, **kwargs):
if not self.logger.isEnabledFor(level):
return
message = message + " ".join(str(i) for i in args)
message = " @{:>3}: {}".format(self.now, message)
for k, v in kwargs:
message += " {k}={v} ".format(k, v)
extra = {}
extra['now'] = self.now
extra['unique_id'] = self.name
return self.logger.log(level, message, extra=extra)
def step(self):
super().step()
self.schedule.step()