Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactoring: made code consistent with published papers (in particula…
…r: agent.py).
- Loading branch information
Showing
9 changed files
with
381 additions
and
329 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# coding=utf-8 | ||
|
||
import scenarios | ||
import cli | ||
from configuration import Configuration | ||
|
||
|
||
if __name__ == '__main__': | ||
cfg = Configuration( | ||
seed=0, | ||
msg_delay_min=None, | ||
msg_delay_max=None, | ||
agent_delay_min=None, | ||
agent_delay_max=None, | ||
log_to_file=False, | ||
) | ||
sc = scenarios.SC(cfg.rnd, cfg.seed, opt_h=5) | ||
# sc = scenarios.SVSM(cfg.rnd, cfg.seed) | ||
# sc = scenarios.CHP(cfg.rnd, cfg.seed, opt_m=10, opt_n=400, opt_q=16, opt_q_constant=20.0) | ||
# | ||
# sc = scenarios.SC(cfg.rnd, cfg.seed, opt_h=5, | ||
# agent_type='AgentStigspaceMMMSSP') | ||
# sc = scenarios.SVSM(cfg.rnd, cfg.seed, agent_type='AgentStigspaceSVSM') | ||
# sc = scenarios.CHP(cfg.rnd, cfg.seed, opt_m=30, opt_n=200, | ||
# agent_type='AgentStigspaceMMMSSP') | ||
cfg.scenario = sc | ||
|
||
cli.run(cfg) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
# coding=utf-8 | ||
|
||
import numpy as np | ||
|
||
|
||
""" | ||
Data models, directly corresponding to the formal model from the 2016 IJBIC | ||
paper (in press). | ||
""" | ||
|
||
|
||
class Schedule_Selection(): | ||
|
||
def __init__(self, aid, schedule, v_lambda): | ||
"""Initializes a schedule selection. | ||
Arguments: | ||
aid -- agent identifier (str) | ||
schedule -- the selected schedule (ndarray) | ||
v_lamdba -- the selection counter (int) | ||
""" | ||
self.aid = aid | ||
self.schedule = schedule | ||
self.v_lambda = v_lambda | ||
|
||
def __eq__(self, other): | ||
if isinstance(other, self.__class__): | ||
return (other.v_lambda == self.v_lambda and | ||
np.all(other.schedule == self.schedule)) | ||
else: | ||
return False | ||
|
||
def __ne__(self, other): | ||
return not self.__eq__(other) | ||
|
||
|
||
class Solution_Candidate(): | ||
|
||
def __init__(self, aid, configuration, rating): | ||
"""Initializes a solution candidate. | ||
Arguments: | ||
aid -- agent identifier (str) | ||
configuration -- system configuration (dict(str: schedule_selection)) | ||
rating -- rating of this solution candidate (float) | ||
""" | ||
self.aid = aid | ||
self.configuration = dict(configuration) | ||
self.rating = rating | ||
|
||
def copy(self): | ||
return Solution_Candidate(self.aid, self.configuration, self.rating) | ||
|
||
def keys(self): | ||
return self.configuration.keys() | ||
|
||
def get(aid): | ||
return self.configuration[aid] | ||
|
||
|
||
class Working_Memory(): | ||
|
||
def __init__(self, objective, configuration, solution_candidate): | ||
"""Initializes an agent's working memory. | ||
Arguments: | ||
objective -- one-argument objective function (obj --> float) | ||
configuration -- system configuration (dict(str: schedule_selection)) | ||
solution_candidate -- initial solution candidate (Solution_Candidate) | ||
""" | ||
self.objective = objective | ||
self.configuration = dict(configuration) | ||
self.solution_candidate = solution_candidate.copy() | ||
|
||
def copy(self): | ||
return Working_Memory(self.objective, self.configuration, | ||
self.solution_candidate.copy()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.