-
Notifications
You must be signed in to change notification settings - Fork 0
/
mainSA.cpp
41 lines (36 loc) · 1.36 KB
/
mainSA.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
#include "Interface.h"
#include <chrono>
using namespace std;
using namespace std::chrono;
int main() {
// Testing
File file("3-pr13");
file.read_file();
float totalProfit = 0;
totalProfit = calculate_profit();
for(int iter = 0; iter< 2; iter++) {
cout << "Total profit is --> " << totalProfit << '\n';
TOP top(file.get_N(), file.get_V());
vector<int> firstSolution = top.random_solution_generator();
cout << "***************** First Solution *****************" << '\n';
for (int i = 0; i < firstSolution.size(); i++) {
cout << firstSolution[i] << ' ';
}
cout << '\n';
cout << "**************************************************" << '\n';
auto start = high_resolution_clock::now();
SA sa(firstSolution, 0.3, 0.999, 30, 4000, file.get_N(), file.get_V());
// sa.ssaAlgorithm(); // By number of Not improving times
sa.fsaAlgorithm(180); // By time
float finalProfit = sa.printFinalSolution();
auto stop = high_resolution_clock::now();
auto duration = duration_cast<seconds>(stop - start);
cout << "**************************************************" << '\n';
cout << "Time taken: "
<< duration.count() << " seconds" << endl;
cout << "Accuracy is --> " << (finalProfit / totalProfit) << '\n';
cout<<"Iteration "<<iter+1<<" finished"<<'\n';
cout<<'\n';
}
return 0;
}