-
Notifications
You must be signed in to change notification settings - Fork 0
/
LocalSearchSolver.h
54 lines (42 loc) · 1.22 KB
/
LocalSearchSolver.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
/**
* @file TSPSolver.h
* @brief TSP solver (neighborhood search)
*
*/
#ifndef LOCALSEARCHSOLVER_H
#define LOCALSEARCHSOLVER_H
#include <vector>
#include "solver.h"
#include "neighborimprovement.h"
/**
* Class that solves a TSP problem by neighbourdood search and 2-opt moves
*/
class LocalSearchSolver : public Solver
{
public:
NeigthborImprovement* findNeighbor;
LocalSearchSolver(bool bestImprovement = true) {
if (bestImprovement) {
findNeighbor = new BestImprovement();
} else {
findNeighbor = new FirstImprovement();
}
}
/**
* search for a good tour by neighbourhood search
* @param TSP TSP data
* @param initSol initial solution
* @param bestSol best found solution (output)
* @return true id everything OK, false otherwise
*/
bool solve ( const TSP& tsp , const TSPSolution& initSol , TSPSolution& bestSol );
std::string getSolverName() const;
/**
* perform a swap move (corresponding to 2-opt)
* @param tspSol solution to be perturbed
* @param move move to perform
* @return (into param tspSol) the perturbed solution
*/
TSPSolution& swap( TSPSolution& tspSol , const TSPMove& move );
};
#endif /* LOCALSEARCHSOLVER_H */