reffactoring for more test
This commit is contained in:
@@ -1,22 +1,82 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "rabbit_hole.h"
|
||||
#include "mt19937ar.h"
|
||||
|
||||
int main(void) {
|
||||
init_genrand(42);
|
||||
printf("===========Rabbit Hole Simulation =============\n");
|
||||
#define N_DRAW (10000)
|
||||
|
||||
/* Mode run : init 10 males / 10 femelles matures, simulation sur 80 ans. */
|
||||
static void run_mode(void) {
|
||||
rabbit_hole_t rabbits;
|
||||
init_rabbits(&rabbits);
|
||||
rabbits.male_mature[0] = 10;
|
||||
rabbits.female_mature[0] = 10;
|
||||
__uint128_t month = 0;
|
||||
print_rabbits(&rabbits,&month);
|
||||
csv_header();
|
||||
for (int j = 0; j < 12*80 ; j++) {
|
||||
|
||||
for (int j = 0; j < 12*80; j++) {
|
||||
if (!process_month(&rabbits,&month))
|
||||
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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user