rosa/examples/greedy.cpp

43 lines
814 B
C++

#include <iostream>
#include <fstream>
#include <sstream>
#include "muscles/rgreedy.h"
#include "tsp/problem.h"
#include "tsp/solution.h"
#include "tsp/tsp.h"
auto mainGreedy(tsp::Problem const& problem, std::size_t start) {
std::mt19937 rng;
auto greedy = RGreedy<tsp::Solution>{0};
return greedy(problem, rng, start);
}
int main(int argc, char **argv) {
tsp::Tsp tspData{"../data/phd"};
tsp::Problem const& problem = tspData.points();
tsp::Solution solution;
std::size_t start = 0;
if(argc > 1) {
std::istringstream iss{argv[1]};
iss >> start;
}
solution = mainGreedy(problem, start);
std::cout << "distance: " << solution.value() << std::endl;
// save
{
std::ofstream ofs{"solution"};
ofs << solution;
}
{
std::ofstream ofs{"solution.ids"};
solution.printIndices(ofs);
}
}