0

我正在 Minizinc 2.5.3(最新版本)和 Gecode 6.3.0 上构建一个简单的模型,以尝试组织武器生产操作。运行代码时,出现如下错误:

Error: Gecode: Float::linear: Number out of limits

我一直在阅读有关使用 Gecode 浮动变量的一些限制,但我不知道问题出在求解器还是我的代码(附加)。我尝试将所有变量更改为整数变量,但资源要求是浮点参数。我也尝试过更改求解器,但没有一个起作用(没有可用的 MIP 求解器)。

enum WEAPONS; %product
enum RESOURCES; %resources

array [RESOURCES] of float: capacity; %resource constraints
array [WEAPONS] of float: pwr; %profit/objective
array [WEAPONS,RESOURCES] of float: consumption; %consumption of resources for each product unit
array [WEAPONS] of var int: amt; %amount to produce

constraint forall(i in WEAPONS)(amt[i]>=0); %non-negative
constraint forall(r in RESOURCES)(sum(i in WEAPONS)(consumption[i,r]*amt[i])<=capacity[r]); %availability of resources must not be exceeded

solve maximize sum(i in WEAPONS)(pwr[i]*amt[i]);

output ["\(i): \(amt[i])\n" | i in WEAPONS];

我正在使用以下数据文件:

%Product
WEAPONS = {AXE, SWORD, PIKE, SPEAR, CLUB};
%Resoruces
RESOURCES = {IRON, WOOD, BLACKSMITHHR, CARPENTERHR};
%capacity
capacity = [5000, 7500, 4000, 3000];
%consumption: [Product,Resources]
consumption = [| 1.5, 1, 1, 1 
               | 2, 0, 2, 0 
               | 1.5, 0.5, 1, 1 
               | 0.5, 1, 0.9, 1.5 
               | 0.1, 2.5, 0.1, 2.5 |];
%profit
pwr = [11, 18, 15, 17, 11];
4

1 回答 1

3

问题的原因是 Gecode 中的浮点变量限制为 32 位。这意味着一些可以在 MiniZinc(支持 64 位浮点数)中创建的问题,Gecode 无法解决。

在您的问题中,这是由

constraint forall(r in RESOURCES)(sum(i in WEAPONS)(consumption[i,r]*amt[i])<=capacity[r]); %availability of resources must not be exceeded

表达式可以通过sum两种方式大于 32 位:

  • 这取决于可能很大的消费数字(在您提供的示例输入中似乎并非如此)。
  • 它取决于amt当前未设置的 的域。这意味着和的域也将跨越完整的 64 位。

因此,在您的问题中解决它的方法是为amt变量设置一个初始域。

于 2020-12-07T23:49:12.993 回答