Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Grégoire PETIT
DataScience
Commits
cee8db70
Commit
cee8db70
authored
Dec 02, 2018
by
Jéhoiakim KINGNE
Browse files
commit
parent
b63aa303
Changes
1
Hide whitespace changes
Inline
Side-by-side
Challenge3/code/challenge3.py
View file @
cee8db70
...
...
@@ -8,12 +8,12 @@ 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"
#
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
)
input_filename_poputation
=
"D:/documents/IMT/datascience/challenge3/moodle/population-density-map.bmp"
#
input_filename_poputation="../moodle/population-density-map.bmp"
#
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
...
...
@@ -80,6 +80,9 @@ def lambdad(graphe,case1,case2):
res
=
(
pi
/
9
-
d
)
*
9
/
pi
return
(
res
)
def
voisins
(
graphe
,
x
,
y
):
'''graphe représente notre graphe sous la forme [[ ,[pop,alt], , ],...,[ , , , ]]'''
...
...
@@ -128,7 +131,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
)]
...
...
@@ -143,19 +146,67 @@ 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
test
=
0
for
col
in
range
(
4422
,
4436
):
#pixels de rize
for
line
in
range
(
2103
,
2218
):
if
[
col
,
line
]
not
in
pixelOutOfRize
:
print
([
col
,
line
],
'pixel de Rize'
)
graphe
[
line
//
15
][
col
//
15
][
2
][
0
]
=
graphe
[
line
//
15
][
col
//
15
][
0
]
graphe
[
line
//
15
][
col
//
15
][
0
]
=
0
if
graphe
[
line
//
15
][
col
//
15
][
0
]
!=
0
:
print
([
col
,
line
],
graphe
[
line
//
15
][
col
//
15
][
0
],
'pop'
)
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]"""
#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
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
#Cellules contenant la population de Rize
pop_totale_de_Rize
=
1060233.7662337662
print
(
"graphe prêt !"
)
...
...
@@ -195,14 +246,27 @@ def enteredZombies(zombiesList):
#STEP ONE
def
stepOne
(
graphe
):
#Calcul du nombre de zombies partant des cellules
zombiesStart
=
0
for
i
in
range
(
len
(
graphe
)):
for
j
in
range
(
len
(
graphe
[
i
])):
zombiesStart
=
zombiesStart
+
sum
(
graphe
[
i
][
j
][
2
])
#Ici comme je ne peux pas faire une copie sans modifier la liste ensuite je suis obligé de faire un petit dico ce qui est un peu dommage
#graphe_memory = graphe.copy()
graphe_memory
=
{}
for
i
in
range
(
len
(
graphe
)):
for
j
in
range
(
len
(
graphe
[
i
])):
graphe_memory
[(
i
,
j
)]
=
sum
(
graphe
[
i
][
j
][
2
])
#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
])):
#print((i,j), 'noeud en question')
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
neighbors_population
=
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
=
[]
...
...
@@ -210,33 +274,54 @@ 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
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
]
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
)]
#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
)])
#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
for
ind
in
range
(
len
(
repartition
)):
graphe
[
k
[
0
]][
k
[
1
]][
2
][
ind
]
=
graphe
[
k
[
0
]][
k
[
1
]][
2
][
ind
]
+
repartition
[
ind
]
graphe
[
possible_neighbors
[
k
][
0
]][
possible_neighbors
[
k
][
1
]][
2
][
ind
]
=
graphe
[
possible_neighbors
[
k
][
0
]][
possible_neighbors
[
k
][
1
]][
2
][
ind
]
+
repartition
[
ind
]
graphe
[
i
][
j
][
2
][
ind
]
=
graphe
[
i
][
j
][
2
][
ind
]
-
repartition
[
ind
]
#Maintenant on fait vieillir tout le monde
for
i
in
range
(
len
(
graphe
)):
for
j
in
range
(
len
(
graphe
[
i
])):
getZombiesOlder
(
graphe
[
i
][
j
][
2
])
#Calcul du nombre de zombies arrivés dans les cellules
zombiesEnd
=
0
for
i
in
range
(
len
(
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
return
graphe
#STEP TWO
def
stepTwo
(
graphe
):
#Calcul de la population initiale (zombies et humains)
zombiesHumainStart
=
0
for
i
in
range
(
len
(
graphe
)):
for
j
in
range
(
len
(
graphe
[
i
])):
zombiesHumainStart
=
zombiesHumainStart
+
sum
(
graphe
[
i
][
j
][
2
])
+
graphe
[
i
][
j
][
0
]
updatedGraph
=
stepOne
(
graphe
)
for
i
in
range
(
len
(
updatedGraph
)):
for
j
in
range
(
len
(
updatedGraph
[
i
])):
potentialKilledHuman
=
10
*
enteredZombies
(
updatedGraph
[
i
][
j
][
2
])
#Nombre d'humains potentiels qui seront tués
if
potentialKilledHuman
>=
updatedGraph
[
i
][
j
][
0
]:
#Si on a moins d'humains que le nombre potentiel à détruire alors ils sont tous tués
potentialKilledHuman
=
10
*
enteredZombies
(
updatedGraph
[
i
][
j
][
2
])
#Nombre d'humains potentiels qui seront tués
#print(potentialKilledHuman, enteredZombies(updatedGraph[i][j][2]))
if
potentialKilledHuman
>=
updatedGraph
[
i
][
j
][
0
]:
#Si on a moins d'humains que le nombre potentiel à détruire alors ils sont tous tués
newZombies
=
updatedGraph
[
i
][
j
][
0
]
#Et on la transforme en zombies
updatedGraph
[
i
][
j
][
2
][
0
]
=
newZombies
#Ils sont tous agés de 0 jour (ces nouveaux zombies).
updatedGraph
[
i
][
j
][
0
]
=
0
#L'ancienne population est détruite
...
...
@@ -245,12 +330,24 @@ def stepTwo(graphe):
newZombies
=
potentialKilledHuman
updatedGraph
[
i
][
j
][
2
][
0
]
=
newZombies
updatedGraph
[
i
][
j
][
0
]
=
updatedGraph
[
i
][
j
][
0
]
-
potentialKilledHuman
#Calcul de la population finale
zombiesHumainEnd
=
0
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
return
updatedGraph
#STEP THREE
def
stepThree
(
graphe
):
#Calcul de la population initiale
zombiesHumainStart
=
0
for
i
in
range
(
len
(
graphe
)):
for
j
in
range
(
len
(
graphe
[
i
])):
zombiesHumainStart
=
zombiesHumainStart
+
sum
(
graphe
[
i
][
j
][
2
])
+
graphe
[
i
][
j
][
0
]
updatedGraph
=
stepTwo
(
graphe
)
for
i
in
range
(
len
(
updatedGraph
)):
for
j
in
range
(
len
(
updatedGraph
[
i
])):
...
...
@@ -260,33 +357,18 @@ def stepThree(graphe):
if
potentialKilledZombies
<
enteredZombies
(
updatedGraph
[
i
][
j
][
2
]):
#Si on a plus de zombies que le nombre potentiel à tuer on conserve une partie
#On va répartir les zombies à tuer selon la quantité présente par tranche d'âge
killedZombiesRepartition
=
zombies_repartition
(
updatedGraph
[
i
][
j
][
2
],
potentialKilledZombies
)
for
i
in
range
(
len
(
updatedGraph
[
i
][
j
][
2
])):
updatedGraph
[
i
][
j
][
2
][
i
]
=
updatedGraph
[
i
][
j
][
2
][
i
]
-
killedZombiesRepartition
[
i
]
#On retire les zombies à tuer et on conserve le reste
for
p
in
range
(
len
(
updatedGraph
[
i
][
j
][
2
])):
updatedGraph
[
i
][
j
][
2
][
p
]
=
updatedGraph
[
i
][
j
][
2
][
p
]
-
killedZombiesRepartition
[
p
]
#On retire les zombies à tuer et on conserve le reste
#Calcul de la population finale
zombiesHumainEnd
=
0
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'
)
return
updatedGraph
updatedGraph
=
stepThree
(
graphe
)
print
(
updatedGraph
[
2214
//
15
][
4435
//
15
],
updatedGraph
[
2215
//
15
][
4435
//
15
],
'Rize après un jour'
)
#20 Itérations
'''updatedGraph = graphe
for k in range(500):
updatedGraph = stepThree(updatedGraph)
print(updatedGraph)'''
#20 Itérations
print
(
stepThree
(
graphe
)[
2103
//
15
][
4422
//
15
])
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment