-
Notifications
You must be signed in to change notification settings - Fork 0
/
ruby_rhino.py
87 lines (70 loc) · 3.03 KB
/
ruby_rhino.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/usr/bin/env python
# [SublimeLinter pep8-max-line-length:300]
# -*- coding: utf-8 -*-
"""
ruby_rhino is a multi-agent simulator for financial network analysis
Copyright (C) 2016 Paweł Fiedor (pawel@fiedor.eu)
Based on black_rhino available on Github
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, version 3 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>
"""
# -------------------------------------------------------------------------
#
# MAIN
#
# -------------------------------------------------------------------------
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 = sys.argv
if len(args) != 5:
print "Usage: ./black_rhino environment_directory/ environment_identifier log_directory/ measurement_directory/"
sys.exit()
#
# INITIALIZATION
#
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.info('START logging for run: %s', environment_directory + identifier + ".xml")
environment = Environment(environment_directory, identifier)
# environment.initialize(environment_directory, identifier)
runner = Runner()
measurement = Measurement()
#
# UPDATE STEP
#
for i in range(environment.static_parameters["numSimulations"]):
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()
logging.info(' DONE')
#
# MEASUREMENT AND LOGGING
#
measurement.write_histograms(measurement_directory, environment)
logging.info('FINISHED logging for run: %s \n', environment_directory + identifier + ".xml")