作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
picat
求解器 (v. 2.6#2
) 指出示例模型 knights.mzn
包含在 minizinc 存储库中,特此复制粘贴:
% RUNS ON mzn20_fd
% RUNS ON mzn-fzn_fd
% RUNS ON mzn20_mip
% knights.mzn
% Ralph Becket
% vim: ft=zinc ts=4 sw=4 et
% Tue Aug 26 14:24:28 EST 2008
%
% Find a closed knight's tour of a chessboard (every square is visited exactly
% once, the tour forms a loop).
include "globals.mzn";
% n is the length of side of the chessboard.
%
int: n = 6;
% The ith square (r, c) on the path is given by p[i] = (r - 1) * n + c.
%
int: nn = n * n;
set of int: sq = 1..nn;
array [sq] of var sq: p;
set of int: row = 1..n;
set of int: col = 1..n;
% Break some symmetry by specifying the first and last moves.
%
constraint p[1] = 1;
constraint p[2] = n + 3;
constraint p[nn] = 2 * n + 2;
% All points along the path must be unique.
%
constraint alldifferent(p);
array [sq] of set of sq: neighbours =
[ { n * (R - 1) + C
|
i in 1..8,
R in {R0 + [-1, -2, -2, -1, 1, 2, 2, 1][i]},
C in {C0 + [-2, -1, 1, 2, 2, 1, -1, -2][i]}
where R in row /\ C in col
}
| R0 in row, C0 in col
];
constraint forall (i in sq where i > 1) (p[i] in neighbours[p[i - 1]]);
solve
:: int_search(
p,
input_order,
indomain_min,
complete
)
satisfy;
% It has been observed that Warnsdorf's heuristic of choosing the next
% square as the one with the fewest remaining neighbours leads almost
% directly to a solution. How might we express this in MiniZinc?
output ["p = " ++ show(p) ++ ";\n"];
% Invert the path to show the tour.
%
% array [sq] of var sq: q;
%
% constraint forall (i in sq) (q[p[i]] = i);
%
% output [ show(q[i]) ++ if i mod n = 0 then "\n" else " " endif
% | i in sq
% ] ++
% [ "\n"
% ];
~$ mzn2fzn knights.mzn
~$ picat tools/picat/fzn_picat_cp.pi knights.fzn
% solving(knights.fzn)
% loading knights.fzn
=====UNSATISFIABLE=====
~$ mzn2fzn knights.mzn
~$ picat tools/picat/fzn_picat_sat.pi knights.fzn
% solving(knights.fzn)
% loading knights.fzn
=====UNSATISFIABLE=====
MiniZinc
求解器,除了
fzn2smt
基于
Yices
(v.
2.2.1
),告诉我模型是可满足的。
最佳答案
Picat 在这个模型上失败的原因是它 - 或者更确切地说是生成的 FlatZinc 模型 - 包含“var set”变量(见下文),而这些变量在 Picat 中不受支持。
var set of 1..36: X_INTRODUCED_36_ ::var_is_introduced :: is_defined_var;
var set of 1..36: X_INTRODUCED_38_ ::var_is_introduced :: is_defined_var;
var set of 1..36: X_INTRODUCED_39_ ::var_is_introduced :: is_defined_var;
Error: LazyGeoff: set variables not supported in line no. 72
nosets
标准库中的文件。该文件将确保所有设置的变量都被转换为多个 bool 变量。理想情况下,此文件将包含在求解器 MiniZinc
redefinitions.mzn
中文件,但您始终可以通过添加以下行直接从模型中包含此文件:
include "nosets.mzn";
关于minizinc - 为什么picat说模型不满足?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57394101/
在介绍性练习中,我的目标是生成 0, 1 值的模式,受各种约束。虽然下面的代码与内置 sum/1 函数一起工作正常,但它在手工制作的 sum1/1 版本中失败(invalid_constraint_e
我有兴趣计算问题的解决方案数量(不列举解决方案)。为此,我有使用 CNF 的工具。文件。我要转换 Minizinc文件(mzn 或 Flatzinc fzn 格式)并将其转换为 CNF。 我学会了Pi
我是一名优秀的程序员,十分优秀!