def create_business(self, social_stratum=None): x, y = self.random_position() if social_stratum is None: social_stratum = int(np.random.rand(1) * 100 // 20) self.business.append(Business(x=x, y=y, status=Status.Susceptible, social_stratum=social_stratum, #fixed_expenses=(social_stratum+1)*self.minimum_expense #fixed_expenses=self.minimum_expense / (5 - social_stratum) environment=self ))
def initialize(self): """ Initializate the Simulation by creating its population of agents """ x, y = self.random_position() self.healthcare = Business(x=x, y=y, status=Status.Susceptible, type=AgentType.Healthcare, environment=self) self.healthcare.fixed_expenses += self.minimum_expense * 3 x, y = self.random_position() self.government = Business(x=x, y=y, status=Status.Susceptible, type=AgentType.Government, social_stratum=4, price=1.0, environment=self) self.government.fixed_expenses += self.population_size * ( self.minimum_expense * 0.05) #number of houses for i in np.arange(0, int(self.population_size // self.homemates_avg)): self.create_house(social_stratum=i % 5) # number of business for i in np.arange(0, self.total_business): self.create_business(social_stratum=5 - (i % 5)) # Initial infected population for i in np.arange( 0, int(self.population_size * self.initial_infected_perc)): self.create_agent(Status.Infected, infected_time=5) # Initial immune population for i in np.arange( 0, int(self.population_size * self.initial_immune_perc)): self.create_agent(Status.Recovered_Immune) # Initial susceptible population for i in np.arange(0, self.population_size - len(self.population)): self.create_agent(Status.Susceptible, social_stratum=i % 5) # Share the common wealth of 10^4 among the population, according each agent social stratum self.government.wealth = self.total_wealth * self.public_gdp_share for quintile in [0, 1, 2, 3, 4]: _houses = [ x for x in filter(lambda x: x.social_stratum == quintile, self.houses) ] nhouses = len(_houses) if nhouses == 0: self.create_house(social_stratum=quintile) _houses = [self.houses[-1]] nhouses = 1 if self.total_business > 5: btotal = lorenz_curve[quintile] * (self.total_wealth * self.business_gdp_share) bqty = max( 1.0, np.sum([ 1.0 for a in self.business if a.social_stratum == quintile ])) else: btotal = self.total_wealth * self.business_gdp_share bqty = self.total_business ag_share = btotal / bqty for bus in filter(lambda x: x.social_stratum == quintile, self.business): bus.wealth = ag_share ptotal = lorenz_curve[quintile] * self.total_wealth * ( 1 - (self.public_gdp_share + self.business_gdp_share)) pqty = max( 1.0, np.sum([ 1 for a in self.population if a.social_stratum == quintile and a.economical_status == EconomicalStatus.Active ])) ag_share = ptotal / pqty for agent in filter(lambda x: x.social_stratum == quintile, self.population): # distribute wealth if agent.economical_status == EconomicalStatus.Active: agent.wealth = ag_share agent.incomes = basic_income[ agent.social_stratum] * self.minimum_income # distribute employ unemployed_test = np.random.rand() if unemployed_test >= self.unemployment_rate: ix = np.random.randint(0, self.total_business) self.business[ix].hire(agent) agent.expenses = basic_income[ agent.social_stratum] * self.minimum_expense #distribute habitation homeless_test = np.random.rand() if not (quintile == 0 and homeless_test <= self.homeless_rate): for kp in range(0, 5): ix = np.random.randint(0, nhouses) house = _houses[ix] if house.size < self.homemates_avg + self.homemates_std: house.append_mate(agent) continue if agent.house is None: ix = np.random.randint(0, nhouses) self.houses[ix].append_mate(agent)