gpt4 book ai didi

MiniZinc 类型错误 : all_different(array[int] of var int) not found

转载 作者:行者123 更新时间:2023-12-03 22:21:56 28 4
gpt4 key购买 nike

我已经为我正在解决的标签问题创建了一个模型。除了找不到“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”, key 签名“array[int] of var 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);

最佳答案

将此添加到您的模型中:

include "globals.mzn";

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

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

关于MiniZinc 类型错误 : all_different(array[int] of var int) not found,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31326097/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com