Ejemplo n.º 1
0
 def stage0(self):
     #print('cap')
    # if self.region == 0:
     #    self.CCA_RD()
     if self.lifecycle > 16:
         self.migrate()
         if self.model.governments[0].aggregate_employment[self.region] == 0:
                     self.region, self.employees_IDs, self.net_worth, self.wage = migration.firm_migrate(1, self.model, self.region, self.unique_id, self.employees_IDs, self.net_worth, self.wage, 0)
         #print(self.region, self.productivity)
         #if self.sales > 0:
        
     if self.model.S > 0:
         self.climate_damages()
       
     self.RD()
     self.calculateProductionCost()
     self.calculatePrice()
     self.advertise()
Ejemplo n.º 2
0
 def stage0(self):
  #   if self.model.schedule.time > self.migration_start:
     #
     self.bankrupt = None
     if self.lifecycle > 16:
             self.migrate()
             if self.model.governments[0].aggregate_employment[self.region] == 0:
                     self.region, self.employees_IDs, self.net_worth, self.wage = migration.firm_migrate(1, self.model, self.region, self.unique_id, self.employees_IDs, self.net_worth, self.wage, self.capital_vintage)
    
     
     if  self.model.S > 0:
         
         self.climate_damages() 
     #   self.CCA_RD()
     if self.lifecycle > 0:
         self.update_capital()
         self.capital_investments()
         if self.replacement_investment_units > 0 or self.expansion_investment_units > 0:
             self.choose_supplier_and_place_order()
Ejemplo n.º 3
0
 def migrate(self):
     
     ##----stocastic barrier to migration --##
    # if  bernoulli.rvs(0.25) == 1:
         r = self.region
         #demand = [self.regional_demand[0] + self.regional_demand[2], self.regional_demand[1]]
         demand = self.regional_demand
         past_sales = self.past_sales 
              
         demand_distance = 0
         if demand[1 -r] > demand[r] and demand[1 - r] > past_sales[1- r]:
              demand_distance = (demand[r] - demand[1-r]) /  demand[r]
              
              prof_distance = 0 
              
          
              # old sales in my region
              past_sales_hr = np.log(past_sales[r])
              
              #old sales in foreign region
              past_sales_fr= np.log(past_sales[1 - r])
                  
              # current sales in my region  (home region) 
              current_sales_hr = np.log(demand[r])
              
              # corrent sales in foreign region
              current_sales_fr = np.log(demand[1 -r])
                  
              profitability_hr =   max( -0.15 ,  min( 0.15, current_sales_hr - past_sales_hr))
              profitability_fr  =   max( -0.15 , min( 0.15 , current_sales_fr - past_sales_fr))
              
              if profitability_fr > profitability_hr and profitability_fr > 0:
                  prof_distance = max( -0.5 , (profitability_hr - profitability_fr) / profitability_hr)
                  mp =  1 - np.exp(0.5 * demand_distance  +   0.5 * prof_distance) 
                  
         ##--calculation of migration probability and process, modules ---> migration --##
                #  mp  = migration.firms_migration_probability( demand_distance, self.region,   self.model, prof_distance) # self.distances_mig)
         #print("mp is", mp
         #self.region_history.append([mp, r])
                  if mp > 0:
                     self.region, self.employees_IDs, self.net_worth, self.wage = migration.firm_migrate(mp, self.model, self.region, self.unique_id, self.employees_IDs, self.net_worth, self.wage, self.capital_vintage)
Ejemplo n.º 4
0
 def migrate(self):
     ##-- stochastic entry barrier to migration process --##
    
 #    if bernoulli.rvs(0.25) == 1:
     #if self.unique_id % 10 != 0:
        
        # unemployment_subsidy = self.model.datacollector.model_vars["Regional_unemployment_subsidy"][int(self.model.schedule.time)]
         demand_distance = 0 
         demand = self.real_demand_cap
         past_sales = self.past_demand
         if demand[1] > demand[0] and demand[1] > past_sales[1]:
             
            demand_distance = ( demand[0] - demand[1]) / (demand[0] + 0.001)
            prof_distance = 0 
             
           # r = self.region
              
            # od sales in my region
            
            past_sales[0] = float(past_sales[0])
            past_sales[1] = float(past_sales[1])
            demand[1] =float(demand[1])
            demand[0] =float(demand[0])
            
            
            past_sales_hr = max( 0 , np.log(past_sales[0]))
     
            #old sales in foreign region
            past_sales_fr= max( 0 , np.log(past_sales[1]))
                  
            # current sales in my region  (home region) 
            current_sales_hr = max( 0 , np.log(demand[0]))
              
            # corrent sales in foreign region
            current_sales_fr =  max( 0 ,  np.log(demand[1]))
                  
            profitability_hr =   max( -0.15 ,  min( 0.15, current_sales_hr - past_sales_hr))
            profitability_fr  =   max( -0.15 , min( 0.15 , current_sales_fr - past_sales_fr))
              
            if profitability_fr > profitability_hr and profitability_fr > 0:
                 prof_distance = max( -0.5 , (profitability_hr - profitability_fr) / profitability_fr)
             
                 mp =  1 - np.exp(0.5 * demand_distance  +   0.5 * prof_distance) 
                 
                 if mp> 0:
                      self.region, self.employees_IDs, self.net_worth, self.wage = migration.firm_migrate(mp, self.model, self.region, self.unique_id, self.employees_IDs, self.net_worth, self.wage, 0)
Ejemplo n.º 5
0
    def entry_exit_cons(self):
        # exit firms
        all_firms_cons = self.model.firms2

        for firm in all_firms_cons:
            if sum(firm.market_share
                   ) < 0.003 or firm.labor_demand == 0:  #firm.lifecycle > 6):
                if firm.lifecycle > 6:
                    # fire employees
                    firm.bankrupt = len(firm.employees_IDs)

                    for employee_id in firm.employees_IDs:
                        employee = firm.model.schedule.agents[employee_id]
                        employee.employer_ID = None
                    firm.employees_IDs = []

                    r = firm.region
                    average_regional_NW = self.model.datacollector.model_vars[
                        "Regional_average_NW"][int(self.model.schedule.time)]
                    regional_wage = self.salaries_cons

                    #updating

                    #average_regional_cons_prof =  self.model.datacollector.model_vars["Regional_profits_cons"][int(self.model.schedule.time)]
                    # current_average_price =  self.model.datacollector.model_vars["Cosumption_price_average"][int(self.model.schedule.time)]
                    #  average_regional_cons=  self.aggregate_cons

                    firm.net_worth = average_regional_NW[r] * 0.5
                    firm.credit_rationed = False
                    firm.capital_vintage = []

                    ###---location of the firm  ---###
                    #cons_distance = (average_regional_cons[r] - average_regional_cons[1 - r]) /  max(average_regional_cons)
                    '''
                    cons_distance =   0 #average_regional_cons[3 + r]
                    
                    
                    mp = migration.firms_migration_probability( cons_distance, r, firm.model , w_1 = 0, w_2 = 1)
                    #print("mp is", mp
                    #firm.region_history.append([mp, r])
                    firm.region, firm.employees_IDs, firm.net_worth,  firm.wage = migration.firm_migrate(mp, firm.model, r, firm.unique_id, firm.employees_IDs, firm.net_worth, regional_wage[r], 0) 
                    '''
                    r = firm.region

                    if self.aggregate_employment[
                            r] == r or self.unemployment_rates[r] == 1:
                        firm.region, firm.employees_IDs, firm.net_worth, firm.wage = migration.firm_migrate(
                            1, firm.model, r, firm.unique_id,
                            firm.employees_IDs, firm.net_worth,
                            regional_wage[r], 0)

                    firm.capital_amount = self.model.datacollector.model_vars[
                        "Capital_Regional"][int(self.model.schedule.time)][r +
                                                                           2]
                    '''
                    supplier_region =[ a  for a in self.model.firms1 if  a.region == r]
                    if supplier_region != []:
                        supplier = random.choice(supplier_region)
                    else:
                        supplier = random.choice(self.model.firms1)
                    '''
                    supplier = self.best_firm1[r]
                    #supplier_id = random.choice(self.model.ids_firms1)

                    #for i in range(math.ceil(firm_capital_amount)):
                    for i in range(4):
                        firm.capital_vintage.append(
                            Vintage(prod=round(supplier.productivity[0]),
                                    amount=firm.capital_amount // 4))
                    # a = [[[1,5],[1,0]], ]
                    #print

                # firm.price = current_average_price[r] + 0.00001
                    firm.markup = 0.3
                    firm.productivity = [
                        supplier.productivity[1], supplier.productivity[1]
                    ]  #, supplier.productivity[1]]
                    #firm.productivity[1] = supplier.productivity[1]

                    firm.normalized_price += 0.00001  #to avoid Nan when calculating competitiveness
                    firm.competitiveness = [
                        round(self.average_normalized_comp[0], 5),
                        round(self.average_normalized_comp[1], 5)
                    ]

                    #firm.market_share = [self.average_normalized_market_share[0] * 0.75, self.average_normalized_market_share[1] * 0.75, self.average_normalized_market_share[2] * 0.75]
                    #firm.market_share_history = [ sum(firm.market_share), sum(firm.market_share)]
                    firm.market_share = [0, 0, 0]
                    firm.past_demands = []
                    #for i in range(3):
                    #   firm.past_demands.append( sum(average_regional_cons) * firm.market_share_history[0])
                    firm.competitiveness = self.average_normalized_comp
                    firm.markup = 0.3
                    firm.real_demand = 0  # firm.past_demands[1]
                    firm.unfilled_demand = 0
                    firm.invetories = 0
                    firm.offers = []
                    firm.wage = regional_wage[r]  #* 1.1
                    firm.order_reduced = 0
                    #firm.investment_cost = 0
                    firm.market_share_history = []
                    firm.past_demands = []
                    firm.production_made = 0

                    #firm.market_share_history[ 0.9 * self.average_normalized_market_share, 0.9 * self.average_normalized_market_share]      # the firms gets a fraction (0.9) of the avergae

                    firm.lifecycle = -1