⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 queens.mod

📁 著名的大规模线性规划求解器源码GLPK.C语言版本,可以修剪.内有详细帮助文档.
💻 MOD
字号:
/* QUEENS, a classic combinatorial optimization problem *//* Written in GNU MathProg by Andrew Makhorin <mao@mai2.rcnet.ru> *//* 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;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -