我如何修改它以在 MiniZinc 中编译:
output [[show (P[j,p]) ++ "\n" | p in 1 .. 4] | j in 1 .. 4];
我尝试了几种方法。
这取决于你想做什么。以下是一些将 P 写为矩阵的不同方法。第一个将矩阵写为列表([...]),第二个仅输出值。
output [
show([P[j,p] | p in 1 .. 4]) ++ "\n"
| j in 1 .. 4
];
output [
if p = 1 then "\n" else " " endif ++
show(P[j,p])
| j in 1 .. 4, p in 1 .. 4
];
更新:在 MiniZinc 2.0 中(至少在最近的 Git 版本中),现在有一个 show2d 谓词:
output [ show2d(P)];