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

320 views Asked by At

I am building a simple model on Minizinc 2.5.3 (latest version) and Gecode 6.3.0 to try and organize a weapons production operation. When running the code, the following error appears:

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

I've been reading about some limitations to float variables with Gecode, but I don't know whether the problem is with the solver or with my code (attached). I've tried changing all to integer variables but the resource requirements are floating point parameters. I've also tried to change the solver but none of them have worked (there is no MIP solver available).

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];

I am using the following data file:

%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];
1

There are 1 answers

0
Dekker1 On BEST ANSWER

The cause of your problem is that floating point variables in Gecode are limited to 32 bits. This means that some problems that can be created in MiniZinc (which support 64 bit floating point numbers) cannot be solved by Gecode.

In your problem this is caused by

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

The sum expressions can be bigger than 32 bits in two ways:

  • It depends on consumption numbers that could potentially be big (in the sample input you give this does not seem to be the case).
  • It depends on the domain of amt, which is currently not set. This means that the domain of the sum would also span the full 64 bits.

The way to solve it in your problem is thus to set an initial domain for the amt variables.