Minizinc error: invalid type-inst: expected `float', actual `var float'

Minizinc error: invalid type-inst: expected `float', actual `var float'

我有以下 Minizinc 程序,它正在努力解决旅行商问题 (TSP)。我知道它遗漏的不仅仅是修复这个错误,但我仍然想了解为什么我会收到这个错误。下面的可重现示例:

include "globals.mzn";

% Input Parameters 
int: NUM_POINTS;
float: MAX_TOTAL_DISTANCE;
array[0..NUM_POINTS-1] of int: points;
array[0..NUM_POINTS-1, 0..NUM_POINTS-1] of float: distance_matrix;

% Decision Variable: where to go next, from each point (indexed on points)
array[0..NUM_POINTS-1] of var 0..NUM_POINTS-1: next_point;  

% Constraints that define a valid tour
constraint alldifferent(next_point);  % each point only visited once
constraint next_point[NUM_POINTS-1] == points[0];  % not sure if this is helpful or not?

% see if we can find a feasible solution below max-total-distance
float: total_distance = sum(p in points)(distance_matrix[points[p],next_point[p]]);
constraint total_distance < MAX_TOTAL_DISTANCE;
solve satisfy;

output[show(total_distance) ++ "\n" ++ show(next_point)];

我得到的错误是:

MiniZinc: type error: initialisation value for 'total_distance' has invalid type-inst: expected 'float', actual 'var float'

我猜是说因为next_point用于total_distance的计算,而next_point是一个决策变量(var),也就是说total_distance 也需要吗?但是,如果我将 float: total_distance... 更改为 var float: total_distance...,我会在其他地方收到一个新错误:

MiniZinc: type error: initialisation value for 'points' has invalid type-inst: expected 'array[int] of int', actual 'array[int,int] of float'

我可以不根据函数(例如求和)、参数和决策变量来定义变量吗?我想我在这里遗漏了一些基本的东西。 (下面的示例数据用于可重现的示例):

% DATA (in my setup this is in a dzn file)
NUM_POINTS = 5;
points = [|
0, 0|
0, 0.5|
0, 1|
1, 1|
1, 0|];
distance_matrix = [|
0.0, 0.5, 1.0, 1.41, 1.0 |
0.5, 0.0, 0.5, 1.12, 1.12 |
1.0, 0.5, 0.0, 1.0, 1.41 |
1.41, 1.12, 1.0, 0.0, 1.0 |
1.0, 1.12, 1.41, 1.0, 0.0 |];

关于如何使用和声明 points 的一个问题:它被声明为单数组,但在 "DATA" 部分中它被定义为二维矩阵。第二列(包含值 0.5 的那一列)有什么用?