Here are two examples from our
website:
nqueens0.mod is an integer programming model for the n-queens problem. The variables X[i,j] are 1 if there is a queen in row i and column j, and 0 otherwise. You can send this formulation to any solver that accepts integer variables.
nqueens.mod is a much more compact formulation that uses AMPL's
alldiff operator. The variables Row[j] give the number of the row in which column j's queen is placed. Originally, this formulation could only be sent to
constraint programming solvers, but now it is recognized by integer programming solvers that use our new MP interface; currently these include x-gurobi, copt, and highs (all available in our standard distribution from
portal.ampl.com), with more to come.
For the 8-queens problem, just set parameter n to 8.