MiniZinc类型错误:没有找到all_different(array[int] of var int)



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

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

我尝试了'all_different'和'alldifferent',关键签名'array[int] of var int'匹配'all_different'的文档。在注释了这些约束之后,我没有其他问题。

你知道有什么问题吗?

我使用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);

添加到你的模型:

include "globals.mzn";

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

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

最新更新