environment_directory = "environments/"
identifier = "test_all_methods"
log_directory = "log/"

"""
Explanation: Running the Solow Model
First, the model needs to be initialized.
End of explanation
"""


if not os.path.exists('log'):
    os.makedirs('log')

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")

"""
Explanation: Then, after a log folder is created, if it doesn't exist, the logger will be initialized. The log files will contain information about how the simulation went.
End of explanation
"""


#tree = ET.parse('environments/test_all_methods.xml')
tree = ET.parse('environments/solow_parameters.xml')
root = tree.getroot()

# all item attributes
print('All parameters: ')
for elem in root:
    print(elem.attrib)

"""
Explanation: Before initializing the model, let's inspect the parameters that are used to initialize it.
End of explanation
"""


environment = Environment(environment_directory, identifier)

"""
Explanation: First, the environment will be initialized. It contains the model parameters and variables. The environment also contains a list of agents. In the Solow model, the environment contains one bank, one firm, and one household. Finally, it also contains initialized transactions for these agents
End of explanation
"""


runner = Runner(environment)

"""
Explanation: Next up, the runner object is created. As the name suggests, the runner object handles the running of the model. But that is not all, it also initializes the updater.
End of explanation
"""


for i in range(int(environment.num_simulations)):
    logging.info('  STARTED with run %s',  str(i))
    environment.initialize(environment_directory,  identifier)
    runner.initialize(environment)
    
    runner.do_run(environment)
    logging.info('  DONE')

"""
Explanation: Now you can actually run the model. Since the agent-based model is simulated using Monte Carlo methods. This means that the model will be run multiple times (num_simulations). For every simulation run, the environment and runner will be (re-)initialized. Then, the runner will run the Solow model. During the run, the runner will write data about capital to a csv file specified within the Measurement class and print out all the transactions happening and the books of firm and household at the end of each sweep.
End of explanation
"""


