7 #include <boost/program_options.hpp> 
   14 namespace po = boost::program_options;
 
   25     static std::optional<qbpp::energy_t> prev_energy = std::nullopt;
 
   27     if (!prev_energy.has_value() || sol.
get_energy() < prev_energy.value()) {
 
   29       std::cout << 
"TTS = " << std::fixed << std::setprecision(3)
 
   30                 << std::setfill(
'0') << tts << 
"s ";
 
   43 int main(
int argc, 
char **argv) {
 
   44   po::options_description desc(
 
   45       "Solve a randomly generated Traveling Salesman Problem (TSP) using the " 
   46       "QUBO++ Easy Solver.");
 
   49     (
"help,h", 
"Display this help message.")
 
   50     (
"nodes,n", po::value<uint32_t>()->default_value(10), 
"Specify the number of nodes in the TSP map.")
 
   51     (
"time,t", po::value<uint32_t>()->default_value(10), 
"Set the time limit in seconds.")
 
   52     (
"seed,s", po::value<uint32_t>(), 
"Set the random seed to reproduce the TSP map.")
 
   53     (
"output,o", po::value<std::string>(), 
"Specify the output file (e.g., png, svg) to save the TSP solution.")
 
   54     (
"fix,f", 
"Fix node 0 as the starting node.");
 
   59     po::store(po::parse_command_line(argc, argv, desc), vm);
 
   60   } 
catch (
const std::exception &e) {
 
   61     std::cout << 
"Wrong arguments. Please use -h/--help option to see the " 
   67   if (vm.count(
"help")) {
 
   68     std::cout << desc << std::endl;
 
   73   uint32_t nodes = vm[
"nodes"].as<uint32_t>();
 
   75   uint32_t time_limit = vm[
"time"].as<uint32_t>();
 
   77   bool fix_first = vm.count(
"fix");
 
   80   if (vm.count(
"seed")) {
 
   86   std::cout << 
"Generating random TSP Map with " << nodes << 
" nodes" 
   91   std::cout << 
"Generating a TSP QUBO expression" << std::endl;
 
   94   std::cout << 
"Variables = " << tsp_quad_model.
var_count()
 
   95             << 
" Linear Terms = " << tsp_quad_model.
term_count(1)
 
   96             << 
" Quadratic Terms = " << tsp_quad_model.
term_count(2)
 
   99   std::cout << 
"Generating an EasySolver object" << std::endl;
 
  104   std::cout << 
"Solving the TSP" << std::endl;
 
  105   auto sol = solver.
search();
 
  110   if (vm.count(
"output")) {
 
  112     for (uint32_t i = 0; i < nodes; ++i) graph.
add_node(tsp_map[i]);
 
  114     for (uint32_t i = 0; i < nodes; ++i)
 
  115       graph.
add_edge(tsp_sol[i], tsp_sol[(i + 1) % nodes]);
 
  117     graph.
draw(vm[
"output"].as<std::string>());
 
void callback(const qbpp::Sol &sol, double tts) const override
 
MyEasySolver(const qbpp::tsp::TSPQuadModel &tsp_quad_model)
 
const qbpp::tsp::TSPQuadModel & tsp_quad_model
 
vindex_t var_count() const
 
size_t term_count(vindex_t deg) const
 
energy_t get_energy() const
 
EasySolver(const qbpp::QuadModel &quad_model, std::shared_ptr< qbpp::SolHolder > sol_holder_ptr=nullptr)
 
std::mutex callback_mutex_
 
void set_time_limit(uint32_t limit)
 
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.
 
Generates a QUBO Expression for the Graph Coloring Problem using QUBO++ library.
 
QUBO++, a C++ library for generating expressions for binary and spin variables.
 
Easy QUBO Solver for solving QUBO problems.
 
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 Easy ...