2022-07-22 12:05:57 +02:00
|
|
|
import csv
|
|
|
|
import math
|
|
|
|
import random
|
|
|
|
import matplotlib.pyplot as plt
|
2022-07-26 16:27:35 +02:00
|
|
|
|
2022-07-22 12:05:57 +02:00
|
|
|
class Mensch(object):
|
2022-07-26 16:27:35 +02:00
|
|
|
|
|
|
|
def __init__(self, alter, geschlecht, bdl):
|
|
|
|
self.Alter = alter
|
|
|
|
self.Geschlecht = geschlecht #0 Mann, 1 Frau
|
|
|
|
self.Bundesland = bdl
|
|
|
|
self.Koordinaten = self.getCoordinates(bdl)
|
|
|
|
self.Infiziert = False
|
|
|
|
self.Stichtag = None
|
|
|
|
|
|
|
|
|
|
|
|
def __del__(self):
|
|
|
|
self.Alter = None
|
|
|
|
self.Geschlecht = None
|
|
|
|
self.Bundesland = None
|
|
|
|
self.Koordinaten = None
|
|
|
|
|
2022-07-22 12:05:57 +02:00
|
|
|
def getCoordinates(self, bdl):
|
2022-07-26 16:27:35 +02:00
|
|
|
bdlDict = {'Vorarlberg':[0,0], 'Tirol':[1,0], 'Kärnten':[2,0], 'Salzburg':[0,1], 'Steiermark':[1,1], 'Burgenland':[2,1], 'Oberösterreich':[0,2] ,'Niederösterreich':[1,2], 'Wien':[2,2]}
|
|
|
|
|
2022-07-22 12:05:57 +02:00
|
|
|
return [int(bdlDict[bdl][0]) + random.random(), int(bdlDict[bdl][1]) + random.random()]
|
2022-07-26 16:27:35 +02:00
|
|
|
|
2022-07-22 12:05:57 +02:00
|
|
|
def die(self):
|
2022-07-26 16:27:35 +02:00
|
|
|
randDie = random.random()
|
|
|
|
infectFaktor = 1
|
|
|
|
genderFaktor = 0.493
|
|
|
|
if self.Geschlecht == 1:
|
|
|
|
genderFaktor = 0.507
|
|
|
|
if self.Infiziert:
|
|
|
|
infectFaktor = 5
|
|
|
|
if (randDie < (int(gestDict[self.Bundesland][int(self.Geschlecht)])*infectFaktor/(int(bevDict[self.Bundesland])*365*genderFaktor))):
|
|
|
|
return True
|
|
|
|
else:
|
|
|
|
return False
|
|
|
|
|
2022-07-22 12:05:57 +02:00
|
|
|
def infect(self, day):
|
2022-07-26 16:27:35 +02:00
|
|
|
if (int(day) - int(self.Stichtag)) > 10:
|
|
|
|
self.Infiziert = False
|
|
|
|
else:
|
|
|
|
for i in range(20):
|
|
|
|
randIndex = random.randint(0, len(Population)-1)
|
|
|
|
randInfect = random.random()
|
|
|
|
if(self.Bundesland == Population[randIndex].Bundesland):
|
|
|
|
Distanz = math.sqrt((self.Koordinaten[0] - Population[randIndex].Koordinaten[0]) * (
|
|
|
|
self.Koordinaten[0] - Population[randIndex].Koordinaten[0]) + (
|
|
|
|
self.Koordinaten[1] - Population[randIndex].Koordinaten[1]) * (
|
|
|
|
self.Koordinaten[1] - Population[randIndex].Koordinaten[1]))
|
|
|
|
InfectProb = 0.3 * (1 - Distanz)
|
|
|
|
else:
|
|
|
|
InfectProb = 0.0015
|
|
|
|
if(randInfect< InfectProb):
|
|
|
|
Population[randIndex].Infiziert = True
|
|
|
|
Population[randIndex].Stichtag = day
|
|
|
|
|
2022-07-22 12:05:57 +02:00
|
|
|
class Simulation(object):
|
2022-07-26 16:27:35 +02:00
|
|
|
|
2022-07-22 12:05:57 +02:00
|
|
|
def __init__(self, population):
|
|
|
|
self.Population = population
|
2022-07-26 16:27:35 +02:00
|
|
|
|
2022-07-22 12:05:57 +02:00
|
|
|
def simulate(self):
|
2022-07-26 16:27:35 +02:00
|
|
|
|
|
|
|
print(len(Population))
|
|
|
|
|
|
|
|
RandomStartInfekt = random.randint(0, len(Population)-1)
|
|
|
|
Population[RandomStartInfekt].Infiziert = True
|
|
|
|
Population[RandomStartInfekt].Stichtag = 0
|
|
|
|
RandomStartInfekt = random.randint(0, len(Population)-1)
|
|
|
|
Population[RandomStartInfekt].Infiziert = True
|
|
|
|
Population[RandomStartInfekt].Stichtag = 0
|
|
|
|
RandomStartInfekt = random.randint(0, len(Population)-1)
|
|
|
|
Population[RandomStartInfekt].Infiziert = True
|
|
|
|
Population[RandomStartInfekt].Stichtag = 0
|
|
|
|
|
|
|
|
plt.ion()
|
|
|
|
|
|
|
|
for i in range(365):
|
|
|
|
print("Today is day number "+ str(i))
|
|
|
|
for key in gebDict.keys():
|
|
|
|
for j in range(int(abs(random.gauss((int(gebDict[key][0])*Populationsfaktor/(365)), 1)))):
|
|
|
|
self.Population.append(Mensch(0, 0, key))
|
|
|
|
for j in range(int(abs(random.gauss((int(gebDict[key][1])*Populationsfaktor / (365)), 1)))):
|
|
|
|
self.Population.append(Mensch(0, 1, key))
|
|
|
|
|
|
|
|
print(len(Population))
|
|
|
|
|
|
|
|
deathlist = []
|
|
|
|
for human in Population:
|
|
|
|
if(human.die()):
|
|
|
|
deathlist.append(Population.index(human))
|
|
|
|
if(human.Infiziert):
|
|
|
|
human.infect(i)
|
|
|
|
|
|
|
|
deathlist.sort(reverse=True)
|
|
|
|
for index in deathlist:
|
|
|
|
Population.remove(Population[index])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#Visualisierung
|
|
|
|
#Scatter Plot
|
|
|
|
x_inf = []
|
|
|
|
y_inf = []
|
|
|
|
x_fit = []
|
|
|
|
y_fit = []
|
|
|
|
|
|
|
|
for human in Population:
|
|
|
|
if(human.Infiziert):
|
|
|
|
#plt.plot(human.Koordinaten[0], human.Koordinaten[1], "o", color="red", markersize=2)
|
|
|
|
x_inf.append(human.Koordinaten[0])
|
|
|
|
y_inf.append(human.Koordinaten[1])
|
|
|
|
else:
|
|
|
|
#plt.plot(human.Koordinaten[0], human.Koordinaten[1], "o", color="blue", markersize=1)
|
|
|
|
x_fit.append(human.Koordinaten[0])
|
|
|
|
y_fit.append(human.Koordinaten[1])
|
|
|
|
|
|
|
|
plt.title("Population")
|
|
|
|
plt.scatter(x_inf, y_inf, c="red", s=5)
|
|
|
|
plt.scatter(x_fit, y_fit, c="blue", s=2)
|
|
|
|
|
|
|
|
plt.draw()
|
|
|
|
if(i % 5 == 0):
|
|
|
|
plt.savefig('result/populationOnDay' + str(i) + '.png')
|
|
|
|
plt.pause(0.0001)
|
|
|
|
plt.clf()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
print(len(Population))
|
|
|
|
|
|
|
|
|
|
|
|
|
2022-07-22 12:05:57 +02:00
|
|
|
if __name__ == '__main__':
|
2022-07-26 16:27:35 +02:00
|
|
|
|
|
|
|
|
2022-07-22 12:05:57 +02:00
|
|
|
print("Generate Population:")
|
|
|
|
Populationsfaktor = 0.01
|
|
|
|
Population = []
|
|
|
|
bevAnzahl = 0
|
|
|
|
bevDict = {}
|
|
|
|
gebDict = {}
|
|
|
|
gestDict = {}
|
2022-07-26 16:27:35 +02:00
|
|
|
AnteilFrauen = 0.507
|
|
|
|
|
|
|
|
|
2022-07-22 12:05:57 +02:00
|
|
|
#read data from Statistik Austria
|
|
|
|
with open('./data/Bevölkerung.csv') as bevoelkerung:
|
|
|
|
csv_reader = csv.reader(bevoelkerung, delimiter = ';')
|
|
|
|
rowcnt = 0
|
|
|
|
for row in csv_reader:
|
|
|
|
rowcnt = rowcnt + 1
|
|
|
|
if rowcnt == 2:
|
|
|
|
bevAnzahl = int(int(row[-1])*Populationsfaktor)
|
|
|
|
if rowcnt > 2:
|
|
|
|
bevDict[row[0]] = row[-1]
|
|
|
|
with open('./data/Geburten2021.csv') as geburten:
|
|
|
|
csv_reader = csv.reader(geburten, delimiter=';')
|
|
|
|
rowcnt = 0
|
|
|
|
for row in csv_reader:
|
|
|
|
rowcnt = rowcnt + 1
|
|
|
|
if rowcnt > 2:
|
|
|
|
gebDict[row[0]] = [row[-2], row[-1]]
|
2022-07-26 16:27:35 +02:00
|
|
|
|
2022-07-22 12:05:57 +02:00
|
|
|
with open('./data/Gestorbene2021.csv') as gestorbene:
|
|
|
|
csv_reader = csv.reader(gestorbene, delimiter=';')
|
|
|
|
rowcnt = 0
|
|
|
|
for row in csv_reader:
|
|
|
|
rowcnt = rowcnt + 1
|
|
|
|
if rowcnt > 2:
|
|
|
|
gestDict[row[0]] = [row[-2], row[-1]]
|
2022-07-26 16:27:35 +02:00
|
|
|
|
2022-07-22 12:05:57 +02:00
|
|
|
print(bevDict)
|
|
|
|
print(gebDict)
|
|
|
|
print(gestDict)
|
|
|
|
print(bevAnzahl)
|
|
|
|
print(random.random())
|
2022-07-26 16:27:35 +02:00
|
|
|
|
2022-07-22 12:05:57 +02:00
|
|
|
for i in range(int(bevAnzahl)):
|
|
|
|
gender = 1
|
|
|
|
if(random.random()>0.507):
|
|
|
|
gender = 0
|
|
|
|
age = random.randint(0, 101)
|
2022-07-26 16:27:35 +02:00
|
|
|
|
2022-07-22 12:05:57 +02:00
|
|
|
bdl = ""
|
|
|
|
randBdl = random.random()
|
|
|
|
BdlCount = 0
|
|
|
|
for key in bevDict.keys():
|
|
|
|
BdlCount += int(bevDict[key])
|
|
|
|
checkWlsk = (BdlCount*Populationsfaktor)/int(bevAnzahl)
|
|
|
|
if(randBdl < checkWlsk):
|
|
|
|
bdl = str(key)
|
|
|
|
break
|
2022-07-26 16:27:35 +02:00
|
|
|
|
|
|
|
|
2022-07-22 12:05:57 +02:00
|
|
|
Population.append(Mensch(age, gender, bdl))
|
2022-07-26 16:27:35 +02:00
|
|
|
|
2022-07-22 12:05:57 +02:00
|
|
|
Simulation = Simulation(Population)
|
|
|
|
Simulation.simulate()
|
2022-07-26 16:27:35 +02:00
|
|
|
|
|
|
|
# See PyCharm help at https://www.jetbrains.com/help/pycharm/
|