繁体   English   中英

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

[英]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:类型错误:“total_distance”的初始化值的类型无效:预期为“float”,实际为“var float”

我想这是因为说next_point被用于计算total_distancenext_point是一个决策变量( var ),这意味着total_distance需求太? 但是,如果我将float: total_distance...更改为var float: total_distance...我在其他地方遇到了一个新错误:

MiniZinc:类型错误:'points' 的初始化值的类型无效:预期的 'array[int] of int',实际的 '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一个问题:它被声明为一个单一的数组,但在“数据”部分它被定义为一个二维矩阵。 第二列(包含值 0.5 的列)有什么用?

暂无
暂无

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

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