-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.cpp
executable file
·117 lines (106 loc) · 3.82 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/* main.cpp
*
* This is the class in which the evolutionary algorithm is going to be run.
* Version: 1.0.0
*/
//STL libraries
#include <memory>
#include <iostream>
#include <string>
//API libraries
#include "API/CompetitionScenario.h"
#include "API/WindScenario.h"
#include "API/KusiakLayoutEvaluator.h"
#include "API/CompetitionEvaluator.h"
//Project's libraries
#include "structures.hpp"
#include "initialization.hpp"
#include "selection.hpp"
#include "recombination.hpp"
#include "mutation.hpp"
#include "replacement.hpp"
#include "evolutionary_algorithm.hpp"
#include "statistical_comparison.hpp"
#include "scenario.hpp"
#include <time.h>
#include <stdlib.h>
#include <fstream>
using namespace std::placeholders;
int main(int argc, const char * argv[]) {
srand(time(NULL));
std::string arg1;
if (argc > 1) {
arg1 = argv[1];
}
if (arg1 == "statistical_comparison") {
int pop_size, generations, iterations;
std::cout << "Enter the population size: " << std::endl;
std::cin >> pop_size;
std::cout << "Enter the number of generations: " << std::endl;
std::cin >> generations;
std::cout << "Enter the number of iterations: " << std::endl;
std::cin >> iterations;
std::cout << "Comparison is being run. This will take a while..." << std::endl;
statistical_comparison(pop_size, generations, iterations, argv[2]);
} else {
bool serious_mode = false;
std::cout << "Run against the server? (0/1)" << std::endl;
std::cin >> serious_mode;
std::unique_ptr<WindFarmLayoutEvaluator> evaluator;
std::unique_ptr<CompetitionScenario> cscenario;
std::unique_ptr<WindScenario> wscenario;
std::unique_ptr<Scenario> scenario;
if (serious_mode) {
int sc_number;
std::cout << "Scenario number? (1 to 5)" << std::endl;
std::cin >> sc_number;
cscenario.reset(new CompetitionScenario(sc_number));
scenario.reset(new Scenario(*cscenario));
const char* TOKEN = "XQNC1VSQ112N3I45DP56D87RYODN7Z";
CompetitionEvaluator* cevaluator = new CompetitionEvaluator();
cevaluator->initialize(*cscenario, TOKEN);
evaluator.reset(cevaluator);
} else {
wscenario.reset(new WindScenario(argv[1]));
scenario.reset(new Scenario(*wscenario));
KusiakLayoutEvaluator* kevaluator = new KusiakLayoutEvaluator();
kevaluator->initialize(*wscenario);
evaluator.reset(kevaluator);
}
int pop_size = 0;
int generations = 0;
bool shouldLoadFile = false;
bool shouldSaveFile = false;
std::cout << "Should it load from disk? (0/1)" << std::endl;
std::cin >> shouldLoadFile;
std::cout << "Should it save data to disk? (0/1)" << std::endl;
std::cin >> shouldSaveFile;
std::ifstream file("population.txt", std::ifstream::in);
if (file.is_open()){
file >> pop_size;
file.close();
}
else{
shouldLoadFile = false;
}
if (!shouldLoadFile){
std::cout << "Enter the population size: " << std::endl;
std::cin >> pop_size;
}
std::cout << "Enter the number of generations: " << std::endl;
std::cin >> generations;
double fitness = evolutionary_algorithm(
*evaluator,
*scenario,
std::bind(initialization::initialization_2, _1,_2,pop_size),
std::bind(selection::selection_1, _1, pop_size),
recombination::crossover,
std::bind(mutation::random_reset, 0.25f, _1, _2),
std::bind(replacement::replacement_1,_1,_2, pop_size),
generations,
shouldLoadFile,
shouldSaveFile
).first;
std::cout << "Best " << fitness << std::endl;
}
}