mirror of
https://github.com/gsi-upm/soil
synced 2024-11-22 11:12:29 +00:00
Fix incompatibility and bug in get_agents
This commit is contained in:
parent
97835b3d10
commit
6690b6ee5f
@ -3,6 +3,12 @@ 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.14.4]
|
||||||
|
### Fixed
|
||||||
|
* Bug in `agent.get_agents()` when `state_id` is passed as a string. The tests have been modified accordingly.
|
||||||
|
## [0.14.3]
|
||||||
|
### Fixed
|
||||||
|
* Incompatibility with py3.3-3.6 due to ModuleNotFoundError and TypeError in DryRunner
|
||||||
## [0.14.2]
|
## [0.14.2]
|
||||||
### Fixed
|
### Fixed
|
||||||
* Output path for exporters is now soil_output
|
* Output path for exporters is now soil_output
|
||||||
|
@ -59,7 +59,7 @@ class Patron(FSM):
|
|||||||
2) Look for a bar where the agent and other agents in the same group can get in.
|
2) Look for a bar where the agent and other agents in the same group can get in.
|
||||||
3) While in the bar, patrons only drink, until they get drunk and taken home.
|
3) While in the bar, patrons only drink, until they get drunk and taken home.
|
||||||
'''
|
'''
|
||||||
level = logging.INFO
|
level = logging.DEBUG
|
||||||
|
|
||||||
defaults = {
|
defaults = {
|
||||||
'pub': None,
|
'pub': None,
|
||||||
@ -113,7 +113,8 @@ class Patron(FSM):
|
|||||||
@state
|
@state
|
||||||
def at_home(self):
|
def at_home(self):
|
||||||
'''The end'''
|
'''The end'''
|
||||||
self.debug('Life sucks. I\'m home!')
|
others = self.get_agents(state_id=Patron.at_home.id, limit_neighbors=True)
|
||||||
|
self.debug('I\'m home. Just like {} of my friends'.format(len(others)))
|
||||||
|
|
||||||
def drink(self):
|
def drink(self):
|
||||||
self['pints'] += 1
|
self['pints'] += 1
|
||||||
|
@ -1 +1 @@
|
|||||||
0.14.2
|
0.14.4
|
||||||
|
@ -476,10 +476,7 @@ class Geo(NetworkAgent):
|
|||||||
|
|
||||||
def select(agents, state_id=None, agent_type=None, ignore=None, iterator=False, **kwargs):
|
def select(agents, state_id=None, agent_type=None, ignore=None, iterator=False, **kwargs):
|
||||||
|
|
||||||
if state_id is not None:
|
if state_id is not None and not isinstance(state_id, (tuple, list)):
|
||||||
try:
|
|
||||||
state_id = tuple(state_id)
|
|
||||||
except TypeError:
|
|
||||||
state_id = tuple([state_id])
|
state_id = tuple([state_id])
|
||||||
if agent_type is not None:
|
if agent_type is not None:
|
||||||
try:
|
try:
|
||||||
|
@ -186,7 +186,7 @@ def deserializer(type_, known_modules=[]):
|
|||||||
module = importlib.import_module(modname)
|
module = importlib.import_module(modname)
|
||||||
cls = getattr(module, tname)
|
cls = getattr(module, tname)
|
||||||
return getattr(cls, 'deserialize', cls)
|
return getattr(cls, 'deserialize', cls)
|
||||||
except (ModuleNotFoundError, AttributeError) as ex:
|
except (ImportError, AttributeError) as ex:
|
||||||
errors.append((modname, tname, ex))
|
errors.append((modname, tname, ex))
|
||||||
raise Exception('Could not find type {}. Tried: {}'.format(type_, errors))
|
raise Exception('Could not find type {}. Tried: {}'.format(type_, errors))
|
||||||
|
|
||||||
|
@ -46,5 +46,5 @@ def safe_open(path, mode='r', backup=True, **kwargs):
|
|||||||
def open_or_reuse(f, *args, **kwargs):
|
def open_or_reuse(f, *args, **kwargs):
|
||||||
try:
|
try:
|
||||||
return safe_open(f, *args, **kwargs)
|
return safe_open(f, *args, **kwargs)
|
||||||
except TypeError:
|
except (AttributeError, TypeError):
|
||||||
return f
|
return f
|
||||||
|
@ -16,10 +16,15 @@ ROOT = os.path.abspath(os.path.dirname(__file__))
|
|||||||
EXAMPLES = join(ROOT, '..', 'examples')
|
EXAMPLES = join(ROOT, '..', 'examples')
|
||||||
|
|
||||||
|
|
||||||
class CustomAgent(agents.BaseAgent):
|
class CustomAgent(agents.FSM):
|
||||||
def step(self):
|
@agents.default_state
|
||||||
self.state['neighbors'] = self.count_agents(state_id=0,
|
@agents.state
|
||||||
|
def normal(self):
|
||||||
|
self.state['neighbors'] = self.count_agents(state_id='normal',
|
||||||
limit_neighbors=True)
|
limit_neighbors=True)
|
||||||
|
@agents.state
|
||||||
|
def unreachable(self):
|
||||||
|
return
|
||||||
|
|
||||||
class TestMain(TestCase):
|
class TestMain(TestCase):
|
||||||
|
|
||||||
@ -134,8 +139,7 @@ class TestMain(TestCase):
|
|||||||
},
|
},
|
||||||
'network_agents': [{
|
'network_agents': [{
|
||||||
'agent_type': CustomAgent,
|
'agent_type': CustomAgent,
|
||||||
'weight': 1,
|
'weight': 1
|
||||||
'state': {'id': 0}
|
|
||||||
|
|
||||||
}],
|
}],
|
||||||
'max_time': 10,
|
'max_time': 10,
|
||||||
@ -145,6 +149,9 @@ class TestMain(TestCase):
|
|||||||
s = simulation.from_config(config)
|
s = simulation.from_config(config)
|
||||||
env = s.run_simulation(dry_run=True)[0]
|
env = s.run_simulation(dry_run=True)[0]
|
||||||
assert env.get_agent(0).state['neighbors'] == 1
|
assert env.get_agent(0).state['neighbors'] == 1
|
||||||
|
assert env.get_agent(0).state['neighbors'] == 1
|
||||||
|
assert env.get_agent(1).count_agents(state_id='normal') == 2
|
||||||
|
assert env.get_agent(1).count_agents(state_id='normal', limit_neighbors=True) == 1
|
||||||
|
|
||||||
def test_torvalds_example(self):
|
def test_torvalds_example(self):
|
||||||
"""A complete example from a documentation should work."""
|
"""A complete example from a documentation should work."""
|
||||||
|
Loading…
Reference in New Issue
Block a user