summaryrefslogtreecommitdiff
path: root/glpk-5.0/examples/queens.mod
diff options
context:
space:
mode:
authorPasha <pasha@member.fsf.org>2023-01-27 00:54:07 +0000
committerPasha <pasha@member.fsf.org>2023-01-27 00:54:07 +0000
commitef800d4ffafdbde7d7a172ad73bd984b1695c138 (patch)
tree920cc189130f1e98f252283fce94851443641a6d /glpk-5.0/examples/queens.mod
parentec4ae3c2b5cb0e83fb667f14f832ea94f68ef075 (diff)
downloadoneapi-ef800d4ffafdbde7d7a172ad73bd984b1695c138.tar.gz
oneapi-ef800d4ffafdbde7d7a172ad73bd984b1695c138.tar.bz2
simplex-glpk with modified glpk for fpgaHEADmaster
Diffstat (limited to 'glpk-5.0/examples/queens.mod')
-rw-r--r--glpk-5.0/examples/queens.mod41
1 files changed, 41 insertions, 0 deletions
diff --git a/glpk-5.0/examples/queens.mod b/glpk-5.0/examples/queens.mod
new file mode 100644
index 0000000..3f446ce
--- /dev/null
+++ b/glpk-5.0/examples/queens.mod
@@ -0,0 +1,41 @@
+/* QUEENS, a classic combinatorial optimization problem */
+
+/* Written in GNU MathProg by Andrew Makhorin <mao@gnu.org> */
+
+/* The Queens Problem is to place as many queens as possible on the 8x8
+ (or more generally, nxn) chess board in a way that they do not fight
+ each other. This problem is probably as old as the chess game itself,
+ and thus its origin is not known, but it is known that Gauss studied
+ this problem. */
+
+param n, integer, > 0, default 8;
+/* size of the chess board */
+
+var x{1..n, 1..n}, binary;
+/* x[i,j] = 1 means that a queen is placed in square [i,j] */
+
+s.t. a{i in 1..n}: sum{j in 1..n} x[i,j] <= 1;
+/* at most one queen can be placed in each row */
+
+s.t. b{j in 1..n}: sum{i in 1..n} x[i,j] <= 1;
+/* at most one queen can be placed in each column */
+
+s.t. c{k in 2-n..n-2}: sum{i in 1..n, j in 1..n: i-j == k} x[i,j] <= 1;
+/* at most one queen can be placed in each "\"-diagonal */
+
+s.t. d{k in 3..n+n-1}: sum{i in 1..n, j in 1..n: i+j == k} x[i,j] <= 1;
+/* at most one queen can be placed in each "/"-diagonal */
+
+maximize obj: sum{i in 1..n, j in 1..n} x[i,j];
+/* objective is to place as many queens as possible */
+
+/* solve the problem */
+solve;
+
+/* and print its optimal solution */
+for {i in 1..n}
+{ for {j in 1..n} printf " %s", if x[i,j] then "Q" else ".";
+ printf("\n");
+}
+
+end;