Example #1
0
 def initialize_households_from_files(self,  household_directory):
     from src.household import Household
     # this routine is called more than once, so we have to reset the list of households each time
     self.households = []
     # we list all the files in the specified directory
     listing = os.listdir(household_directory)
     # and check if the number of files is in line with the parameters
     if (len(listing) != self.num_households):
         logging.error("    ERROR: number of configuration files in %s (=%s) does not match num_households (=%s)",
                       household_directory,  str(len(listing)), str(self.num_households))
     # we read the files sequentially
     for infile in listing:
         household = Household()
         household.get_parameters_from_file(household_directory + infile,  self)
         # and read parameters to the firms, only to add them to the environment
         self.households.append(household)
Example #2
0
 def initialize_households_from_files(self,  household_directory):
     from src.household import Household
     # this routine is called more than once, so we have to reset the list of households each time
     self.households = []
     # we list all the files in the specified directory
     listing = os.listdir(household_directory)
     # and check if the number of files is in line with the parameters
     if (len(listing) != self.num_households):
         logging.error("    ERROR: number of configuration files in %s (=%s) does not match num_households (=%s)",
                       household_directory,  str(len(listing)), str(self.num_households))
     # we read the files sequentially
     for infile in listing:
         household = Household()
         household.get_parameters_from_file(household_directory + infile,  self)
         # and read parameters to the firms, only to add them to the environment
         self.households.append(household)
Example #3
0
    def household__get_parameters_from_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  # needed for the bankDirectory

        text = "This test checks household.get_parameters_from_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 household__get_parameters_from_file in run: %s',
                     environment_directory + identifier + ".xml")

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

        # get the household_directory from the environment
        household_directory = environment.household_directory
        # and loop over all firms in the directory
        listing = os.listdir(household_directory)
        householdFilename = household_directory + listing[0]

        # 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()
        environment.households.append(household)
        household.get_parameters_from_file(householdFilename, environment)

        #
        # TESTING
        #

        # test whether the parameters are read properly
        text = "Identifier has been read as follows: \n"
        text = text + "Identifier: "
        text = text + household.identifier
        text = text + "\n"
        text = text + "Amount of labour: "
        text = text + str(household.parameters["labour"])
        text = text + "\n"
        text = text + "Propensity to save: "
        text = text + str(household.parameters["propensity_to_save"])
        self.print_info(text)