-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
executable file
·195 lines (185 loc) · 5.88 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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
#include <iostream>
#include <iomanip>
#include <ctime>
#include <fstream>
#include <sys/file.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <testfile.h>
#include <ES.h>
#include <HC.h>
#include <SA.h>
#include <TS.h>
#include <GA.h>
#include <ACO.h>
#include <PSO.h>
#include <Gnuplot.h>
#include <lib.h>
using namespace std;
int main(int argc, char** argv)
{
int name_algo = atoi(argv[1]);
int num_bit ;
int num_evaluation ;
int num_run ;
int name_function ;
clock_t begin ;
if(name_algo == 10) goto PLOT;
else
{
num_bit = atoi(argv[2]);
num_evaluation = atoi(argv[3]);
num_run = atoi(argv[4]);
name_function = atoi(argv[5]);
}
if(name_function == 2 && (num_bit > 15))
{
cout << "---ALERT---" << endl;
cout << "Num_bit is too long." << endl;
exit(0);
}
PLOT:
begin = clock();
// switch method
// switch (name_algo)
// {
// case 0:
// {
// testfile testfile(name_algo, num_bit);
// testfile.main();
// break;
// }
// case 1:
// {
// ES ES(name_algo, num_bit, num_evaluation, num_run, name_function);
// ES.main();
// break;
// }
// case 2:
// {
// string way_method = argv[6];
// HC HC(name_algo, num_bit, num_evaluation, num_run, name_function, way_method);
// HC.main();
// break;
// }
// case 3:
// {
// string way_method = argv[6];
// SA SA(name_algo, num_bit, num_evaluation, num_run, name_function, way_method);
// SA.main();
// break;
// }
// case 4:
// {
// string way_method = argv[6];
// TS TS(name_algo, num_bit, num_evaluation, num_run, name_function, way_method);
// TS.main();
// break;
// }
// case 5:
// {
// int num_population = atoi(argv[6]);
// string way_selection = argv[7];
// string way_crossover = argv[8];
// double crossover_rate = atof(argv[9]);
// double mutation_rate = atof(argv[10]);
// GA GA(name_algo, num_bit, num_evaluation, num_run, name_function, num_population, way_selection, way_crossover, crossover_rate, mutation_rate);
// GA.main();
// break;
// }
// case 6:
// {
// int num_population = atoi(argv[6]);
// double alpha = atof(argv[7]);
// double beta = atof(argv[8]);
// double rho = atof(argv[9]);
// double q = atof(argv[10]);
// ACO ACO(name_algo, num_bit, num_evaluation, num_run, name_function, num_population, alpha, beta, rho, q);
// ACO.main();
// }
// case 10:
// {
// name_function = atoi(argv[2]);
// Gnuplot Gnuplot(name_algo, name_function);
// Gnuplot.main();
// break;
// }
// default:
// {
// cout << "########## Please check the name of method. ##########" << endl;
// break;
// }
// }
// if method
if(name_algo == 0)
{
testfile testfile(name_algo, num_bit);
testfile.main();
}
else if(name_algo == 1)
{
ES ES(name_algo, num_bit, num_evaluation, num_run, name_function);
ES.main();
}
else if(name_algo == 2)
{
string way_method = argv[6];
HC HC(name_algo, num_bit, num_evaluation, num_run, name_function, way_method);
HC.main();
}
else if(name_algo == 3)
{
string way_method = argv[6];
SA SA(name_algo, num_bit, num_evaluation, num_run, name_function, way_method);
SA.main();
}
else if(name_algo == 4)
{
string way_method = argv[6];
TS TS(name_algo, num_bit, num_evaluation, num_run, name_function, way_method);
TS.main();
}
else if(name_algo == 5)
{
int num_population = atoi(argv[6]);
string way_selection = argv[7];
string way_crossover = argv[8];
double crossover_rate = atof(argv[9]);
double mutation_rate = atof(argv[10]);
GA GA(name_algo, num_bit, num_evaluation, num_run, name_function, num_population, way_selection, way_crossover, crossover_rate, mutation_rate);
GA.main();
}
else if(name_algo == 6)
{
int num_population = atoi(argv[6]);
double alpha = atof(argv[7]);
double beta = atof(argv[8]);
double rho = atof(argv[9]);
double q = atof(argv[10]);
string dataset = argv[11];
ACO ACO(name_algo, num_bit, num_evaluation, num_run, name_function, num_population, alpha, beta, rho, q, dataset);
ACO.main();
}
else if(name_algo == 7)
{
int num_population = atoi(argv[6]);
double w = atof(argv[7]);
double c1 = atof(argv[8]);
double c2 = atof(argv[9]);
int dimension = atof(argv[10]);
PSO PSO(name_algo, num_bit, num_evaluation, num_run, name_function, num_population, w, c1, c2, dimension);
PSO.main();
}
else if(name_algo == 10)
{
name_function = atoi(argv[2]);
Gnuplot Gnuplot(name_algo, name_function);
Gnuplot.main();
}
else cout << "########## Please check the name of method. ##########" << endl;
clock_t end = clock();
double elapsed_secs = double(end - begin) / CLOCKS_PER_SEC;
cout << "---------------------" << endl;
cout << elapsed_secs << " sec." << endl;
cout << "DONE." << endl;
}