【问题标题】:Why picat says that the model is unsatisfiable?为什么picat说模型不能满足?
【发布时间】:2019-08-07 12:04:12
【问题描述】:

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=====

除基于Yices(v.2.2.1)的fzn2smt 之外的所有其他MiniZinc 求解器都告诉我模型是可满足的。

问:这是软件中的错误还是不支持的公式的样本?

【问题讨论】:

    标签: minizinc picat


    【解决方案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;
    

    理想情况下,Picat 应该给出更好的错误消息,例如“不支持设置变量”。

    请注意,许多 FlatZinc 求解器不支持设置变量。例如,Chuffed 在模型上抛出了这个好消息:

    Error: LazyGeoff: set variables not supported in line no. 72
    

    本身不支持设置变量的求解器可以包含标准库中的nosets 文件。该文件将确保将所有设置变量转换为多个布尔变量。理想情况下,此文件将包含在求解器 MiniZinc redefinitions.mzn 文件中,但您始终可以通过添加以下行直接从您的模型中包含此文件:

    include "nosets.mzn"; 
    

    【讨论】:

    • 谢谢。错误消息确实会更好。
    • @hakank @PatrickTrentin 包含include "nosets.mzn"; 会将所有设置变量转换为多个布尔变量。它可以添加到模型或求解器库中的重新定义文件中。 Picat 可以考虑这样做。像 chuffed、CBC、Gurobi 这样的求解器使用它,它似乎翻译得很好。
    • @Dekker1 谢谢!我还有一个问题:minizinc 比赛中使用了 include 吗?
    • 否,但在 MiniZinc 挑战赛中使用的模型规范规定只能使用布尔变量和整数变量。由于对浮点和集合变量的支持有限,这些不包括在挑战中
    猜你喜欢
    • 2019-10-29
    • 1970-01-01
    • 1970-01-01
    • 2019-09-12
    • 1970-01-01
    • 2014-01-12
    • 2012-06-20
    • 2013-07-08
    相关资源
    最近更新 更多