forked from ameya005/AntColonyAlgorithms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathantal.cpp
65 lines (47 loc) · 1.74 KB
/
antal.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
//Ant algorithms for Travelling salesman Problem
#include <stdio.h>
#include "common.h"
#include <complex>
#include <iostream>
#include <stdlib.h>
#include <chrono>
#include <iomanip>
using namespace std;
int main() {
int curTime = 0;
cout << "S-ACO:";
cout << "MaxTime=" << MAX_TIME << endl;
srand(time(NULL));
std::chrono::system_clock::time_point startTime = std::chrono::system_clock::now();
init();
std::chrono::system_clock::time_point endTime = std::chrono::system_clock::now();
std::chrono::microseconds microRunTime
= std::chrono::duration_cast<std::chrono::microseconds>(endTime - startTime);
double runTime = microRunTime.count() / 1000000.0;
std::cout << std::setprecision( 8 )
<< "Init clock time = " << runTime << " seconds."
<< std::endl << std::flush;
startTime = std::chrono::system_clock::now();
while (curTime++ < MAX_TIME) {
if (simulateAnts() == 0) {
updateTrails();
if (curTime != MAX_TIME)
restartAnts();
cout << "\n Time is " << curTime << " (" << best << " km)";
}
}
endTime = std::chrono::system_clock::now();
microRunTime = std::chrono::duration_cast<std::chrono::microseconds>(endTime - startTime);
runTime = microRunTime.count() / 1000000.0;
std::cout << std::setprecision( 8 ) << endl
<< "Wall clock time = " << runTime << " seconds."
<< std::endl << std::flush;
cout << "\nSACO: Best tour = " << best << " km" << endl << endl << endl;
antType antBest;
antBest = ants[bestIndex];
for (int i = 0; i < MAX_CITIES; i++) {
cout << cities[antBest.path[i]].name << " > ";
}
emitDataFile(bestIndex);
return 0;
}