f4c3@1031: #ifndef LEMON_INSERTION_TSP_H f4c3@1031: #define LEMON_INSERTION_TSP_H f4c3@1031: f4c3@1031: #include f4c3@1031: #include f4c3@1031: #include f4c3@1031: #include f4c3@1031: #include f4c3@1031: f4c3@1031: namespace lemon { f4c3@1031: f4c3@1031: namespace insertion_tsp_helper { f4c3@1031: f4c3@1031: template f4c3@1031: L vectorConvert(const std::vector &_path) { f4c3@1031: return L(_path.begin(), _path.end()); f4c3@1031: }; f4c3@1031: f4c3@1031: template <> f4c3@1031: std::vector vectorConvert( f4c3@1031: const std::vector &_path) { f4c3@1031: return _path; f4c3@1031: }; f4c3@1031: f4c3@1031: }; f4c3@1031: f4c3@1031: template f4c3@1031: class InsertionTsp { f4c3@1031: private: f4c3@1031: GRAPH_TYPEDEFS(FullGraph); f4c3@1031: f4c3@1031: public: f4c3@1031: typedef CM CostMap; f4c3@1031: typedef typename CM::Value Cost; f4c3@1031: f4c3@1031: InsertionTsp(const FullGraph &gr, const CostMap &cost) : f4c3@1031: _gr(gr), _cost(cost) {} f4c3@1031: f4c3@1031: enum InsertionMethod { f4c3@1031: INSERT_NEAREST, f4c3@1031: INSERT_FARTHEST, f4c3@1031: INSERT_CHEAPEST, f4c3@1031: INSERT_RANDOM f4c3@1031: }; f4c3@1031: f4c3@1031: Cost run(InsertionMethod method = INSERT_FARTHEST) { f4c3@1031: switch (method) { f4c3@1031: case INSERT_NEAREST: f4c3@1031: start, NearestSelection, DefaultInsert>(); f4c3@1031: break; f4c3@1031: case INSERT_FARTHEST: f4c3@1031: start, FarthestSelection, DefaultInsert>(); f4c3@1031: break; f4c3@1031: case INSERT_CHEAPEST: f4c3@1031: start, CheapestSelection, CheapestInsert>(); f4c3@1031: break; f4c3@1031: case INSERT_RANDOM: f4c3@1031: start, RandomSelection, DefaultInsert>(); f4c3@1031: break; f4c3@1031: } f4c3@1031: return sum; f4c3@1031: } f4c3@1031: f4c3@1031: template f4c3@1031: void tourNodes(L &container) { f4c3@1031: container(insertion_tsp_helper::vectorConvert(nodesPath)); f4c3@1031: } f4c3@1031: f4c3@1031: template