-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
66 lines (46 loc) · 1.88 KB
/
Copy pathmain.cpp
File metadata and controls
66 lines (46 loc) · 1.88 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
#include <iostream>
#include "Graph.h"
#include "Population.h"
#include "KMeans.h"
void evolutionary_algorithm(std::ifstream &config_file, Graph &graph, Evaluator &evaluator) {
int no_individuals, no_generations;
double mutation_probability;
config_file >> no_individuals >> mutation_probability >> no_generations;
Population population(no_individuals, graph, mutation_probability, evaluator);
for (int i = 0; i < no_generations; i++) {
population.generate_offsprings();
population.generate_next_generation();
std::cout << "current best fitness: " << population[0].get_fitness() << "\n";
}
Individual best_individual = population[0];
std::cout << "best fitness: " << best_individual.get_fitness();
}
void KMeans_algorithm(std::ifstream &config_file, Graph &graph, Evaluator &evaluator) {
int no_tests, no_clusters, no_generations;
config_file >> no_tests >> no_clusters >> no_generations;
for (int _ = 0; _ < no_tests; ++_) {
std::cout << "TEST " << _ << "\n\n";
KMeans k_means(graph, no_clusters);
std::cout << evaluator(k_means.get_clusters()) << '\n';
for (int iter = 0; iter < no_generations; ++iter) {
k_means.step();
std::cout << evaluator(k_means.get_clusters()) << '\n';
}
}
}
int main() {
std::string config_path;
std::cout << "Which config file do you want to use?\n";
std::cin >> config_path;
std::ifstream config_file(config_path);
std::string algorithm_type, graph_type, graph_file_path;
config_file >> algorithm_type >> graph_file_path >> graph_type;
Graph graph(graph_file_path, graph_type);
Evaluator evaluator(graph);
if (algorithm_type == "evolutionary") {
evolutionary_algorithm(config_file, graph, evaluator);
} else {
KMeans_algorithm(config_file, graph, evaluator);
}
return 0;
}