reffactoring for more test
This commit is contained in:
@@ -1,22 +1,82 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
#include "rabbit_hole.h"
|
#include "rabbit_hole.h"
|
||||||
#include "mt19937ar.h"
|
#include "mt19937ar.h"
|
||||||
|
|
||||||
int main(void) {
|
#define N_DRAW (10000)
|
||||||
init_genrand(42);
|
|
||||||
printf("===========Rabbit Hole Simulation =============\n");
|
/* Mode run : init 10 males / 10 femelles matures, simulation sur 80 ans. */
|
||||||
|
static void run_mode(void) {
|
||||||
rabbit_hole_t rabbits;
|
rabbit_hole_t rabbits;
|
||||||
init_rabbits(&rabbits);
|
init_rabbits(&rabbits);
|
||||||
rabbits.male_mature[0] = 10;
|
rabbits.male_mature[0] = 10;
|
||||||
rabbits.female_mature[0] = 10;
|
rabbits.female_mature[0] = 10;
|
||||||
__uint128_t month = 0;
|
__uint128_t month = 0;
|
||||||
print_rabbits(&rabbits,&month);
|
|
||||||
csv_header();
|
csv_header();
|
||||||
|
|
||||||
for (int j = 0; j < 12*80; j++) {
|
for (int j = 0; j < 12*80; j++) {
|
||||||
if (!process_month(&rabbits,&month))
|
if (!process_month(&rabbits,&month))
|
||||||
break;
|
break;
|
||||||
print_rabbits(&rabbits,&month);
|
//print_rabbits(&rabbits,&month);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Mode stats : 10000 tirages, init 1 male / 1 femelle, 10 ans chacun. */
|
||||||
|
static void stats_mode(void) {
|
||||||
|
rabbit_hole_t rabbits;
|
||||||
|
__uint128_t month = 0;
|
||||||
|
int good = 0;
|
||||||
|
__uint128_t total = 0;
|
||||||
|
for (int i = 1; i <= N_DRAW; i++) {
|
||||||
|
init_rabbits(&rabbits);
|
||||||
|
rabbits.male_mature[0] = 1;
|
||||||
|
rabbits.female_mature[0] = 1;
|
||||||
|
for (int j = 0; j < 12*10; j++) {
|
||||||
|
if (!process_month(&rabbits,&month))
|
||||||
|
break;
|
||||||
|
//print_rabbits(&rabbits,&month);
|
||||||
|
}
|
||||||
|
total_rabbits(&rabbits,&total);
|
||||||
|
if (total > 0)
|
||||||
|
good++;
|
||||||
|
}
|
||||||
|
puts("#############################");
|
||||||
|
printf("taux de lancement reussi: %f\n",(double)good/N_DRAW);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void print_usage(const char *prog) {
|
||||||
|
fprintf(stderr, "Usage: %s [-r | -s] [--csv]\n", prog);
|
||||||
|
fprintf(stderr, " -r mode run : simulation sur 80 ans (par defaut)\n");
|
||||||
|
fprintf(stderr, " -s mode stats : 10000 tirages de 10 ans\n");
|
||||||
|
fprintf(stderr, " --csv activer la sortie CSV sur stderr (desactive par defaut)\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char **argv) {
|
||||||
|
init_genrand(42);
|
||||||
|
|
||||||
|
int run = 1; /* mode run par defaut si aucun argument */
|
||||||
|
int csv = 0;
|
||||||
|
if (argc > 1) {
|
||||||
|
for (int i = 1; i < argc; i++) {
|
||||||
|
if (strcmp(argv[i], "-s") == 0)
|
||||||
|
run = 0;
|
||||||
|
else if (strcmp(argv[i], "-r") == 0)
|
||||||
|
run = 1;
|
||||||
|
else if (strcmp(argv[i], "--csv") == 0)
|
||||||
|
csv = 1;
|
||||||
|
else {
|
||||||
|
print_usage(argv[0]);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
set_csv_enabled(csv);
|
||||||
|
|
||||||
|
printf("===========Rabbit Hole Simulation =============\n");
|
||||||
|
if (run)
|
||||||
|
run_mode();
|
||||||
|
else
|
||||||
|
stats_mode();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -305,7 +305,15 @@ char print_rabbits(rabbit_hole_t *rabbits, __uint128_t *month)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int csv_enabled = 0;
|
||||||
|
|
||||||
|
void set_csv_enabled(int enabled) {
|
||||||
|
csv_enabled = enabled;
|
||||||
|
}
|
||||||
|
|
||||||
void csv_header() {
|
void csv_header() {
|
||||||
|
if (!csv_enabled)
|
||||||
|
return;
|
||||||
fprintf(stderr, "Month, Total Rabbit, Litters,");
|
fprintf(stderr, "Month, Total Rabbit, Litters,");
|
||||||
for ( i = 0; i < N_MATURE; i++) {
|
for ( i = 0; i < N_MATURE; i++) {
|
||||||
fprintf(stderr,"Male (age %d),",i+1);
|
fprintf(stderr,"Male (age %d),",i+1);
|
||||||
@@ -324,6 +332,8 @@ void csv_header() {
|
|||||||
|
|
||||||
char csv_rabbits(rabbit_hole_t *rabbits, const __uint128_t *month) {
|
char csv_rabbits(rabbit_hole_t *rabbits, const __uint128_t *month) {
|
||||||
__uint128_t total;
|
__uint128_t total;
|
||||||
|
if (!csv_enabled)
|
||||||
|
return 1;
|
||||||
if (!total_rabbits(rabbits,&total))
|
if (!total_rabbits(rabbits,&total))
|
||||||
return 0;
|
return 0;
|
||||||
char number_string[512];
|
char number_string[512];
|
||||||
|
|||||||
@@ -25,7 +25,9 @@ typedef struct rabbit_hole_s {
|
|||||||
|
|
||||||
void init_rabbits(rabbit_hole_t *rabbits);
|
void init_rabbits(rabbit_hole_t *rabbits);
|
||||||
char process_month(rabbit_hole_t *rabbits,__uint128_t *month);
|
char process_month(rabbit_hole_t *rabbits,__uint128_t *month);
|
||||||
|
void set_csv_enabled(int enabled);
|
||||||
void csv_header();
|
void csv_header();
|
||||||
char print_rabbits(rabbit_hole_t *rabbits, __uint128_t *month);
|
char print_rabbits(rabbit_hole_t *rabbits, __uint128_t *month);
|
||||||
|
char total_rabbits(rabbit_hole_t *rabbits, __uint128_t *total);
|
||||||
|
|
||||||
#endif //SIMULATIONRABBIT_RABBIT_HOLE_H
|
#endif //SIMULATIONRABBIT_RABBIT_HOLE_H
|
||||||
|
|||||||
@@ -182,6 +182,7 @@ if (rabbits->female_litter < 100) {
|
|||||||
\end{figure}
|
\end{figure}
|
||||||
|
|
||||||
\section{Statistiques}
|
\section{Statistiques}
|
||||||
|
\subsection{Régles}
|
||||||
Pour collecter les statistiques, j'écris sur la sortie d'erreur (stderr)
|
Pour collecter les statistiques, j'écris sur la sortie d'erreur (stderr)
|
||||||
au format CSV, puis je redirige cette sortie vers un fichier afin de
|
au format CSV, puis je redirige cette sortie vers un fichier afin de
|
||||||
l'exploiter. J'inscris une nouvelle ligne chaque mois, contenant
|
l'exploiter. J'inscris une nouvelle ligne chaque mois, contenant
|
||||||
@@ -189,10 +190,12 @@ l'ensemble des nombres de ma structure. Pour afficher les nombres en
|
|||||||
\verb|__uint128_t|, il n'existe pas de format d'affichage par défaut,
|
\verb|__uint128_t|, il n'existe pas de format d'affichage par défaut,
|
||||||
contrairement à \verb|uint64_t| par exemple (\verb|%llu|) : il a donc
|
contrairement à \verb|uint64_t| par exemple (\verb|%llu|) : il a donc
|
||||||
fallu réaliser un formatage manuel. Les graphiques obtenus permettent de
|
fallu réaliser un formatage manuel. Les graphiques obtenus permettent de
|
||||||
vérifier que les règles posées au départ sont bien respectées.
|
vérifier que les règles posées au départ sont bien respectées. J'ai pris, pour
|
||||||
|
commencer, 10 lapins mâles et 10 lapines, pour être sûr qu'ils grandissent.
|
||||||
|
|
||||||
\begin{figure}[htbp]
|
\begin{figure}[htbp]
|
||||||
\centering
|
\centering
|
||||||
|
\includegraphics[width=0.45\textwidth]{population_total}
|
||||||
\includegraphics[width=0.45\textwidth]{regle1_gestation}
|
\includegraphics[width=0.45\textwidth]{regle1_gestation}
|
||||||
\includegraphics[width=0.45\textwidth]{regle2_distribution}
|
\includegraphics[width=0.45\textwidth]{regle2_distribution}
|
||||||
\includegraphics[width=0.45\textwidth]{regle2_portees}
|
\includegraphics[width=0.45\textwidth]{regle2_portees}
|
||||||
@@ -203,6 +206,14 @@ vérifier que les règles posées au départ sont bien respectées.
|
|||||||
\label{fig:regles}
|
\label{fig:regles}
|
||||||
\end{figure}
|
\end{figure}
|
||||||
|
|
||||||
|
\subsection{Taux de commencement}
|
||||||
|
|
||||||
|
En prenant un seul couple il y a une possibilité de mort trop tôt et que la
|
||||||
|
reaction en chaine ne ce fasse pas. J'ai donc essayer de lancer plusieur fois
|
||||||
|
pour avoir le taux de fois ou on arrive a lancer la simulation a partir d'un couple.
|
||||||
|
Le taux optenu est du coup de $92\%$ donc $8\%$ des simulations ne sont
|
||||||
|
pas pertinante.
|
||||||
|
|
||||||
\section{Utilisation de l'IA}
|
\section{Utilisation de l'IA}
|
||||||
Pendant ce TP, l'IA a été utilisée pour :
|
Pendant ce TP, l'IA a été utilisée pour :
|
||||||
\begin{itemize}
|
\begin{itemize}
|
||||||
|
|||||||
Reference in New Issue
Block a user