-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
54 lines (52 loc) · 1.69 KB
/
main.cpp
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
#include <iostream>
#include <fstream>
#include <vector>
#include "map.h"
#include "route.h"
#include "mutate.h"
#include "misc.h"
#include "genePool.h"
int main() {
map town;
town.load();
genePool generations;
std::cout<<zachlannyArtura(*&town, generations)<<std::endl;
populateGeneration(*&town,*&generations);
generations.calcFitnessAll(*&town);
//generations.improve(town);
int i=1;
for (route &it: generations.getPool()){
checkVector(it.getRoute(),it.getLength(),town,generations);
//std::cout<<i<<" "<<it.getLength()<<" "<<it.getFitness()<<std::endl;
i++;
}
int j=0;
int failCounter=0;
int previousLengthSum;
double chance=genomMutationChance;
while(true){
std::cout<<"generacja: "<<j<<" postep: "<<generations.getCurrentLengthSum()<<" best: "<<generations.getBestLength()<<std::endl;
previousLengthSum=generations.getCurrentBestLength();
if(failCounter>=overdDriveThreshhold){
failCounter=0;
chance=chance+0.1;
generations.improve(town);
}
else{
chance=genomMutationChance;
failCounter=0;
}
generations.createNewGeneration(*&town,chance,true);
generations.calcFitnessAll(*&town);
if(generations.getCurrentBestLength()==previousLengthSum)failCounter++;
if(j%100==0){
std::cout<<generations.getBestLength()<<" "<<generations.getCurrentBestLength()<<" "<<generations.getCurrentLengthSum()<<std::endl;
for(auto it:generations.getBestRoute().getRoute()){
std::cout<<it<<" ";
}
std::cout<<std::endl;
}
j++;
}
return 0;
}