コード例 #1
0
ファイル: runner.py プロジェクト: ldyst/BlackRhino
    def do_run(self, environment):
        # loop over all time steps and do the updating

        # For each update step

        measurement = Measurement(environment, self)
        measurement.open_file()

        for i in range(self.num_sweeps):

            self.current_step = i

            self.updater.do_update(environment)
            measurement.write_to_file()

        print("***\nThis run had %s sweeps and %s simulations") % (
            self.num_sweeps, environment.static_parameters['num_simulations'])
        print(
            "Check the output file that was written as csv in the measurements folder\n***"
        )

        # environment.print_parameters()

        # agent = Agent()
        # print(self.get_identifier())
        # print(self.get_num_sweeps())
        # print(environment.agents[0])
        # print(environment.agents[1])

        # parameters={'deposit_rate':-0.02}
        # agent.append_parameters(parameters)
        # print(agent.get_parameters())

        measurement.close_file()
コード例 #2
0
ファイル: runner.py プロジェクト: cogeorg/black_rhino
    def do_run(self, environment):
        # loop over all time steps and do the updating

        # For each update step

        measurement = Measurement(environment, self)
        measurement.open_file()

        for i in range(self.num_sweeps):

            self.current_step = i

            self.updater.do_update(environment)
            measurement.write_to_file()

        print("***\nThis run had %s sweeps and %s simulations" ) % (self.num_sweeps, environment.static_parameters['num_simulations'])
        print("Check the output file that was written as csv in the measurements folder\n***")

        # environment.print_parameters()

        # agent = Agent()
        # print(self.get_identifier())
        # print(self.get_num_sweeps())
        # print(environment.agents[0])
        # print(environment.agents[1])

        # parameters={'deposit_rate':-0.02}
        # agent.append_parameters(parameters)
        # print(agent.get_parameters())

        measurement.close_file()
コード例 #3
0
    def measurement__close_file(self, args):
        import os
        from src.bank import Bank
        from src.household import Household
        from src.firm import Firm
        from src.environment import Environment
        from src.transaction import Transaction
        from src.market import Market
        from src.runner import Runner
        from src.measurement import Measurement

        text = "This test checks measurement.close_file \n"
        self.print_info(text)
        #
        # INITIALIZATION
        #
        environment_directory = str(args[0])
        identifier = str(args[1])
        log_directory = str(args[2])

        # 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 test measurement__close_file in run: %s',
                     environment_directory + identifier + ".xml")

        # Construct household filename
        environment = Environment(environment_directory,  identifier)

        # Construct a runner
        runner = Runner(environment)

        # generate a bank
        bank = Bank()
        bank.identifier = "test_bank"
        environment.banks.append(bank)

        # generate a firm
        firm = Firm()
        firm.identifier = "test_firm"
        environment.firms.append(firm)

        # generate a household
        household = Household()
        household.identifier = "test_household"
        environment.households.append(household)

        #
        # TESTING
        #
        measurement = Measurement(environment, runner)
        measurement.open_file()
        print("Is the file closed?")
        print(measurement.file.closed)
        measurement.close_file()
        print("Is the file closed?")
        print(measurement.file.closed)
コード例 #4
0
ファイル: runner.py プロジェクト: cogeorg/black_rhino
    def do_run(self, environment):
        # loop over all time steps and do the updating

        # For each update step

        measurement = Measurement(environment, self)
        measurement.open_file()

        for i in range(self.num_sweeps):

                self.current_step = i

                self.updater.do_update(environment, i)
                measurement.write_to_file()

        print("***\nThis run had %s sweeps and %s simulations" ) % (self.num_sweeps, environment.static_parameters['num_simulations'])
        print("Check the output file that was written as csv in the measurements folder\n***")

        measurement.close_file()
コード例 #5
0
ファイル: runner.py プロジェクト: IanMadlenya/BlackRhino
    def do_run(self, environment):
        # loop over all time steps and do the updating
        # For each update step

        measurement = Measurement(environment, self)
        measurement.open_file()

        for i in range(self.num_sweeps):

            self.current_step = i

            self.updater.do_update(environment, i)
            measurement.write_all_to_file()

        print("***\nThis run had %s sweeps and %s simulations") % (
            self.num_sweeps, environment.static_parameters['num_simulations'])
        print(
            "Check the output file that was written as csv in the measurements folder\n***"
        )

        measurement.close_file()
コード例 #6
0
ファイル: runner.py プロジェクト: cogeorg/black_rhino
    def do_run(self, environment):
        # loop over all time steps and do the updating

        # For each update step

        measurement = Measurement(environment, self)
        measurement.open_file()

        for i in range(self.num_sweeps):

                self.current_step = i

                self.updater.do_update(environment, i)
                measurement.write_to_file()

        print("***\nThis run had %s sweeps and %s simulations" ) % (self.num_sweeps, environment.static_parameters['num_simulations'])
        print("Check the output file that was written as csv in the measurements folder\n***")

        agent = Agent()
        for each_agent in environment.agents:
            print(agent.identifier)

        # agent = Agent()
        # print(agent.private_belief)
        # print(agent.calc_social_belief)
        # print(agent.investment_decision(environment))

        # for keys, values in agent.parameters.items():
        #     print keys, '-->', values

        # agent = Agent()
        # print(self.get_identifier())
        # print(self.get_num_sweeps())
        # print(environment.agents[0])
        # parameters={'deposit_rate':-0.02}
        # agent.append_parameters(parameters)
        # print(agent.get_parameters())

        measurement.close_file()
コード例 #7
0
 def do_run(self, environment):
     # loop over all time steps and do the updating
     # We initialise the measurement class for writing outputs to csv
     # measurement = Measurement("Measurement", environment, self, {1: ["Step", "static", "self.runner.current_step"],
     # 2: ["Deposits", "dynamic", "self.environment.households[0].get_account", ["deposits"]]}, "TestMeasurement.csv")
     measurement = Measurement(environment, self)
     # And open the output file
     measurement.open_file()
     # For each update step
     for i in range(self.num_sweeps):
         print(environment.measurement_config)
         # the update step
         # append current step, this is mostly for measurements
         self.current_step = i
         # do the actual update
         self.updater.do_update(environment, i)
         # write the state of the system
         measurement.write_to_file()
         # HELPER, to be removed in production
         print(environment.households[0])
         print(environment.firms[0])
     # Close the output file at the end of the simulation
     measurement.close_file()
コード例 #8
0
ファイル: runner.py プロジェクト: zouhx11/BlackRhino
 def do_run(self, environment):
     # loop over all time steps and do the updating
     # We initialise the measurement class for writing outputs to csv
     # measurement = Measurement("Measurement", environment, self, {1: ["Step", "static", "self.runner.current_step"],
     # 2: ["Deposits", "dynamic", "self.environment.households[0].get_account", ["deposits"]]}, "TestMeasurement.csv")
     measurement = Measurement(environment, self)
     # And open the output file
     measurement.open_file()
     # We start the shock class as well
     shock_class = Shock()
     # For each update step
     for i in range(self.num_sweeps):
         # Do the shock:
         # First we check if the shock occurs at the current sweep
         # Then we run the shock procedure at the start of the update
         for shock in environment.shocks:
             if int(shock[0]) <= i+1 and int(shock[1]) >= i+1:
                 shock_class.do_shock(environment, i, shock[2], "start")
         # the update step
         # append current step, this is mostly for measurements
         self.current_step = i
         # do the actual update
         self.updater.do_update(environment, i)
         # write the state of the system
         measurement.write_to_file()
         # Do the shock (revert the shock if necessary):
         # First we check if the shock occurs at the current sweep
         # Then we run the shock procedure at the end of the update
         for shock in environment.shocks:
             if int(shock[0]) <= i+1 and int(shock[1]) >= i+1:
                 shock_class.do_shock(environment, i, shock[2], "end")
         # HELPER, to be removed in production
         # for firm in environment.households:
         #    print(firm)
         # print(environment.households[0])
         # print(environment.firms[0])
         # capital = 0.0
         # for tranx in environment.firms[0].accounts:
         #     if tranx.type_ == "capital" and tranx.from_ == environment.firms[0]:
         #         capital = capital + tranx.amount
         #     if tranx.type_ == "capital" and tranx.to == environment.firms[0]:
         #         capital = capital - tranx.amount
         # print(environment.firms[0].get_account("deposits")+capital-environment.firms[0].get_account("loans"))
         # capital = 0.0
         # for tranx in environment.firms[1].accounts:
         #     if tranx.type_ == "capital" and tranx.from_ == environment.firms[1]:
         #         capital = capital + tranx.amount
         #     if tranx.type_ == "capital" and tranx.to == environment.firms[1]:
         #         capital = capital - tranx.amount
         # print(environment.firms[1].get_account("deposits")+capital-environment.firms[1].get_account("loans"))
         # capital = 0.0
         # for tranx in environment.firms[2].accounts:
         #     if tranx.type_ == "capital" and tranx.from_ == environment.firms[2]:
         #         capital = capital + tranx.amount
         #     if tranx.type_ == "capital" and tranx.to == environment.firms[2]:
         #         capital = capital - tranx.amount
         # print(environment.firms[2].get_account("deposits")+capital-environment.firms[2].get_account("loans"))
         print(environment.banks[0])
         # print(environment.firms[0])
     # Close the output file at the end of the simulation
     measurement.close_file()