population simulation """ import numpy as np import pandas as pd import matplotlib.pyplot as plt
import subprocess
sta=time.time()
timespan=100 ratio=0.1 male_ratio=0.51 # children are born from couple between lower and upper years old. lower=18 upper=40 lifespan=100 ini_pop=500000
#initial male and female for 500,000 male=pd.Series(np.random.randint(0,lifespan+1,ini_pop)) female=pd.Series(np.random.randint(0,lifespan+1,ini_pop))
new_b=0
for year in range(timespan+1): plot(male, female) print("year=", year, "new_b=", new_b, "male= ",len(male), "female= ", len(female), "population= ", len(male)+len(female)) # children are born from couple between lower and upper years old. young_m=len(male[lower<male][male<upper]) young_f=len(female[lower<female][female<upper]) new_b=int(ratio*min(young_m, young_f)) n_male=int(male_ratio*new_b) # aging male=male+1 female=female+1 # children are added male=pd.concat([male, pd.Series(np.zeros(n_male))]) female=pd.concat([female, pd.Series(np.zeros(new_b-n_male))]) male=male.reset_index(drop=True) female=female.reset_index(drop=True) male=male[male<lifespan] female=female[female<lifespan] plot(male, female)