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:
parent
2116fe6f38
commit
5559d37e57
@ -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).
|
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]
|
## [0.20.3]
|
||||||
### Fixed
|
### Fixed
|
||||||
* Default state values are now deepcopied again.
|
* Default state values are now deepcopied again.
|
||||||
|
@ -1 +1 @@
|
|||||||
0.20.3
|
0.20.4
|
@ -35,7 +35,9 @@ class BaseAgent(Agent):
|
|||||||
unique_id,
|
unique_id,
|
||||||
model,
|
model,
|
||||||
name=None,
|
name=None,
|
||||||
interval=None):
|
interval=None,
|
||||||
|
**kwargs
|
||||||
|
):
|
||||||
# Check for REQUIRED arguments
|
# Check for REQUIRED arguments
|
||||||
# Initialize agent parameters
|
# Initialize agent parameters
|
||||||
if isinstance(unique_id, Agent):
|
if isinstance(unique_id, Agent):
|
||||||
@ -52,7 +54,8 @@ class BaseAgent(Agent):
|
|||||||
|
|
||||||
if hasattr(self, 'level'):
|
if hasattr(self, 'level'):
|
||||||
self.logger.setLevel(self.level)
|
self.logger.setLevel(self.level)
|
||||||
|
for (k, v) in kwargs.items():
|
||||||
|
setattr(self, k, v)
|
||||||
|
|
||||||
# TODO: refactor to clean up mesa compatibility
|
# TODO: refactor to clean up mesa compatibility
|
||||||
@property
|
@property
|
||||||
|
@ -5,6 +5,7 @@ import math
|
|||||||
import random
|
import random
|
||||||
import yaml
|
import yaml
|
||||||
import tempfile
|
import tempfile
|
||||||
|
import logging
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
from time import time as current_time
|
from time import time as current_time
|
||||||
from copy import deepcopy
|
from copy import deepcopy
|
||||||
@ -101,6 +102,8 @@ class Environment(Model):
|
|||||||
environment_agents = agents._convert_agent_types(distro)
|
environment_agents = agents._convert_agent_types(distro)
|
||||||
self.environment_agents = environment_agents
|
self.environment_agents = environment_agents
|
||||||
|
|
||||||
|
self.logger = utils.logger.getChild(self.name)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def now(self):
|
def now(self):
|
||||||
if self.schedule:
|
if self.schedule:
|
||||||
@ -198,6 +201,18 @@ class Environment(Model):
|
|||||||
start = start or self.now
|
start = start or self.now
|
||||||
return self.G.add_edge(agent1, agent2, **attrs)
|
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):
|
def step(self):
|
||||||
super().step()
|
super().step()
|
||||||
self.schedule.step()
|
self.schedule.step()
|
||||||
|
Loading…
Reference in New Issue
Block a user