简体   繁体   English

Minizinc 错误:无效的类型插入:预期的“浮动”,实际的“浮动浮动”

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

I have the following Minizinc program which is a work in progress towards being a solution for the Traveling Salesman Problem (TSP).我有以下 Minizinc 程序,它正在努力解决旅行商问题 (TSP)。 I know it's missing more than just fixing this error, but I would still like to understand why I'm getting this error.我知道它所缺少的不仅仅是修复此错误,但我仍然想了解为什么我会收到此错误。 Reproduceable example below:下面的可复制示例:

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)];

The error I'm getting is:我得到的错误是:

MiniZinc: type error: initialisation value for 'total_distance' has invalid type-inst: expected 'float', actual 'var float' MiniZinc:类型错误:“total_distance”的初始化值的类型无效:预期为“float”,实际为“var float”

I guess it's saying because next_point is used in the calculation of total_distance , and next_point is a decision variable ( var ), that means total_distance needs to be too?我想这是因为说next_point被用于计算total_distancenext_point是一个决策变量( var ),这意味着total_distance需求太? But if I change float: total_distance... to var float: total_distance... I get a new error elsewhere on points:但是,如果我将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' MiniZinc:类型错误:'points' 的初始化值的类型无效:预期的 'array[int] of int',实际的 'array[int,int] of float'

Can I just not define a variable based on a function (eg sum across) a parameter and a decision variable?我可以不定义基于函数(例如求和)、参数和决策变量的变量吗? I think I'm missing something fundamental here.我想我在这里遗漏了一些基本的东西。 (Example data below for a reproduceable example): (以下示例数据为可复制示例):

% 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 |];

One problem in how you use and declare points : It is declared as a singe array but in the "DATA" section it is defined as a 2d matrix.如何使用和声明points一个问题:它被声明为一个单一的数组,但在“数据”部分它被定义为一个二维矩阵。 What is the use of the second column, the one that contain the value of 0.5?第二列(包含值 0.5 的列)有什么用?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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