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
141bc684
Commit
141bc684
authored
Dec 06, 2018
by
Grégoire PETIT
Browse files
bon, j'ai autre chose à faire ciao
parent
c61e52f0
Changes
4
Expand all
Hide whitespace changes
Inline
Side-by-side
Challenge3/code/challenge3.py
View file @
141bc684
...
...
@@ -10,12 +10,12 @@ import csv
import
matplotlib
as
mpl
#
input_filename_altitude="D:/documents/IMT/datascience/challenge3/moodle/altitude-map.bmp"
input_filename_altitude
=
"../moodle/altitude-map.bmp"
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"
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
)
...
...
@@ -80,44 +80,19 @@ def lambdad(graphe,case1,case2):
return
(
res
)
def
neighbors
(
node
,
size
):
#size represent the whole size of the image
def
voisins
(
graphe
,
x
,
y
):
'''graphe représente notre graphe sous la forme [[ ,[pop,alt], , ],...,[ , , , ]]'''
longueur
,
largeur
=
size
x
,
y
=
node
[
0
],
node
[
1
]
res
=
[[[
xi
,
yi
]
for
xi
in
range
(
x
-
1
,
x
+
2
)]
for
yi
in
range
(
y
-
1
,
y
+
2
)]
largeur
=
len
(
graphe
[
0
])
longueur
=
len
(
graphe
)
flat
=
[]
for
ligne
in
res
:
for
point
in
ligne
:
if
(
point
[
0
]
>=
0
)
&
(
point
[
0
]
<=
largeur
-
1
)
&
(
point
[
1
]
>=
0
)
&
(
point
[
1
]
<=
longueur
-
1
)
&
([
x
,
y
]
!=
point
)
&
(
graphe
[
point
[
0
]][
point
[
1
]]
!=-
1
)
&
(
graphe
[
point
[
0
]][
point
[
1
]]
<=
50
)
:
if
(
point
[
0
]
>=
0
)
&
(
point
[
0
]
<=
largeur
-
1
)
&
(
point
[
1
]
>=
0
)
&
(
point
[
1
]
<=
longueur
-
1
)
&
([
x
,
y
]
!=
point
):
flat
.
append
(
point
)
return
(
flat
)
def
neighbors
(
node
,
size
):
#size 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
<
size
[
0
]:
my_neighbors
.
append
((
x
+
1
,
y
))
if
y
+
1
<
size
[
1
]:
my_neighbors
.
append
((
x
,
y
+
1
))
if
x
+
1
<
size
[
0
]
and
y
+
1
<
size
[
1
]:
my_neighbors
.
append
((
x
+
1
,
y
+
1
))
if
x
+
1
<
size
[
0
]
and
y
-
1
>=
0
:
my_neighbors
.
append
((
x
+
1
,
y
-
1
))
if
y
+
1
<
size
[
1
]
and
x
-
1
>=
0
:
my_neighbors
.
append
((
x
-
1
,
y
+
1
))
return
my_neighbors
print
(
"alt = "
,
altCaseXY
((
4435
//
15
,
2214
//
15
)))
print
(
"pop = "
,
popCaseXY
((
4435
//
15
,
2214
//
15
)))
...
...
@@ -127,7 +102,7 @@ def exportgraphe(graphe, i):
flat
=
[]
for
line
in
graphe
:
flat
+=
line
with
open
(
"
../moodleBis/graphe
"
+
str
(
i
)
+
"jours.csv"
,
'a'
)
as
outcsv
:
with
open
(
"
D:/documents/IMT/datascience/challenge3/sauvegarde/
"
+
str
(
i
)
+
"jours.csv"
,
'a'
)
as
outcsv
:
#configure writer to write standard csv file
writer
=
csv
.
writer
(
outcsv
,
delimiter
=
','
,
quotechar
=
'|'
,
quoting
=
csv
.
QUOTE_MINIMAL
,
lineterminator
=
'
\n
'
)
for
item
in
flat
:
...
...
@@ -136,7 +111,7 @@ def exportgraphe(graphe, i):
def
importgraphe
(
nbline
,
nbcol
,
i
):
with
open
(
"
../moodleBis/graphe
"
+
str
(
i
)
+
"jours.csv"
,
newline
=
''
)
as
f
:
with
open
(
"
D:/documents/IMT/datascience/challenge3/sauvegarde/
"
+
str
(
i
)
+
"jours.csv"
,
newline
=
''
)
as
f
:
reader
=
csv
.
reader
(
f
,
delimiter
=
','
)
uidlist
=
list
(
reader
)
res
=
[[[]
for
_
in
range
(
nbcol
)]
for
_
in
range
(
nbline
)]
...
...
@@ -161,14 +136,27 @@ y=range(3510)
z=[[getAltXY((xi,yi)) for xi in x] for yi in y] #profil de l'altitude de la ligne du mont blanc (il est à x=1573)
print(max([max(zi) for zi in z])) """
#A décommenter
newWidth
=
4830
//
15
newHeigth
=
3510
//
15
Graph
=
[[[
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)]
#exportgraphe(Graph)
#Graph=[[[popCaseXY((col,line)),0,[0 for _ in range(15)]] for col in range(newWidth)] for line in range(newHeigth)]
def
importgrapheinitial
(
nbline
,
nbcol
):
with
open
(
"D:/documents/IMT/datascience/challenge3/sauvegarde/grapheinitial.csv"
,
newline
=
''
)
as
f
:
reader
=
csv
.
reader
(
f
,
delimiter
=
','
)
uidlist
=
list
(
reader
)
res
=
[[[]
for
_
in
range
(
nbcol
)]
for
_
in
range
(
nbline
)]
compteur
=
0
for
line
in
uidlist
:
res
[
compteur
%
nbline
][
compteur
//
nbline
].
append
(
float
(
line
[
0
]))
res
[
compteur
%
nbline
][
compteur
//
nbline
].
append
(
float
(
line
[
1
]))
res
[
compteur
%
nbline
][
compteur
//
nbline
].
append
([
float
(
elt
)
for
elt
in
line
[
2
:]])
compteur
+=
1
return
(
res
)
nbline
,
nbcol
=
234
,
322
Graph
=
importgrapheinitial
(
nbline
,
nbcol
)[::
-
1
]
#### 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
]]
...
...
@@ -302,6 +290,7 @@ def stepOne(Graph):
graphe
=
Graph
.
copy
()
#Calcul du nombre de zombies partant des cellules
zombiesStart
=
0
larglong
=
(
len
(
graphe
[
0
]),
len
(
graphe
))
for
i
in
range
(
len
(
graphe
)):
for
j
in
range
(
len
(
graphe
[
i
])):
zombiesStart
=
zombiesStart
+
sum
(
graphe
[
i
][
j
][
2
])
...
...
@@ -317,7 +306,7 @@ def stepOne(Graph):
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
neighbor
=
neighbors
((
i
,
j
),
larglong
)
#On récupère les cellules voisines
neighbors_population
=
0
for
n
in
neighbor
:
neighbors_population
=
neighbors_population
+
graphe
[
n
[
0
]][
n
[
1
]][
0
]
#On récupère la population totale de nos voisins
...
...
@@ -432,13 +421,18 @@ def stepThree(Graph):
#Itérations
#(146,295)
gr
=
stepThree
(
Graph
)
"""
for i in range(300):
for
i
in
range
(
300
):
graphe
=
stepThree
(
Graph
)
nbline
,
nbcol
=
322
,
234
#graphetest=importgraphe(nbline,nbcol, i)[::-1]
x = [[isZombie(case) for case in line] for line in graphe]
exportgraphe
(
graphe
,
i
)
graphetoplot
=
importgraphe
(
nbline
,
nbcol
,
i
)[::
-
1
]
x
=
[[
isZombie
(
case
)
for
case
in
line
]
for
line
in
graphetoplot
]
soldats
=
[[
231
,
139
],[
231
,
140
],[
231
,
141
],[
222
,
143
],[
221
,
143
],[
220
,
143
],[
219
,
143
],[
218
,
143
],[
217
,
143
],[
216
,
143
]]
for
point
in
soldats
:
x
[
321
-
point
[
0
]][
point
[
1
]]
=
0.8
fig
,
ax
=
plt
.
subplots
()
# define the colors
cmap
=
mpl
.
colors
.
ListedColormap
([
'b'
,
'g'
,
'r'
,
'c'
,
'm'
,
'y'
,
'k'
,
'w'
])
...
...
@@ -449,10 +443,8 @@ gr = stepThree(Graph)
# plot it
ax
.
imshow
(
x
,
interpolation
=
'none'
,
cmap
=
cmap
,
norm
=
norm
)
plt.savefig('
../moodleBis
/test'+str(i)+'.png')
print('Jour', i+1, 'terminé!')
"""
plt
.
savefig
(
'
D:/documents/IMT/datascience/challenge3/sauvegarde
/test'
+
str
(
i
)
+
'.png'
)
print
(
'Jour'
,
i
+
1
,
'terminé!'
)
Challenge3/code/svg.csv
deleted
100644 → 0
View file @
c61e52f0
This diff is collapsed.
Click to expand it.
Challenge3/moodle/graphe.csv
deleted
100644 → 0
View file @
c61e52f0
1,2,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4
7,8,10,11,121,13,14,15,61,7,181,191,101,111,121,131,14
Challenge3/sauvegarde/grapheinitial.csv
0 → 100644
View file @
141bc684
This diff is collapsed.
Click to expand it.
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