Commit a37ab7a1 authored by Grégoire PETIT's avatar Grégoire PETIT
Browse files

bizarre

parents 6763b28e 38cf2208
......@@ -8,12 +8,9 @@ from math import atan, pi
from matplotlib import pyplot
#input_filename_altitude="../moodle/elevation1x1_new-mer-bleue_deforme.bmp"
input_filename_altitude="c:/Users/Floyd Warshall/Documents/IMT/UV/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)
#input_filename_poputation="../moodle/population-density-map.bmp"
input_filename_poputation="c:/Users/Floyd Warshall/Documents/IMT/UV/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
......@@ -64,7 +61,8 @@ def altCaseXY(case):#Permet d'avoir l'altitude moyenne réelle d'une cellule (do
#### from now on, the functions deal with the graph with cells of 15*15 pixels ####
def denivele(graphe,case1,case2): #Donne le denivelé entre deux cellules du graphe
return(abs(atan((graphe[case1[0]][case1[1]]-graphe[case2[0]][case2[1]])/15))) #positif
print(case1, case2, 'deux cases')
return(abs(atan((graphe[case1[0]][case1[1]][1]-graphe[case2[0]][case2[1]][1])/15))) #positif
def lambdad(graphe,case1,case2):
......@@ -87,6 +85,29 @@ def voisins(graphe,x,y):
flat.append(point)
return(flat)
def neighbors(node, height):
#height represent the whole size of the image
my_neighbors =[]
x,y = node[0],node[1]
if x-1>=0:
my_neighbors.append((x-1,y))
if y-1>=0:
my_neighbors.append((x,y-1))
if x-1>=0 and y-1>=0:
my_neighbors.append((x-1,y-1))
if x+1<height[0]:
my_neighbors.append((x+1,y))
if y+1<height[1]:
my_neighbors.append((x,y+1))
if x+1<height[0] and y+1<height[1]:
my_neighbors.append((x+1,y+1))
if x+1<height[0] and y-1>=0:
my_neighbors.append((x+1,y-1))
if y+1<height[1] and x-1>=0:
my_neighbors.append((x-1,y+1))
return my_neighbors
print("alt = ",altCaseXY((1560,1590)))
print("pop = ",popCaseXY((1560,1590)))
......@@ -107,7 +128,7 @@ graphe=[[[popCaseXY((i*15,j*15)),altCaseXY((i*15,j*15)),[0 for _ in range(15)]]
#### initialization of the graph ####
#### initialization of the graph and the zombies list with their age####
pixelOutOfRize=[[4422,2108],[4422,2109],[4422,2110],[4422,2111],[4423,2109],[4423,2110],[4423,2111],[4424,2110],[4425,2111]]
pixelOutOfRize.append([[i,2111] for i in range(4429,4436)])
pixelOutOfRize.append([[i,2110] for i in range(4430,4436)])
......@@ -119,24 +140,81 @@ for i in range(4422,4436): #pixels de rize
for j in range(2103,2218):
if [i,j] not in pixelOutOfRize:
graphe[j//15][i//15][0]+=(-getPopXY((i,j)))
graphe[j//15][i//15][0]+=getPopXY((i,j))
graphe[j//15][i//15][2][0]=getPopXY((i,j))
print(len(graphe), 'taille graphe')
def getZombiesOlder(listZombies):
for i in range(15):
listZombies[14-i]=listZombies[13-i]
listZombies[0]=0
print(neighbors((2128//15, 4434//15),(heigth,width)))
#Exemple de cellule à Rize : (4435, 2150), (4434, 2128)
#On fait viellir les zombies grâce à cette fonction
def getZombiesOlder(zombiesList):
for i in range(15):
zombiesList[14-i]=zombiesList[13-i]
zombiesList[0]=0
#Sera utile pour vérifier si oui ou non une cellule contient des zombies : prend en paramètre la liste du nombre de zombies d'une cellule classés par âge
def are_they_zombies(zombies):
boolean = 0
for i in zombies:
if i!= 0:
boolean = 1
return boolean
"""def getGraphOlder(graphe):
for i in range(newWidth):
for j in range(newHeigth):"""
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)
return repartition
#STEP ONE
def stepOne(graphe):
#On parcourt la liste de toutes les cellules et on regarde pour chacune d'elle s'il y a des zombies si oui on les répartis dans les cellules voisines
for i in range(len(graphe)):
for j in range(len(graphe[i])):
if are_they_zombies(graphe[i][j][2]) == 1: #Cela signifie qu'on a bien des zombies dans cette cellule
neighbor = neighbors((i, j),(len(graphe[0]),len(graphe))) #On récupère les cellules voisines
neighbors_population = 0
for n in neighbor:
neighbors_population += graphe[n[0]][n[1]][0] #On récupère la population totale de nos voisins
possible_neighbors = [] #Cette liste ne contiendra uniquement les voisins succeptibles d'être contaminés
lambdab_possible_neighbors = []
for k in neighbor:
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
for k in possible_neighbors: #We compute the number of zombies going to a neighboring cell
N = ((graphe[k[0]][k[1]][0])/neighbors_population)*lambdab_possible_neighbors[k]
#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)
#Ensuite on ajoute les nouveaux zombies dans la cellule en question
for ind in range(len(repartition)):
graphe[k[0]][k[1]][2][ind] = graphe[k[0]][k[1]][2][ind] + repartition[ind]
#Après ça on fait vieillir tout le monde
return 'Game Over'
print(stepOne(graphe), 'Game Over')
#def stepOne(graphe):
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