def __init__(self, record, VarList, current_year, db, pp_table_name, pp_table, land_dict, model_parameters):
        '''
        Construct the household class from the household table in the DB, and then add some other user-defined attributes.

        record - a record in the household table in the DB.       
        VarList - the variable (or field) list of the household table in the DB   
        VarList = {paramName1: paramOrder1, paramName2: paramOrder2, ...}
        
        Also initialize the household's own person instances here from the person table in the DB.
        Also initialize the household's capital properties instance here.     
        '''       
        
        # Set the attributes (var) and their values (record) from the household table in the DB.
        for var in VarList:
            setattr(self, var[0], record[var[1]])

        # Set the household and person variables (attributes) lists
        self.hh_var_list = VarList
        self.pp_var_list = DataAccess.get_var_list(db, pp_table_name)


        # Set the current time stamp
        self.StatDate = current_year
        
        
        # Define own persons (members) dict of the household, indexed by PID
        self.own_pp_dict = dict()

        
        # Add respective persons into the persons dict of the household
        for pp in pp_table:
            if pp.HID == self.HID:
                pp_temp = Person(pp, self.pp_var_list, current_year)
                self.own_pp_dict[pp_temp.PID] = pp_temp # Indexed by PID
        

        
        # Initialize the household's capital properties class instance
        self.own_capital_properties = CapitalProperty(self, land_dict, model_parameters)
        
        # Define an empty list of available business sectors,
        # and another empty list of the business sectors that the household is in in the current year
        self.own_av_business_sectors = list()
        self.own_current_sectors = list()
        
        # Define an empty list of participant policy programs
        self.own_policy_programs = list()


        # Initialize the household's energy class instance
        self.energy = Energy()
        
        
        # Define a variable indicating the household's preference type
        '''
        1 - Max Labor, Min Risk;
        2 - Min Labor, Min Risk;
        3 - Max Labor, Max Risk;
        4 - Min Labor, Max Risk;
        '''
        self.hh_preference_type = int()
        
        # Also define a variable indicating the preference toward risks
        '''
        True - risk aversion; False - risk appetite;
        '''
        self.hh_risk_type = True
        
        
        # Define a variable indicating the household's business type
        '''
        0 - agriculture only
        1 - agriculture and another business sectors; or one business sector which is not agriculture
        2 - agriculture and more than one other business sectors
        '''
        self.business_type = int()
        
        # Define a switch variable indicating whether the household is dissolved in the current year
        self.is_dissolved_this_year = False
Beispiel #2
0
    def __init__(self, record, VarList, current_year, db, pp_table_name, pp_table, land_dict, model_parameters):
        '''
        Construct the household class from the household table in the DB, and then add some other user-defined attributes.

        record - a record in the household table in the DB.       
        VarList - the variable (or field) list of the household table in the DB   
        VarList = {paramName1: paramOrder1, paramName2: paramOrder2, ...}
        
        Also initialize the household's own person instances here from the person table in the DB.
        Also initialize the household's capital properties instance here.     
        '''       
        
        # Set the attributes (var) and their values (record) from the household table in the DB.
        for var in VarList:
            setattr(self, var[0], record[var[1]])

        # Set the household and person variables (attributes) lists
        self.hh_var_list = VarList
        self.pp_var_list = DataAccess.get_var_list(db, pp_table_name)


        # Set the current time stamp
        self.StatDate = current_year
        
        
        # Define own persons (members) dict of the household, indexed by PID
        self.own_pp_dict = dict()

        
        # Add respective persons into the persons dict of the household
        for pp in pp_table:
            if pp.HID == self.HID:
                pp_temp = Person(pp, self.pp_var_list, current_year)
                self.own_pp_dict[pp_temp.PID] = pp_temp # Indexed by PID
        

        
        # Initialize the household's capital properties class instance
        self.own_capital_properties = CapitalProperty(self, land_dict, model_parameters)
        
        # Define an empty list of available business sectors,
        # and another empty list of the business sectors that the household is in in the current year
        self.own_av_business_sectors = list()
        self.own_current_sectors = list()
        
        # Define an empty list of participant policy programs
        self.own_policy_programs = list()


        # Initialize the household's energy class instance
        self.energy = Energy()
        
        
        # Define a variable indicating the household's preference type
        '''
        1 - Max Labor, Min Risk;
        2 - Min Labor, Min Risk;
        3 - Max Labor, Max Risk;
        4 - Min Labor, Max Risk;
        '''
        self.hh_preference_type = int()
        
        # Also define a variable indicating the preference toward risks
        '''
        True - risk aversion; False - risk appetite;
        '''
        self.hh_risk_type = True
        
        
        # Define a variable indicating the household's business type
        '''
        0 - agriculture only
        1 - agriculture and another business sectors; or one business sector which is not agriculture
        2 - agriculture and more than one other business sectors
        '''
        self.business_type = int()
        
        # Define a switch variable indicating whether the household is dissolved in the current year
        self.is_dissolved_this_year = False
Beispiel #3
0
    def __init__(self, db, model_table_name, model_table, hh_table_name, hh_table, pp_table_name, pp_table, 
                 land_table_name, land_table, business_sector_table_name, business_sector_table, 
                 policy_table_name, policy_table, stat_table_name, stat_table, start_year):
        '''
        Initialize the society class;
        '''
        
        # Set the start year and current time stamps
        self.start_year = start_year
        self.current_year = start_year
        
        # Create a dictionary to store model parameters, indexed by Variable_Name, and contents are Variable_Value      
        self.model_parameters_dict = dict()        
        # Fill in the model parameters dictionary from the model table (fetched from DB)
        for record in model_table:
            self.model_parameters_dict[record.Variable_Name] = record.Variable_Value
          
        
        # Get the variable lists for household, person, land, business sector, policy, and statistics classes 
        self.hh_var_list = DataAccess.get_var_list(db, hh_table_name)
        self.pp_var_list = DataAccess.get_var_list(db, pp_table_name)
        self.land_var_list = DataAccess.get_var_list(db, land_table_name)
        self.business_sector_var_list = DataAccess.get_var_list(db, business_sector_table_name)
        self.policy_var_list = DataAccess.get_var_list(db, policy_table_name)
        self.stat_var_list = DataAccess.get_var_list(db, stat_table_name)


        # Initialize the land instances, and create a land dictionary to store all the land parcels
        # Note that the land parcels here do not necessarily belong to any household. i.e. land_parcel.HID could be "None".
        self.land_dict = dict()
        for land in land_table:
            land_parcel = Land(land, self.land_var_list, self.current_year)
            self.land_dict[land_parcel.ParcelID] = land_parcel # Indexed by ParcelID


        # Initialize the household instances (household capital property and land class instances are initialized at the initialization of household class);
        # And create a dictionary to store them, indexed by HID.
        self.hh_dict = dict()        
        # Add household instances to hh_dict
        for hh in hh_table:
            hh_temp = Household(hh, self.hh_var_list, self.current_year, db, pp_table_name, pp_table, 
                                self.land_dict, self.model_parameters_dict)
            self.hh_dict[hh_temp.HID] = hh_temp # Indexed by HID

        
        # Initialize the business sector instances;
        # And create a dictionary to store them, indexed by sector name.
        self.business_sector_dict = dict()
        for sector in business_sector_table:
            sector_temp = BusinessSector(sector, self.business_sector_var_list)
            self.business_sector_dict[sector_temp.SectorName] = sector_temp # Indexed by SectorName
            
        
        # Initialize the policy program instances;
        # And create a dictionary to store them, indexed by policy program type.
        self.policy_dict = dict()
        for program in policy_table:
            program_temp = Policy(program, self.policy_var_list)
            self.policy_dict[program_temp.PolicyType] = program_temp # Indexed by PolicyType
        
                        
        # Create a statistics dictionary; indexed by Variable Names.To be filled later in Statistics Class.
        self.stat_dict = dict()
        
        # Create some variables to record the confiscated (due to ownerlessness) money and land
        self.ownerless_land = list()
        self.ownerless_money = 0
Beispiel #4
0
    def __init__(self, db, model_table_name, model_table, hh_table_name, hh_table, pp_table_name, pp_table, 
                 land_table_name, land_table, business_sector_table_name, business_sector_table, 
                 policy_table_name, policy_table, stat_table_name, stat_table, start_year):
        '''
        Initialize the society class;
        '''
        
        # Set the start year and current time stamps
        self.start_year = start_year
        self.current_year = start_year
        
        # Create a dictionary to store model parameters, indexed by Variable_Name, and contents are Variable_Value      
        self.model_parameters_dict = dict()        
        # Fill in the model parameters dictionary from the model table (fetched from DB)
        for record in model_table:
            self.model_parameters_dict[record.Variable_Name] = record.Variable_Value
          
        
        # Get the variable lists for household, person, land, business sector, policy, and statistics classes 
        self.hh_var_list = DataAccess.get_var_list(db, hh_table_name)
        self.pp_var_list = DataAccess.get_var_list(db, pp_table_name)
        self.land_var_list = DataAccess.get_var_list(db, land_table_name)
        self.business_sector_var_list = DataAccess.get_var_list(db, business_sector_table_name)
        self.policy_var_list = DataAccess.get_var_list(db, policy_table_name)
        self.stat_var_list = DataAccess.get_var_list(db, stat_table_name)


        # Initialize the land instances, and create a land dictionary to store all the land parcels
        # Note that the land parcels here do not necessarily belong to any household. i.e. land_parcel.HID could be "None".
        self.land_dict = dict()
        for land in land_table:
            land_parcel = Land(land, self.land_var_list, self.current_year)
            self.land_dict[land_parcel.ParcelID] = land_parcel # Indexed by ParcelID


        # Initialize the household instances (household capital property and land class instances are initialized at the initialization of household class);
        # And create a dictionary to store them, indexed by HID.
        self.hh_dict = dict()        
        # Add household instances to hh_dict
        for hh in hh_table:
            hh_temp = Household(hh, self.hh_var_list, self.current_year, db, pp_table_name, pp_table, 
                                self.land_dict, self.model_parameters_dict)
            self.hh_dict[hh_temp.HID] = hh_temp # Indexed by HID

        
        # Initialize the business sector instances;
        # And create a dictionary to store them, indexed by sector name.
        self.business_sector_dict = dict()
        for sector in business_sector_table:
            sector_temp = BusinessSector(sector, self.business_sector_var_list)
            self.business_sector_dict[sector_temp.SectorName] = sector_temp # Indexed by SectorName
            
        
        # Initialize the policy program instances;
        # And create a dictionary to store them, indexed by policy program type.
        self.policy_dict = dict()
        for program in policy_table:
            program_temp = Policy(program, self.policy_var_list)
            self.policy_dict[program_temp.PolicyType] = program_temp # Indexed by PolicyType
        
                        
        # Create a statistics dictionary; indexed by Variable Names.To be filled later in Statistics Class.
        self.stat_dict = dict()
        
        # Create some variables to record the confiscated (due to ownerlessness) money and land
        self.ownerless_land = list()
        self.ownerless_money = 0