10 #ifndef QBPP_NQUEEN_HPP 
   11 #define QBPP_NQUEEN_HPP 
   44     for (
int i = 0; i < 2 * dim - 3; i++) {
 
   46       for (
int j = 0; j < dim; j++) {
 
   47         if (k - j >= 0 && k - j < dim) {
 
   52       for (
int j = 0; j < dim; j++) {
 
   53         if (l + j >= 0 && l + j < dim) {
 
   75     for (
int x = 0; x < dim; ++x) {
 
   76       for (
int y = 0; y < dim; ++y) {
 
   79         for (
int i = x + 1; i < dim; ++i) {
 
   81           expr += X[x][y] * X[i][y];
 
   83         for (
int j = y + 1; j < dim; ++j) {
 
   85           expr += X[x][y] * X[x][j];
 
   87         for (
int d = 1; d < dim - x; ++d) {
 
   90             expr += X[x][y] * X[x + d][y - d];
 
   94             expr += X[x][y] * X[x + d][y + d];
 
  107     tbb::parallel_for(0, dim, [&](
int x) {
 
  108       for (
int y = 0; y < dim; ++y) {
 
  111         for (
int i = x + 1; i < dim; ++i) {
 
  113           exprs[x] += X[x][y] * X[i][y];
 
  115         for (
int j = y + 1; j < dim; ++j) {
 
  117           exprs[x] += X[x][y] * X[x][j];
 
  119         for (
int d = 1; d < dim - x; ++d) {
 
  122             exprs[x] += X[x][y] * X[x + d][y - d];
 
  126             exprs[x] += X[x][y] * X[x + d][y + d];
 
  139   std::tuple<qbpp::QuadModel, int, Vector<Vector<qbpp::Var>>>
 
  150       throw std::runtime_error(
"Invalid mode");
 
  162         X_(std::get<2>(tuple)) {}
 
Expr & simplify_as_binary()
 
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)
 
NQueenQuadModel(int dim, Mode mode)
Constructor: Creates an N-Queens QUBO expression.
 
const int dim_
Dimension of the chessboard.
 
const Vector< Vector< qbpp::Var > > X_
2-dimensional vector of qbpp::Var representing the chessboard
 
static qbpp::QuadModel expand_mode(int dim, const Vector< Vector< qbpp::Var >> &X)
Generates qbpp::Expr for the N-Queens problem.
 
NQueenQuadModel(std::tuple< qbpp::QuadModel, int, Vector< Vector< qbpp::Var >>> &&tuple)
Constructor to initialize member variables.
 
std::tuple< qbpp::QuadModel, int, Vector< Vector< qbpp::Var > > > helper_func(int dim, Mode mode)
Helper function to compute initial values for member variables.
 
static qbpp::QuadModel parallel_mode(int dim, const Vector< Vector< qbpp::Var >> &X)
Generates the QUBO expression for the N-Queens problem using TBB in parallel.
 
static qbpp::QuadModel fast_mode(int dim, const Vector< Vector< qbpp::Var >> &X)
Generates the QUBO expression for the N-Queens problem.
 
Generates a QUBO Expression for the Graph Coloring Problem using QUBO++ library.
 
Expr vector_sum(const T &items[[maybe_unused]])
 
Var var(const std::string &var_str)
 
Vector< Vector< Expr > > transpose(const Vector< Vector< T >> &vec)
 
Expr sum(const Vector< T > &items)
 
Expr simplify_as_binary(const Expr &expr)
 
QUBO++, a C++ library for generating expressions for binary and spin variables.