-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
71 lines (64 loc) · 2.24 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
#include "./util/common.h"
#include "./rdata/rdata.h"
#include "./brute-force/brute.h"
#include "./greedy-algorithm/nearest-neighbor/nearest.h"
#include "./greedy-algorithm/bellmore-nemhauser/bn-heuristic.h"
#include "./greedy-algorithm/cheaper-insertion/cheaper.h"
#include <iostream>
using std::cout;
using std::endl;
int main(int argc, char **argv)
{
double **matrixAdj;
int dimension, startCity = 1;
// Reading the data of instance passed by parameter
readData(argc, argv, &dimension, &matrixAdj);
/**
* Starting the greedy algorithm looking for the best neighbor
* */
clock_t startTime = clock();
int *path = solveNearest(matrixAdj, dimension, startCity);
double totalTime = timeExecution(startTime);
double totalCost = cost(path, dimension, matrixAdj);
// See the greedy solution
cout << "\nThe nearest neighbor algorithm cost was: " << totalCost << endl;
see(path, dimension);
cout << "Execution time: " << totalTime << " s" << endl;
/**
* Starting the bellmore-nemhauser algorithm
* */
startTime = clock();
int *bnPath = solveNearestEdge(matrixAdj, dimension, startCity);
totalTime = timeExecution(startTime);
double costBn = cost(bnPath, dimension, matrixAdj);
// See the bn-heuristic solution
cout << "\nThe bellmore-nemhauser cost was: " << costBn << endl;
see(bnPath, dimension);
cout << "Execution time: " << totalTime << " s" << endl;
/**
* Starting cheaper insertion
*/
startTime = clock();
int *ciPath = cheaperInsertion(matrixAdj, dimension, startCity);
totalTime = timeExecution(startTime);
double costCi = cost(ciPath, dimension, matrixAdj);
cout << "\nThe cheaper insertion cost was: " << costCi << endl;
see(ciPath, dimension);
cout << "Execution time: " << totalTime << " s" << endl;
/*
/**
* Starting the brute force algorithm
*
clock_t startTimeBrute = clock();
int *bestPath = bruteForce(matrixAdj, dimension, path);
totalTime = timeExecution(startTimeBrute);
double bestCost = cost(bestPath, dimension, matrixAdj);
// See the best solution
cout << "The best cost of path is " << bestCost << endl;
see(bestPath, dimension);
cout << "Execution time: " << totalTime << " s" << endl;
*/
// Deallocate memory
delete[] matrixAdj, path;
return 0;
}