-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
71 lines (51 loc) · 1.26 KB
/
main.cpp
File metadata and controls
71 lines (51 loc) · 1.26 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#ifndef _STANDARD
#define _STANDARD
#include <iostream>
#include <iomanip>
#include <cmath>
#include <ctime>
#endif
#ifndef _CHROMOSOME
#define _CHROMOSOME
#include "Chromosome.h"
#endif
#ifndef _VECTOR
#define _VECTOR
#include <vector>
#endif
#include "Population.h"
using namespace std;
// Current problem = max(x.sin(10pi.x) + 1.0)
// Max should be around x=1.85
// Required chromosome length = 2^22
// VAR : Init probability of mutation
float Chromosome::PROB_MUT = 0.05;
float Chromosome::PROB_XOV = 0.25;
float Population::FITNESS_HALT = 0.0001;
float Population::HARD_LIMIT = 2.7; //Currently unused
const int Population::pop_size = 100;
int main(){
srand(time(0));
Population curPool(22);
const int MAX_ITER = 1000;
int iter = 1;
cout << " First generation : " << endl << curPool;
cin.get();
while(iter<= MAX_ITER){
cout <<setw(7)<< iter++ << " : ";
curPool.evolve();
}
cout << " Max iter reached \n";
curPool.getBest();
cout << curPool;
/* Test Code for Operators
cout << "Hello World\n";
Chromosome test(32), test2(32);
cout << "\n Before : \n" << test << endl << test2;
test.cross(test2);
cout << "\n After : \n" << test << endl << test2;
test2.mutate();
cout << "\n Mutate (2): \n" << test2;
*/
return 0;
}