-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmainST.cpp
More file actions
61 lines (50 loc) · 1.63 KB
/
Copy pathmainST.cpp
File metadata and controls
61 lines (50 loc) · 1.63 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
#include <iostream>
#include <chrono>
#include "src/graph/undirectedGraph.h"
#include "src/geneticAlgorithm/TSPGeneticAlgorithmST.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]);
}
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("nWorker: %d msecST: %ld numberOfNode: %ld nPopulation: %ld nIteration: %d\n",
nWorker,
msecST,
numberOfNode,
nPopulation,
nIteration);
}