【问题标题】:Error: Gecode: Float::linear: Number out of limits错误:Gecode:Float::linear:数量超出限制
【发布时间】:2020-12-07 23:18:45
【问题描述】:

我正在 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];

【问题讨论】:

标签: minizinc gecode


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2016-09-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-11-14
    • 2010-11-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多