Commit 3e6e953d authored by Jéhoiakim KINGNE's avatar Jéhoiakim KINGNE
Browse files

Après 242 jours

parent ffa68039
......@@ -8,6 +8,50 @@ from math import atan, pi
from matplotlib import pyplot
#input_filename_altitude="D:/documents/IMT/datascience/challenge3/moodle/altitude-map.bmp"
input_filename_altitude="../moodle/altitude-map.bmp"
im_alt = Image.open(input_filename_altitude)
#input_filename_poputation="D:/documents/IMT/datascience/challenge3/moodle/population-density-map.bmp"
input_filename_poputation="../moodle/population-density-map.bmp"
im_pop = Image.open(input_filename_poputation)
# This modules gives useful informations
width=im_alt.size[0]
heigth=im_alt.size[1]
print("width = ",width)
print("heigth = ", heigth)
# To plot an histogram
pix_mont_blanc=im_alt.getpixel((1573,1593))
pix_sea_level=im_alt.getpixel((929,1666))
pix_sea=im_alt.getpixel((1,1))
print(pix_sea,pix_sea_level,pix_mont_blanc) #rgb
def getAltitude(rgbValues):
'''assigne à un triplet RGB (gris) une altitude'''
greyValue=rgbValues[0]
return(4810/255*greyValue)
def getAltXY(pixel):
'''Permet d'avoir l'altitude réelle pour un pixel'''
rgbValues=im_alt.getpixel(pixel)
# print("rgbValues = ", rgbValues)
return(getAltitude(rgbValues))
"""# -*- coding: utf-8 -*-
from PIL import Image
import numpy as np
import mpl_toolkits.mplot3d
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
from math import atan, pi
from matplotlib import pyplot
#input_filename_altitude="D:/documents/IMT/datascience/challenge3/moodle/elevation1x1_new-mer-bleue_deforme.bmp"
input_filename_altitude="../moodle/elevation1x1_new-mer-bleue_deforme.bmp"
im_alt = Image.open(input_filename_altitude)
......@@ -40,7 +84,7 @@ def getAltXY(pixel):
'''Permet d'avoir l'altitude réelle pour un pixel'''
rgbValues=im_alt.getpixel(pixel)
# print("rgbValues = ", rgbValues)
return(getAltitude(rgbValues))
return(getAltitude(rgbValues))"""
......@@ -69,8 +113,8 @@ def altCaseXY(case):
def denivele(graphe,case1,case2):
'''Donne le denivelé entre deux cellules du graphe'''
print(case1, case2, 'deux cases')
return(abs(atan((graphe[case1[0]][case1[1]][1]-graphe[case2[0]][case2[1]][1])/15))) #positif
#print(case1, case2, 'deux cases')
return(abs(atan((graphe[case1[0]][case1[1]][1]-graphe[case2[0]][case2[1]][1])/15000))) #positif #Division par 15?
def lambdad(graphe,case1,case2):
......@@ -134,8 +178,7 @@ print(max([max(zi) for zi in z])) """
#A décommenter
newWidth=4830//15
newHeigth=3510//15
graphe=[[[popCaseXY((col,line)),altCaseXY((col,line)),[0 for _ in range(15)]] for col in range(newWidth)] for line in range(newHeigth)]
Graph=[[[popCaseXY((col,line)),altCaseXY((col,line)),[0 for _ in range(15)]] for col in range(newWidth)] for line in range(newHeigth)]
#### initialization of the graph and the zombies list with their age####
......@@ -146,70 +189,98 @@ pixelOutOfRize.append([4433,2109])
pixelOutOfRize.append([[4434,j] for j in range(2105,2110)])
pixelOutOfRize.append([[4435,j] for j in range(2104,2110)])
print(graphe[2103//15][4422//15], 'un de Rize juste avant') # Résultat [182480.5194805195, 1175.629339729832, [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]] Ce qui est logique
#print(Graph[2103//15][4422//15], 'un de Rize juste avant') # Résultat [182480.5194805195, 1175.629339729832, [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]] Ce qui est logique
test=0
for col in range(4422,4436): #pixels de rize
for line in range(2103,2118):
if [col,line] not in pixelOutOfRi44ze:
tmp=graphe[line//15][col//15][0]
graphe[line//15][col//15][2][0]=tmp
graphe[line//15][col//15][0]=0
if graphe[line//15][col//15][2][0] != 0:
print([col,line], graphe[line//15][col//15][0], graphe[line//15][col//15], 'pop avant', [col, line])
"""if graphe[line//15][col//15][0] != 0:
print([col,line], graphe[line//15][col//15][0], 'pop')"""
test+=graphe[line//15][col//15][2][0]
"""[2103, 4422] [182480.5194805195, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] #Ce résultat obtenu dans la boucle ci-dessous est logique lui aussi
[2115, 4422] [229246.75324675324, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
[2130, 4422] [62987.01298701298, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
[2145, 4422] [10480.51948051948, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
[2160, 4422] [15623.376623376624, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
[2175, 4422] [59259.74025974027, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
[2190, 4422] [49623.37662337662, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
[2205, 4422] [15272.727272727274, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
[2103, 4425] [212636.36363636368, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
[2115, 4425] [80363.63636363635, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
[2130, 4425] [40857.142857142855, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
[2145, 4425] [12415.584415584415, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
[2160, 4425] [6948.051948051949, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
[2175, 4425] [26428.57142857143, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
[2190, 4425] [43415.58441558442, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
[2205, 4425] [12194.805194805193, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]"""
if [col,line] not in pixelOutOfRize:
tmp=Graph[line//15][col//15][0]
Graph[line//15][col//15][2][0]=tmp
Graph[line//15][col//15][0]=0
#if Graph[line//15][col//15][2][0] != 0:
#print([col,line], Graph[line//15][col//15][0], Graph[line//15][col//15], 'pop avant', [col, line])
"""if Graph[line//15][col//15][0] != 0:
print([col,line], Graph[line//15][col//15][0], 'pop')"""
test+=Graph[line//15][col//15][2][0]
#On va faire un truc pas beau du tout
graphe[2103//15][4422//15][2][0] = 182480.5194805195
graphe[2115//15][4422//15][2][0] = 229246.75324675324
graphe[2130//15][4422//15][2][0] = 62987.01298701298
graphe[2145//15][4422//15][2][0] = 10480.51948051948
graphe[2160//15][4422//15][2][0] = 15623.376623376624
graphe[2175//15][4422//15][2][0] = 59259.74025974027
graphe[2190//15][4422//15][2][0] = 49623.37662337662
graphe[2205//15][4422//15][2][0] = 15272.727272727274
graphe[2103//15][4425//15][2][0] = 212636.36363636368
graphe[2115//15][4425//15][2][0] = 80363.63636363635
graphe[2130//15][4425//15][2][0] = 40857.142857142855
graphe[2145//15][4425//15][2][0] = 12415.584415584415
graphe[2160//15][4425//15][2][0] = 6948.051948051949
graphe[2175//15][4425//15][2][0] = 26428.57142857143
graphe[2190//15][4425//15][2][0] = 43415.58441558442
graphe[2205//15][4425//15][2][0] = 12194.805194805193
Graph[2103//15][4422//15][2][0] = 182480.5194805195
Graph[2115//15][4422//15][2][0] = 229246.75324675324
Graph[2103//15][4425//15][2][0] = 212636.36363636368
Graph[2115//15][4425//15][2][0] = 80363.63636363635
#Maintenant on a ça dans le graphe à Rize et c'est plus logique
"""[4422, 2103] [0, 1175.629339729832, [182480.5194805195, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]
[4422, 2115] [0, 2725.9298068425705, [229246.75324675324, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]
[4425, 2103] [0, 2334.255775785886, [212636.36363636368, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]
[4425, 2115] [0, 4284.731725792198, [80363.63636363635, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]"""
##
neighborCase1 = neighbors((2103//15, 4422//15),(len(Graph[0]),len(Graph)))
neighborCase2 = neighbors((2115//15, 4422//15),(len(Graph[0]),len(Graph)))
neighborCase3 = neighbors((2103//15, 4425//15),(len(Graph[0]),len(Graph)))
neighborCase4 = neighbors((2115//15, 4425//15),(len(Graph[0]),len(Graph)))
#print(len(neighborCase1), len(neighborCase2), len(neighborCase3), len(neighborCase4), 'len neighbors')
denivCase1 = [Graph[2103//15][4422//15][1]]
denivCase2 = [Graph[2115//15][4422//15][1]]
denivCase3 = [Graph[2103//15][4425//15][1]]
denivCase4 = [Graph[2115//15][4425//15][1]]
for i in neighborCase1:
denivCase1.append((i, lambdad(Graph,(2103//15, 4422//15),i), Graph[i[0]][i[1]][1]))
for i in neighborCase2:
denivCase2.append((i, lambdad(Graph,(2115//15, 4422//15),i), Graph[i[0]][i[1]][1]))
for i in neighborCase3:
denivCase3.append((i, lambdad(Graph,(2103//15, 4425//15),i), Graph[i[0]][i[1]][1]))
for i in neighborCase4:
denivCase4.append((i, lambdad(Graph,(2115//15, 4425//15),i), Graph[i[0]][i[1]][1]))
#print(denivCase1, denivCase2, denivCase3, denivCase4, 'deniv')
##
"""[1175.629339729832, ((139, 294), 0, 0.6072465597778058), ((140, 293), 0, 923.6220174220426), ((139, 293), 0, 0.6072465597778058), ((141, 294), 0, 2725.9298068425705), ((141, 293), 0, 2645.166014392122)]
[2725.9298068425705, ((140, 294), 0, 1175.629339729832), ((141, 293), 0, 2645.166014392122), ((140, 293), 0, 923.6220174220426), ((142, 294), 0, 3061.1299078399193), ((142, 293), 0, 3061.1299078399193)]
[2334.255775785886, ((139, 295), 0, 923.6220174220426), ((140, 294), 0, 1175.629339729832), ((139, 294), 0, 0.6072465597778058), ((141, 295), 0, 4284.731725792198), ((141, 294), 0, 2725.9298068425705)]
[4284.731725792198, ((140, 295), 0, 2334.255775785886), ((141, 294), 0, 2725.9298068425705), ((140, 294), 0, 1175.629339729832), ((142, 295), 0, 4702.517358919328), ((142, 294), 0, 3061.1299078399193)] """
##On bidouille un peu pour voir s'il y a propagation
"""Graph[139][294][1] = 1176
Graph[140][293][1] = 1176
Graph[139][293][1] = 1177
Graph[141][294][1] = 1176
Graph[141][293][1] = 1176
Graph[140][294][1] = 2725
Graph[141][293][1] = 2726"""
print("pop totale de Rize = ", test)
print(graphe[2103//15][4422//15], 'un de Rize avant') # [0, 1175.629339729832, [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]] un de Rize avant pourtant dans le for juste avant on a une liste cohérente
##
#print("pop totale de Rize = ", test)
#print(Graph[2103//15][4422//15], 'un de Rize avant') # [0, 1175.629339729832, [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]] un de Rize avant pourtant dans le for juste avant on a une liste cohérente
#Cellules contenant la population de Rize
pop_totale_de_Rize = 1060233.7662337662
pop_totale_de_Rize = test
print("graphe prêt !")
#print("Graph prêt !")
#On fait viellir les zombies grâce à cette fonction
......@@ -233,7 +304,8 @@ def are_they_zombies(zombies):
def zombies_repartition(zombies, N): #N is the number of zombies that we want to affect to a neighboring cell
repartition = [] #This repartition is done giving the age of the zombies
for i in zombies:
repartition.append((i//sum(zombies))*N)
if sum(zombies) != 0:
repartition.append((i/sum(zombies))*N)
return repartition
......@@ -243,10 +315,13 @@ def enteredZombies(zombiesList):
return sum(zombiesList)
#Before StepOne
print(Graph[88][52], 'Brest')
#STEP ONE
def stepOne(graphe):
def stepOne(Graph):
graphe = Graph.copy()
#Calcul du nombre de zombies partant des cellules
zombiesStart = 0
for i in range(len(graphe)):
......@@ -275,17 +350,19 @@ def stepOne(graphe):
if lambdad(graphe,(i,j),k) != 0:
possible_neighbors.append(k)
lambdab_possible_neighbors.append(lambdad(graphe,(i,j),k)) #On est en possession des voisins contaminables et des coefficients correspondants
print(len(lambdab_possible_neighbors), 'contaminables')
#print(len(lambdab_possible_neighbors), 'contaminables')
for k in range(len(possible_neighbors)): #We compute the number of zombies going to a neighboring cell
N = ((graphe[possible_neighbors[k][0]][possible_neighbors[k][1]][0])/neighbors_population)*lambdab_possible_neighbors[k]*graphe_memory[(i,j)]
if neighbors_population != 0:
N = ((graphe[possible_neighbors[k][0]][possible_neighbors[k][1]][0])/neighbors_population)*lambdab_possible_neighbors[k]*graphe_memory[(i,j)]
else:
N = 0
#From now on we can distribute the zombies on the possible neighboring cells
#On va repartir les zombies par rapport à leur quantité par groupes d'âges
repartition = zombies_repartition(graphe[i][j][2], N)
print(repartition, 'repartition', N, 'pop init',graphe_memory[(i,j)])
#print(repartition, 'repartition', N, 'pop init',graphe_memory[(i,j)])
#Ensuite on ajoute les nouveaux zombies dans la cellule en question
#En supposant que les zombies ne disparaissent pas juste, on retire de la cellule actuelle les zombies qui partent dans cellules voisines
......@@ -306,12 +383,13 @@ def stepOne(graphe):
for j in range(len(graphe[i])):
zombiesEnd = zombiesEnd + sum(graphe[i][j][2])
print(zombiesStart, zombiesEnd, 'start end') #C'est juste pour vérifier qu'on a bien la même chose
#print(zombiesStart, zombiesEnd, 'start end') #C'est juste pour vérifier qu'on a bien la même chose
return graphe
#STEP TWO
def stepTwo(graphe):
def stepTwo(Graph):
graphe = Graph.copy()
#Calcul de la population initiale (zombies et humains)
zombiesHumainStart = 0
for i in range(len(graphe)):
......@@ -337,13 +415,14 @@ def stepTwo(graphe):
for i in range(len(graphe)):
for j in range(len(graphe[i])):
zombiesHumainEnd = zombiesHumainEnd + sum(graphe[i][j][2]) + graphe[i][j][0]
print(zombiesHumainStart, zombiesHumainEnd, 'pop init fin step 2') #Entre 0 et 15 jours on doit avoir la même chose
#print(zombiesHumainStart, zombiesHumainEnd, 'pop init fin step 2') #Entre 0 et 15 jours on doit avoir la même chose
return updatedGraph
#STEP THREE
def stepThree(graphe):
def stepThree(Graph):
graphe = Graph.copy()
#Calcul de la population initiale
zombiesHumainStart = 0
for i in range(len(graphe)):
......@@ -366,10 +445,22 @@ def stepThree(graphe):
for i in range(len(graphe)):
for j in range(len(graphe[i])):
zombiesHumainEnd = zombiesHumainEnd + sum(graphe[i][j][2]) + graphe[i][j][0]
print(zombiesHumainStart, zombiesHumainEnd, 'pop init fin step 3')
#print(zombiesHumainStart, zombiesHumainEnd, 'pop init fin step 3')
return updatedGraph
#20 Itérations
print(stepThree(graphe)[2103//15][4422//15])
for i in range(500):
print(stepThree(Graph)[88][52], len(Graph), len(Graph[0]))
print('Jour', i+1, 'terminé!')
print(Graph[2103//15:229])
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment