-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstatistics.cpp
More file actions
29 lines (20 loc) · 859 Bytes
/
Copy pathstatistics.cpp
File metadata and controls
29 lines (20 loc) · 859 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
/******************************************************************************\
* Statistics *
\******************************************************************************/
#include "defs.h"
#include <cstdlib>
void statistics( population *pop )
{
int j;
pop->sum_fitness = pop->ind[0].fitness; // sum of the fitness in the population
pop->max_fitness = pop->ind[0].fitness; // maximum fitness in the population
pop->best_individual = 0; // best individual in the population
for(j=1;j<popsize;j++) {
pop->sum_fitness = pop->sum_fitness + pop->ind[j].fitness;
if (pop->ind[j].fitness > pop->max_fitness ) {
pop->max_fitness = pop->ind[j].fitness ;
pop->best_individual = j;
}
}
pop->mean_fitness = pop->sum_fitness / popsize; // mean fitness in the population
}