Commit 104aaf6e authored by Jéhoiakim KINGNE's avatar Jéhoiakim KINGNE
Browse files

Push

parent 28bfed64
......@@ -7,6 +7,7 @@ import matplotlib.pyplot as plt
from math import atan, pi
from matplotlib import pyplot
import csv
import matplotlib as mpl
#input_filename_altitude="D:/documents/IMT/datascience/challenge3/moodle/altitude-map.bmp"
......@@ -121,12 +122,12 @@ def neighbors(node, size):
print("alt = ",altCaseXY((4435//15,2214//15)))
print("pop = ",popCaseXY((4435//15,2214//15)))
def exportgraphe(graphe):
def exportgraphe(graphe, i):
"""Fonction permettant de transformer le graphe en un fichier csv"""
flat=[]
for line in graphe:
flat+=line
with open("../moodle/graphe60jours.csv", 'a') as outcsv:
with open("../moodleBis/graphe"+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:
......@@ -134,9 +135,8 @@ def exportgraphe(graphe):
writer.writerow([item[0], item[1], item[2][0], item[2][1], item[2][2], item[2][3], item[2][4], item[2][5], item[2][6], item[2][7], item[2][8], item[2][9], item[2][10], item[2][11], item[2][12], item[2][13], item[2][14]])
def importgraphe(nbline,nbcol):
"""Fonction permettant de récupérer un fichier csv et de le transformer en graphe"""
with open("../moodle/graphe60jours.csv",newline='') as f:
def importgraphe(nbline,nbcol, i):
with open("../moodleBis/graphe"+str(i)+"jours.csv",newline='') as f:
reader = csv.reader(f,delimiter=',')
uidlist = list(reader)
res=[[[] for _ in range(nbcol)] for _ in range(nbline)]
......@@ -148,6 +148,13 @@ def importgraphe(nbline,nbcol):
compteur+=1
return(res)
def isZombie(case):
res=1
if case[0]==0:
res=0.5
if sum(case[2])!=0:
res=0
return(res)
""" x=range(4830)
y=range(3510)
......@@ -160,6 +167,7 @@ print(max([max(zi) for zi in z])) """
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)),0,[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####
......@@ -285,7 +293,9 @@ def enteredZombies(zombiesList):
#Before StepOne
print(Graph[88][52], 'Brest')
print(Graph[146][295], 'Où')
print(neighbors((146, 295),(len(Graph[0]),len(Graph))), (146,295))
print(neighbors((147, 296),(len(Graph[0]),len(Graph))), (147,296))
#STEP ONE
def stepOne(Graph):
......@@ -311,7 +321,7 @@ def stepOne(Graph):
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
possible_neighbors = [] #Cette liste ne contiendra uniquement les voisins succeptibles d'être contaminés
lambdab_possible_neighbors = []
for k in neighbor:
......@@ -319,6 +329,8 @@ def stepOne(Graph):
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')
if (i,j) == (146,295):
print(neighbor, lambdab_possible_neighbors, neighbors_population, (146,295))
for k in range(len(possible_neighbors)): #We compute the number of zombies going to a neighboring cell
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)]
......@@ -418,16 +430,29 @@ def stepThree(Graph):
#Itérations
#(146,295)
gr = stepThree(Graph)
"""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]
fig, ax = plt.subplots()
# define the colors
cmap = mpl.colors.ListedColormap(['b', 'g', 'r', 'c', 'm', 'y', 'k', 'w'])
# create a normalize object the describes the limits of
# each color
bounds = [0., 0.2, 0.7, 1.]
norm = mpl.colors.BoundaryNorm(bounds, cmap.N)
# plot it
ax.imshow(x, interpolation='none', cmap=cmap, norm=norm)
plt.savefig('../moodleBis/test'+str(i)+'.png')
print('Jour', i+1, 'terminé!')"""
"""for i in range(60):
print(stepThree(Graph)[87][43], len(Graph), len(Graph[0]))
print('Jour', i+1, 'terminé!')
if i == 59:
exportgraphe(Graph) """
#Graphe à 60 jours
graphe60jours=importgraphe(3510//15, 4830//15)
a = stepThree(graphe60jours)
print('bon')
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