template<typename CM>
class lemon::Opt2Tsp< CM >
Opt2Tsp implements the 2-opt heuristic for solving symmetric TSP.
This algorithm starts with an initial tour and iteratively improves it. At each step, it removes two edges and the reconnects the created two paths in the other way if the resulting tour is shorter. The algorithm finishes when no such 2-opt move can be applied, and so the tour is 2-optimal.
If no starting tour is given to the run() function, then the algorithm uses the node sequence determined by the node IDs. Oherwise, it starts with the given tour.
This is a rather slow but effective method. Its typical usage is the improvement of the result of a fast tour construction heuristic (e.g. the InsertionTsp algorithm).
- Template Parameters
-
|
| Opt2Tsp (const FullGraph &gr, const CostMap &cost) |
| Constructor.
|
|
|
Cost | run () |
| Runs the algorithm from scratch.
|
|
template<typename Path > |
Cost | run (const Path &tour) |
| Runs the algorithm starting from the given tour.
|
|
Cost | run (const std::vector< Node > &tour) |
| Runs the algorithm starting from the given tour.
|
|
|
Cost | tourCost () const |
| The total cost of the found tour.
|
|
const std::vector< Node > & | tourNodes () const |
| Returns a const reference to the node sequence of the found tour.
|
|
template<typename Iterator > |
void | tourNodes (Iterator out) const |
| Gives back the node sequence of the found tour.
|
|
template<typename Path > |
void | tour (Path &path) const |
| Gives back the found tour as a path.
|
|