-
Notifications
You must be signed in to change notification settings - Fork 0
/
TabuSearchSolver.h
94 lines (60 loc) · 2.28 KB
/
TabuSearchSolver.h
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
85
86
87
88
89
90
91
92
93
94
/**
* @file TSPSolver.h
* @brief TSP solver (neighborhood search)
*
*/
#ifndef TSPSOLVER_H
#define TSPSOLVER_H
#include <vector>
#include <list>
#include <iostream>
#include <set>
#include "solver.h"
using namespace std;
class TSStopCriteria {
};
/**
* Class that solves a TSP problem by neighbourdood search and 2-opt moves
*/
class TabuSearchSolver : public Solver
{
public:
uint mTabuLength;
int mMaxIteration;
double mMaxTime;
list<TSPMove> mTabuList;
// Advance Tabu
list<string> mAdvTabuList;
set<string> mTabuSet;
double mAspiration;
// config variable
bool ACmode;
bool BestImprovement;
char mBuffer[50];
//TSStopCriteria StopCriteria;
TabuSearchSolver() {}
TabuSearchSolver(int tabuLength, int maxIter, bool aspCriteria = false, bool bestImprovement = true, double maxSeconds = 1e10)
: mTabuLength(tabuLength), mMaxIteration(maxIter), mMaxTime(maxSeconds), ACmode(aspCriteria), BestImprovement(bestImprovement) {}
// Factory methods
static TabuSearchSolver* buildTS_BI(int tabuLenght, int maxIter, double maxSeconds = 1e10) {
return new TabuSearchSolver(tabuLenght, maxIter, false, true, maxSeconds);
}
static TabuSearchSolver* buildTS_BI_AC(int tabuLenght, int maxIter, double maxSeconds = 1e10) {
return new TabuSearchSolver(tabuLenght, maxIter, true, true, maxSeconds);
}
static TabuSearchSolver* buildTS_FI(int tabuLenght, int maxIter, double maxSeconds = 1e10) {
return new TabuSearchSolver(tabuLenght, maxIter, false, false, maxSeconds);
}
static TabuSearchSolver* buildTS_FI_AC(int tabuLenght, int maxIter, double maxSeconds = 1e10) {
return new TabuSearchSolver(tabuLenght, maxIter, true, false, maxSeconds);
}
std::string getSolverName() const;
bool solve(const TSP &tsp, const TSPSolution &initSol, TSPSolution &bestSol);
bool satisfiedAspirationCriteria(double neighbourCostVariation) const;
// private:
double findBestNeighbor(const TSP& tsp , const TSPSolution& currSol , TSPMove& move );
double findFirstBestNeighbor(const TSP &tsp, const TSPSolution &currSol, TSPMove &move);
TSPSolution& swap(TSPSolution& tspSol , const TSPMove& move );
bool isTabuMove(int from, int to);
};
#endif /* TSPSOLVER_H */