-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
56 lines (45 loc) · 1.34 KB
/
Copy pathmain.cpp
File metadata and controls
56 lines (45 loc) · 1.34 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <iostream>
#include "genome.h"
#include "chromosome.h"
#include "population.h"
#define CROSS_RATE 0.5
#define MUTATION_RATE 0.1
#define MIN_RANDOM -5.0
#define MAX_RANDOM 5.0
#define MAX_GENERATION_COUNT 40
#define POP_SIZE 35
#define GENOMES_COUNT 5
#define MINIMUM
#ifdef MINIMUM
#define FITNESS -1
#else
#define FITNESS 1
#endif
int main()
{
Population * population = new Population();
if( ! population )
return -1;
population->set_cross_rate( CROSS_RATE );
population->set_mutation_rate( MUTATION_RATE );
population->set_min_random( MIN_RANDOM );
population->set_max_random( MAX_RANDOM );
population->set_max_generation_count( MAX_GENERATION_COUNT );
population->set_pop_size( POP_SIZE );
population->set_genomes_count( GENOMES_COUNT );
population->initialize();
population->print_output();
int i = 0;
while( ! population->population_is_stopped() )
//while( i < MAX_GENERATION_COUNT )
{
population->apply_cross_over();
population->apply_mutation();
population->calculate_fitness_function( FITNESS );
population->select_best_chromosomes();
i++;
}
population->print_output();
delete population;
return 0;
}