7 #include <boost/program_options.hpp>
13 namespace po = boost::program_options;
22 int main(
int argc,
char *argv[]) {
24 po::options_description desc(
25 "N-Queens Problem Solver using QUBO++ Easy Solver");
26 desc.add_options()(
"help,h",
"produce help message")
27 (
"dimension,d", po::value<int>()->default_value(8),
"set dimension of the chessboard")
28 (
"time_limit,t", po::value<int>()->default_value(10),
"set time limit in seconds")
29 (
"seed,s", po::value<int>(),
"set random seed")
30 (
"expand,e",
"expand the one-hot formula for QUBO model generation")
31 (
"fast,f",
"fast mode for QUBO model generation")
32 (
"parallel,p",
"parallel mode for QUBO model generation (default)");
37 po::store(po::parse_command_line(argc, argv, desc), vm);
38 }
catch (
const std::exception &e) {
39 std::cout <<
"Wrong arguments. Please use -h/--help option to see the "
45 if (vm.count(
"help")) {
46 std::cout << desc << std::endl;
50 int dimension = vm[
"dimension"].as<
int>();
51 int time_limit = vm[
"time_limit"].as<
int>();
54 if (vm.count(
"seed")) {
59 if (vm.count(
"expand")) {
61 }
else if (vm.count(
"fast")) {
63 }
else if (vm.count(
"parallel")) {
71 std::cout <<
"Generating the QUBO model." << std::endl;
73 std::cout <<
"Variables = " << nqueen_model.
var_count()
74 <<
" Linear Terms = " << nqueen_model.
term_count(1)
75 <<
" Quadratic Terms = " << nqueen_model.
term_count(2) << std::endl;
77 std::cout <<
"Generating an EasySolver object for the QUBO model."
80 solver.set_time_limit(time_limit);
81 solver.set_target_energy(0);
82 solver.enable_default_callback();
84 std::cout <<
"Executing the EasySolver to solve the QUBO model." << std::endl;
85 auto sol = solver.search();
88 for (
int i = 0; i < dimension; ++i) {
89 for (
int j = 0; j < dimension; ++j)
90 std::cout <<
static_cast<int>(sol.get(nqueen_model.
get_var(i, j)));
91 std::cout << std::endl;
94 std::cout <<
"Dimension = " << dimension <<
" TTS = " << std::fixed
95 << std::setprecision(3) << std::setfill(
'0') << solver.get_tts()
96 <<
"s Energy = " << sol.get_energy() << std::endl;
vindex_t var_count() const
size_t term_count(vindex_t deg) const
static void set_seed(uint32_t seed=1)
Class to generate a QUBO model for the N-Queens problem.
qbpp::Var get_var(int i, int j) const
Gets the variable at (i, j)
int main(int argc, char *argv[])
Solves the N-Queens problem using EasySolver in the QUBO++ library. library.
QUBO++, a C++ library for generating expressions for binary and spin variables.
Easy QUBO Solver for solving QUBO problems.
Generates QUBO expression for the N-Queens problem using the QUBO++ library.