-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
84 lines (68 loc) · 2.66 KB
/
Copy pathmain.cpp
File metadata and controls
84 lines (68 loc) · 2.66 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include <iostream>
#include <chrono>
#include "src/graph/undirectedGraph.h"
#include "src/geneticAlgorithm/TSPGeneticAlgorithm.h"
#include "src/geneticAlgorithm/TSPGeneticAlgorithmST.h"
#include "src/geneticAlgorithm/TSPGeneticAlgorithmFF.h"
int main(int argc, char *argv[]) {
if (argc < 4) {
std::cout << "Usage is " << argv[0]
<< " numberOfNode population nIteration [nWorker] [seed] [crossoverProbability] [mutationProbability]" << std::endl;
return (-1);
}
const size_t numberOfNode = atoi(argv[1]);
const size_t nPopulation = atoi(argv[2]);
if (nPopulation < 2) {
std::cout << "Population must be greater than or equal to 2"
<< std::endl;
return (-1);
}
const int nIteration = atoi(argv[3]);
int nWorker = 1;
int seed = 0;
double crossoverProbability = 0.2;
double mutationProbability = 0.1;
if (argc > 4) {
nWorker = atoi(argv[4]);
}
if (argc > 5) {
seed = atoi(argv[5]);
}
if (argc > 6) {
crossoverProbability = std::stod(argv[6]);
}
if (argc > 7) {
mutationProbability = std::stod(argv[7]);
}
TSPGeneticAlgorithm<int, double> tspSeq(seed, crossoverProbability, mutationProbability);
tspSeq.SetMultiplier(1);
tspSeq.SetTotalPopulation(nPopulation);
tspSeq.setRandomGraph(numberOfNode);
auto startSeq = std::chrono::high_resolution_clock::now();
tspSeq.run(nIteration);
auto elapsedSeq = std::chrono::high_resolution_clock::now() - startSeq;
auto msecSeq = std::chrono::duration_cast<std::chrono::milliseconds>(elapsedSeq).count();
printf("Final Seq time (msecs): %ld\n", msecSeq);
std::cout<<std::endl;
TSPGeneticAlgorithmST<int, double> tspST(seed, crossoverProbability, mutationProbability);
tspST.SetMultiplier(1);
tspST.SetTotalPopulation(nPopulation);
tspST.setRandomGraph(numberOfNode);
tspST.SetNWorker(nWorker);
auto startST = std::chrono::high_resolution_clock::now();
tspST.run(nIteration);
auto elapsedST = std::chrono::high_resolution_clock::now() - startST;
auto msecST = std::chrono::duration_cast<std::chrono::milliseconds>(elapsedST).count();
printf("Final ST time (msecs): %ld\n", msecST);
std::cout << std::endl;
TSPGeneticAlgorithmFF<int, double> tspFF(seed, crossoverProbability, mutationProbability);
tspFF.SetMultiplier(1);
tspFF.SetTotalPopulation(nPopulation);
tspFF.setRandomGraph(numberOfNode);
tspFF.SetNWorker(nWorker);
auto startFF = std::chrono::high_resolution_clock::now();
tspFF.run(nIteration);
auto elapsedFF = std::chrono::high_resolution_clock::now() - startFF;
auto msecFF = std::chrono::duration_cast<std::chrono::milliseconds>(elapsedFF).count();
printf("Final FF time (msecs): %ld\n", msecFF);
}