Skip to content

Commit

Permalink
min_to_master
Browse files Browse the repository at this point in the history
  • Loading branch information
pafiedor committed May 11, 2016
1 parent a6d78c4 commit 80be727
Show file tree
Hide file tree
Showing 38 changed files with 2,273 additions and 3,948 deletions.
1 change: 0 additions & 1 deletion .gitignore
Expand Up @@ -51,4 +51,3 @@
.Trashes
ehthumbs.db
Thumbs.db
__init__.py
2 changes: 1 addition & 1 deletion .gitmodules
@@ -1,3 +1,3 @@
[submodule "abm_template"]
path = abm_template
url = git://github.com/cogeorg/abm_template/
url = git://github.com/cogeorg/abm_template/
26 changes: 24 additions & 2 deletions README.md
@@ -1,5 +1,27 @@
This is the new repository for black_rhino and takes over from http://sourceforge.net/projects/oxblackrhino/?source=directory as of 2015-11-07.

Minimal rhino branch aims at a complete overhaul in terms of code for an agent-based model, it is implemented from the very basics to provide greater clarity and quality.

INSTALL
git clone https://github.com/cogeorg/black_rhino
once you have the repo, you need to clone abm_template as well
git submodule update --init --recursive

FOLDER STRUCTURE

+---.git -git structure files
+---abm_template -abstract base classes (submodule from https://github.com/cogeorg/abm_template)
+---agents -config files for agents
| +---banks
| +---firms
| \---households
+---environments -config files for environment
+---log -log files
+---networkx -networkx package for network capabilities
+---src -source code files
+---tests -redundant structure for tests
\---tools -specific tools

INSTRUCTIONS -- to be updated with the new code

Introduction

Expand Down Expand Up @@ -81,4 +103,4 @@ black_rhino has a separate program called ./br-make_tests.py that is used to exe

References

Georg, Co-Pierre, „The Effect of the Interbank Network Structure on Contagion and Common Shocks“, Deutsche Bundesbank Working Paper Series 2, 12-2011, (2011)
Georg, Co-Pierre, „The Effect of the Interbank Network Structure on Contagion and Common Shocks“, Deutsche Bundesbank Working Paper Series 2, 12-2011, (2011)
2 changes: 2 additions & 0 deletions agents/banks/bank_for_tests.xml
@@ -0,0 +1,2 @@
<bank identifier='bank_test_config_id'>
</bank>
3 changes: 3 additions & 0 deletions agents/central_bank/central_bank_for_tests.xml
@@ -0,0 +1,3 @@
<central_bank identifier='central_bank_test_config_id'>
<parameter type='static' name='interest_rate_cb_loans' value='0.00'></parameter>
</central_bank>
3 changes: 3 additions & 0 deletions agents/firms/firm_for_tests.xml
@@ -0,0 +1,3 @@
<firm identifier='firm_test_config_id'>
<parameter name='productivity' value='1.25'></parameter>
</firm>
4 changes: 4 additions & 0 deletions agents/households/household_for_tests.xml
@@ -0,0 +1,4 @@
<household identifier='household_test_config_id'>
<parameter name='labour' value='24.00'></parameter>
<parameter name='propensity_to_save' value='0.45'></parameter>
</household>
31 changes: 10 additions & 21 deletions black_rhino.py
Expand Up @@ -3,6 +3,8 @@
# -*- coding: utf-8 -*-

"""
This is a minimal example.
black_rhino is a multi-agent simulator for financial network analysis
Copyright (C) 2012 Co-Pierre Georg (co-pierre.georg@keble.ox.ac.uk)
Expand All @@ -28,22 +30,18 @@
#
# -------------------------------------------------------------------------
if __name__ == '__main__':
import pdb # python debugger, for debugging purposes only

import sys
# sys.path.append('src/')
import logging
import networkx as nx

from src.environment import Environment
from src.runner import Runner
from src.measurement import Measurement

args = ['./black_rhino.py', "src/environments/", "test3", "src/log/", "src/measurements/"]
args = ['./black_rhino.py', "tests/environments/", "test_all_methods", "tests/log/"]
# args = sys.argv

if len(args) != 5:
print "Usage: ./black_rhino environment_directory/ environment_identifier log_directory/ measurement_directory/"
if len(args) != 4:
print "Usage: ./black_rhino environment_directory/ environment_identifier log_directory/"
sys.exit()


Expand All @@ -53,36 +51,27 @@
environment_directory = str(args[1])
identifier = str(args[2])
log_directory = str(args[3])
measurement_directory = str(args[4])

# Configure logging parameters so we get output while the program runs
logging.basicConfig(format='%(asctime)s %(message)s', datefmt='%m/%d/%Y %H:%M:%S', filename=log_directory + identifier + ".log", level=logging.INFO)
logging.basicConfig(format='%(asctime)s %(message)s', datefmt='%m/%d/%Y %H:%M:%S',
filename=log_directory + identifier + ".log", level=logging.INFO)
logging.info('START logging for run: %s', environment_directory + identifier + ".xml")

environment = Environment(environment_directory, identifier)
# environment.initialize(environment_directory, identifier)
runner = Runner()
measurement = Measurement()
runner = Runner(environment)

#
# UPDATE STEP
#
for i in range(environment.static_parameters["numSimulations"]):
for i in range(int(environment.num_simulations)):
logging.info(' STARTED with run %s', str(i))
environment.initialize(environment_directory, identifier)
# check that environment file has been read correctly
# environment.write_environment_file(identifier)
runner.initialize(environment)
measurement.initialize() # clear the previous measurement

# do the run
runner.do_run(measurement, "info")
# do the histograms, i.e. add the current measurement to the histogram
measurement.do_histograms()
runner.do_run(environment)
logging.info(' DONE')

#
# MEASUREMENT AND LOGGING
#
measurement.write_histograms(measurement_directory, environment)
logging.info('FINISHED logging for run: %s \n', environment_directory + identifier + ".xml")

0 comments on commit 80be727

Please sign in to comment.