I am really new to CVXPY. I am trying to solve the 8 queens problem, i.e., the problem of placing 8 chess queens on an 8 x 8 chessboard so that no two queens threaten each other. As I understand it, the constrainsts should be:
- sum of each row equals to 1.
- sum of each column equals to 1.
- sum of each diagonal equals to 1.
- all variables should be larger than 0.
Moreover, the objective function should be: maximize the 2-norm of the matrix (so that we get only 1's and 0's, because we can get a sum of 1 also with float
s, but norm of 1 with zeros is larger than norm of floats between 0 to 1 that also sum up to 1 (for example: 0.8^2+0.2^2 < 1^2+0^2).
Is it possible to solve this kind of problem in CVXPY? I am pretty clueless on how to form the constraints and the objective function in CVXPY, but here are my initial initial attempts (I immediately got a "DCP Error" so I had no reason to continue, but still):
from cvxpy import *
x=Variable(shape=(9,9), name='board')
obj = Maximize(norm(x))
const = [sum(x, axis=1)==1]
prob=Problem(objective=obj,constraints=const)
prob.solve()
Any help will be appreciated!!!