简体   繁体   中英

MiniZinc type error: all_different(array[int] of var int) not found

I've created a model for a labeling problem I'm solving. Everything works great except that the 'all_different' predicate can't be found. The error arises in 'Constraints' (2) and (3), producing the following error log:

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

I've tried both 'all_different' and 'alldifferent', and the key signature 'array[int] of var int' matches the documentation for 'all_different'. I have no other issues after commenting out the to constraints.

Any idea what could be wrong?

I'm using MiniZincIDE Version 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);

Add this to your model:

include "globals.mzn";

This includes the definitions for global constraints, such as all_different.

A tip: If possible you should avoid using "var int". Try instead to define appropriate domains for the decision variables. This will often speed up the model since the solvers don't have to deal will irrelevant domains.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM