7 #include <boost/program_options.hpp>
14 namespace po = boost::program_options;
29 void callback(
const std::string &event)
override {
30 if (event ==
"init") {
33 }
else if (event ==
"new") {
36 std::cout <<
"TTS = " << std::fixed << std::setprecision(3)
37 << sol.get_tts() <<
"s ";
49 int main(
int argc,
char **argv) {
51 po::options_description desc(
52 "Solving the randomly generated TSP using QUBO++ Easy Solver");
53 desc.add_options()(
"help,h",
"produce help message")
54 (
"nodes,n", po::value<uint32_t>()->default_value(10),
"set the number of nodes in the TSP map")
55 (
"time,t", po::value<uint32_t>()->default_value(10),
"set time limit in seconds")
56 (
"tsp_seed,s", po::value<uint32_t>(),
"set the random seed for the TSP map")
57 (
"output,o", po::value<std::string>(),
"set the output file (png, svg, etc) to save the TSP solution")
58 (
"fix,f",
"fix node 0 as the starting node");
63 po::store(po::parse_command_line(argc, argv, desc), vm);
64 }
catch (
const std::exception &e) {
65 std::cout <<
"Wrong arguments. Please use -h/--help option to see the "
71 if (vm.count(
"help")) {
72 std::cout << desc << std::endl;
77 uint32_t nodes = vm[
"nodes"].as<uint32_t>();
79 uint32_t time_limit = vm[
"time"].as<uint32_t>();
81 bool fix_first = vm.count(
"fix");
84 if (vm.count(
"tsp_seed")) {
90 std::cout <<
"Generating random TSP Map with " << nodes <<
" nodes"
95 std::cout <<
"Generating a TSP QUBO expression" << std::endl;
98 std::cout <<
"Variables = " << tsp_quad_model.
var_count()
99 <<
" Linear Terms = " << tsp_quad_model.
term_count(1)
100 <<
" Quadratic Terms = " << tsp_quad_model.
term_count(2)
114 abs2_param.
set(abs2_callback);
116 std::cout <<
"Solving the TSP" << std::endl;
117 auto sol = abs2_solver(abs2_model, abs2_param);
122 if (vm.count(
"output")) {
124 for (uint32_t i = 0; i < nodes; ++i) graph.
add_node(tsp_map[i]);
126 for (uint32_t i = 0; i < nodes; ++i)
127 graph.
add_edge(tsp_sol[i], tsp_sol[(i + 1) % nodes]);
129 graph.
draw(vm[
"output"].as<std::string>());
Class to define ABS2 callback function for factorization.
void callback(const std::string &event) override
Callback function for ABS2 solver.
ABS2Callback(const qbpp::tsp::TSPQuadModel &tsp_quad_model)
Construct a new ABS2 callback object.
const qbpp::tsp::TSPQuadModel & tsp_quad_model
The TSP expression.
void set(const std::string &operation)
Set the operation to the ABS2 Callback.
Callback()
Constructor for creating a callback object.
void set(const std::string &key, const std::string &val)
Set "val" to "key".
vindex_t var_count() const
size_t term_count(vindex_t deg) const
static void set_seed(uint32_t seed=1)
Class to draw a simple undirected graph.
void add_edge(unsigned int node1, unsigned int node2)
Add an edge to the graph.
void draw(std::string filename)
Draw the graph in a file.
void add_node(int x, int y, const std::string &label="")
Add a node to the graph.
Class to generates a random map for the TSP with n nodes.
void gen_random_map(uint32_t n)
Generate a random map with n nodes.
Class to store the QUBO expression for the Traveling Salesman Problem (TSP).
Class to store a Tour of the TSP.
void print() const
Print the tour.
A class for defining the ABS2 callback function.
A class for setting parameters for the ABS2 QUBO solver.
A class for storing both the qbpp::QuadModel and abs2::Model.
A class for calling the ABS2 QUBO solver.
void set_time_limit(uint32_t time_limit)
Set the time limit for ABS2 QUBO solver.
Sol get_sol() const
Get the solution from the ABS2 solver.
Namespace to use ABS2 QUBO solver from QUBO++ library.
QUBO++, a C++ library for generating expressions for binary and spin variables.
QUBO++ interface to call ABS2 GPU QUBO solver.
A miscellaneous library used for sample programs of the QUBO++ library.
Generates a QUBO Expression for the Traveling Salesman Problem (TSP) using QUBO++ library.
int main(int argc, char **argv)
Main function to generate a random map and solve the Traveling Salesman Problem (TSP) using the ABS2 ...