-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathselection.cpp
More file actions
39 lines (28 loc) · 1.16 KB
/
Copy pathselection.cpp
File metadata and controls
39 lines (28 loc) · 1.16 KB
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
30
31
32
33
34
35
36
37
38
39
/******************************************************************************\
* Selection *
\******************************************************************************/
#include "defs.h"
#include <cstdlib>
/******************************************************************************\
* Tournament Selection *
\*******************************************************************************/
int selection_tournament(population *pop)
{
int i, individual_rand, individual_chosen;
individual_chosen=random_int(0, (popsize-1) );
for (i=1;i<tournament_size;i++){
individual_rand=random_int(0, (popsize-1) );
if ( pop->ind[individual_rand].fitness > pop->ind[individual_chosen].fitness )
individual_chosen=individual_rand;
}
return individual_chosen;
}
/******************************************************************************\
* Selection *
\*******************************************************************************/
int selection( population *pop )
{
int individual_chosen;
individual_chosen = selection_tournament( pop );
return individual_chosen;
}