【问题标题】:MiniZinc type error: all_different(array[int] of var int) not foundMiniZinc 类型错误:未找到 all_different(array[int] of var int)
【发布时间】:2015-07-09 19:03:13
【问题描述】:

我已经为我正在解决的标签问题创建了一个模型。除了找不到“all_different”谓词之外,一切都很好。错误出现在“约束”(2) 和 (3) 中,产生以下错误日志:

MiniZinc: type error: no function or predicate with this signature found: `all_different(array[int] of var int)'

我已经尝试了“all_different”和“alldifferent”,并且键签名“var int 的array[int]”与“all_different”的文档相匹配。注释掉 to 约束后,我没有其他问题。

知道可能出了什么问题吗?

我正在使用 MiniZincIDE 0.9.8 版。

%%%%%%%%%%%%%%%%%%%%%%%%%
% Parameter Definitions %
%%%%%%%%%%%%%%%%%%%%%%%%%

% Number of Solutions for Region
int: num_sols;

% Number of Adjacent Coordinates.
int: num_adj;

% Center Coordinate Name
string: center_name;

% Adjacent Coordinate Names.
array[1..num_adj] of string: adj_names;

% Center Coordinate Torsion Angles.
array[1..6] of float: center_tors;

% Adjacent Coordinate Torsion Angles.
array[1..num_adj,1..6] of float: adj_tors;

% Distances Between Solutions of Center and Adjacent Coordinates.
% [adj_coord,sol_num of adj_coord,sol_num of center_coord]
array[1..num_adj,1..num_sols,1..num_sols] of float: dists;

%%%%%%%%%%%%%%%%%%%%%%
% Decision Variables %
%%%%%%%%%%%%%%%%%%%%%%

%%% Symmetry Breaking %%%
% Layer Assignment for First Center Coordinate.
% array[1..num_sols] of int: center_layers = [i | i in 1..num_sols]

% Center Coordinate Layers
array[1..num_sols] of var int: center_layers;

% Center Coordinate Solution Assigned To Layers.
% (Inverse array of center_layers above)
array[1..num_sols] of var int: layers_center;

% Adjacent Coordinate Layers
% [adj_coord,sol_num] = layer_num
array[1..num_adj,1..num_sols] of var int: adj_layers;

% Adjacent Coorinate Solution Assigned To Layers.
% (Inverse array of layer_num above)
% [layer_num,adj_coord] = sol_num
array[1..num_sols,1..num_adj,] of var int: layers_adj;

% Distances Solutions Of the Same Layer.
% [layer_1,layer_2,..layer_3]
array[1..num_sols] of var float: layers_dists;

%%%%%%%%%%%%%%%%%%%%%%%
% Variable Assignment %
%%%%%%%%%%%%%%%%%%%%%%%

% (1) Match adj_layers and layers_adj

constraint forall(i in 1..num_adj, j in 1..num_sols)
    (layers_adj[adj_layers[i,j],i] = j);

% (2) Match center_layers and layers_center

constraint forall(i in 1..num_sols)
    (layers_center[center_layers[i]] = i);

% (3) For Each Layer, Sum The Distances Between Center Coordinate Solution    and
% Adjacent Coordinates

constraint forall(i in 1..num_sols)
    (layers_dists[i] = sum(j in 1..num_adj)
        (dists[j, layers_adj[i,j], layers_center[i]])
    );

%%%%%%%%%%%%%%%
% Constraints %
%%%%%%%%%%%%%%%

% (1) All Layers Must Be Within Layer Range

constraint forall(i in 1..num_sols)
    (center_layers[i] <= num_sols /\ center_layers[i] >= 1);

constraint forall(i in 1..num_adj,j in 1..num_sols)
  (adj_layers[i,j] <= num_sols /\ adj_layers[i,j] >= 1);

% (2) The Center Coordinate Solutions Must Have Unique Layers.

constraint all_different(center_layers);

% (3) For Each Adjacent Coordinate, The Solutions Must Have Unique Layers.

constraint forall(i in 1..num_adj) (all_different(row(adj_layers,i)));

%%%%%%%%%%%%%%%%%%%%%%
% Objective Function %
%%%%%%%%%%%%%%%%%%%%%%

solve minimize sum(layers_dists);

【问题讨论】:

    标签: minizinc


    【解决方案1】:

    将此添加到您的模型中:

    include "globals.mzn";
    

    这包括全局约束的定义,例如 all_different。

    提示:如果可能,您应该避免使用“var int”。而是尝试为决策变量定义适当的域。这通常会加速模型,因为求解器不必处理不相关的域。

    【讨论】:

    • 感谢您的建议!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-09-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-31
    相关资源
    最近更新 更多