我正在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];发布于 2020-12-07 23:49:12
造成问题的原因是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 exceededsum表达式可以通过两种方式大于32位:
amt域。这意味着和的域也将跨越整个64位。。
因此,解决问题的方法是为amt变量设置初始域。
https://stackoverflow.com/questions/65190862
复制相似问题