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

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

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

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

我一直在阅读有关使用 Gecode 浮动变量的一些限制,但我不知道问题是出在求解器上还是出在我的代码(随附)上。我已经尝试将所有更改为整数变量,但资源要求是浮点参数。我也尝试过更改解算器,但 none 已经奏效(没有可用的 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];

你的问题的原因是 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 变量设置一个初始域。