簡體   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