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

version 0.20.4

parent 2116fe6f
Pipeline #3610 canceled with stage
in 52 seconds
......@@ -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.
......
0.20.3
\ No newline at end of file
0.20.4
\ No newline at end of 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
......
......@@ -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()
......
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