diff --git a/bin/generate.py b/bin/generate.py new file mode 100644 index 0000000..dbc4a4f --- /dev/null +++ b/bin/generate.py @@ -0,0 +1,25 @@ +import matplotlib.pyplot as plt +import csv +data = [] +with open('output.csv',newline='') as csvfile: + spamreader = csv.reader(csvfile,delimiter=',') + for row in spamreader: + data.append(row) +def getcolumn(data,col,start = 0): + column = [] + for i in range(start,len(data)): + column.append(float(data[i][col])) + return column + +X,S,I,E,N,R,D = getcolumn(data,0,1),getcolumn(data,1,1),getcolumn(data,2,1),getcolumn(data,3,1),getcolumn(data,4,1),getcolumn(data,5,1),getcolumn(data,6,1) +plt.plot(X,S,label="Sains") +plt.plot(X,I,label="Infectés") +plt.plot(X,E,label="Incubation") +plt.plot(X,R,label="Réémis") +plt.plot(X,D,label="Morts") +plt.plot(X,N,label="Population") +plt.legend(loc="upper right") +plt.xlabel("Jours") +plt.ylabel("Part de la population") +plt.show() + diff --git a/bin/simulation_sir b/bin/simulation_sir new file mode 100644 index 0000000..67238c1 Binary files /dev/null and b/bin/simulation_sir differ diff --git a/img/diag2.png b/img/diag2.png new file mode 100644 index 0000000..5520a58 Binary files /dev/null and b/img/diag2.png differ diff --git a/source/generate.py b/source/generate.py new file mode 100644 index 0000000..4545320 --- /dev/null +++ b/source/generate.py @@ -0,0 +1,25 @@ +import matplotlib.pyplot as plt +import csv +data = [] +with open('output.csv',newline='') as csvfile: + spamreader = csv.reader(csvfile,delimiter=',') + for row in spamreader: + data.append(row) +def getcolumn(data,col,start = 0): + column = [] + for i in range(start,len(data)): + column.append(float(data[i][col])) + return column + +X,S,I,E,N,R,D = getcolumn(data,0,1),getcolumn(data,1,1),getcolumn(data,2,1),getcolumn(data,3,1),getcolumn(data,4,1),getcolumn(data,5,1),getcolumn(data,6,1) +plt.plot(X,S,label="Healthy") +plt.plot(X,I,label="Infected") +plt.plot(X,E,label="Exposed") +plt.plot(X,R,label="Recovered") +plt.plot(X,D,label="Deceased") +plt.plot(X,N,label="Population") +plt.legend(loc="upper right") +plt.xlabel("Days") +plt.ylabel("Percentage of population") +plt.show() + diff --git a/source/model.c b/source/model.c new file mode 100644 index 0000000..9ee47af --- /dev/null +++ b/source/model.c @@ -0,0 +1,138 @@ +#include +#include + +typedef struct Description Description; +struct Description{ + long double Sains; + long double Incubation; + long double Infectes; + long double Immunises; + long double Morts; + long double beta; + long double gamma; + long double alpha; + long double mu; + long double nu; + long double delta; + long double epsilon; +}; + +long double yn(long double y, long double h,long double (*f)(Description d),Description d){ + long double result = y+h*(*f)(d); + return result; +} +long double N(Description d){ + return d.Sains+d.Incubation+d.Infectes+d.Immunises; +} +long double dS(Description d){ + return d.nu*N(d)-d.beta*d.Sains*d.Infectes-d.mu*d.Sains+d.epsilon*d.Immunises; +} +long double dE(Description d){ + return d.beta*d.Sains*d.Infectes-d.alpha*d.Incubation-d.mu*d.Incubation; +} +long double dI(Description d){ + return d.alpha*d.Incubation - d.delta*d.Infectes - d.gamma*d.Infectes -d.mu*d.Infectes; +} +long double dR(Description d){ + return d.gamma*d.Infectes - d.mu*d.Immunises-d.epsilon*d.Immunises; +} +long double dD(Description d){ + long double morts = d.delta*d.Infectes; + return morts; +} + +void modele(long double sains0,long double incubation0,long double infectes0, long double alpha,long double beta, long double gamma, long double delta, long double epsilon,long double mu, long double nu,long double duree,long double points){ + printf("Sains %Lf\nIncubation :%Lf\ninfectés : %Lf\nalpha : %Lf\nbeta : %Lf\ngamma : %Lf\ndelta %Lf\nmu : %Lf\nnu : %Lf\nduree : %Lf\npoints : %Lf\n",sains0,incubation0,infectes0,alpha,beta,gamma,delta,mu,nu,duree,points); + Description systeme = {.Sains = sains0,.Incubation = incubation0, .Infectes = infectes0, .Morts = 0,.Immunises = 0, .alpha = alpha,.beta=beta,.gamma=gamma,.delta=delta,.nu = nu,.mu = mu,.epsilon = epsilon}; + long double* S = NULL; + long double* I = NULL; + long double* E = NULL; + long double* Nt = NULL; + long double* R = NULL; + long double* D = NULL; + long double* X = NULL; + S = malloc(points*sizeof(long double)); + I = malloc(points*sizeof(long double)); + E = malloc(points*sizeof(long double)); + Nt = malloc(points*sizeof(long double)); + R = malloc(points*sizeof(long double)); + D = malloc(points*sizeof(long double)); + X = malloc(points*sizeof(long double)); + + if (S==NULL||I==NULL||E==NULL||Nt==NULL||R==NULL||D==NULL||X==NULL){ + printf("Erreur d'allocation"); + exit(0); + } + S[0] = systeme.Sains; + I[0] = systeme.Infectes; + E[0] = systeme.Incubation; + Nt[0] = N(systeme); + R[0] = systeme.Immunises; + D[0] = systeme.Morts; + X[0] = 0; + unsigned long i = 0; + long double sains = 0; + long double infectes = 0; + long double incubation = 0; + long double n = 0; + long double immunises = 0; + long double morts = 0; + long double h = duree/points; + for(i = 1;i