New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Help moving model to float (arithmetic error: arithmetic operation on infinite value) #138

Closed
wvrius opened this Issue Jan 29, 2017 · 0 comments

Comments

Projects
None yet
1 participant
@wvrius

wvrius commented Jan 29, 2017

Hi,

I'm trying to solve a constraints problem using MiniZinc, and I'm encountering an issue while trying to move my model to use floats.

This is my first time using MiniZinc, so I might be misusing it or making a silly mistake.

Problem: Given a matrix with products X feature weights, select multiple products that respect the sum constraints. One product can be chosen multiple times.

I started from the Knapsack example, here: https://github.com/MiniZinc/minizinc-examples/blob/master/knapsack/knapsack01.mzn, removed solving for maximizing profit and generalized for nFeatures.

Model:

int: nProducts; 
int: nFeatures;
int: nMatrix = nProducts * nFeatures;

array[1..nMatrix] of int: featuresMatrix;

array[1..nFeatures] of int: maxCons;
array[1..nFeatures] of int: minCons;

set of int: Products = 1..nProducts;
set of int: Features = 1..nFeatures;

array[Features] of var int: featureUsage;
array[Products] of var int: productsTaken; 

constraint forall(k in Features) (
    featureUsage[k] = sum(i in Products)(featuresMatrix[((k-1)*nProducts)+i] * productsTaken[i])
);

constraint forall(k in Features) (
    if minCons[k] != -1 then
     featureUsage[k] >= minCons[k]
    else 
      true
    endif
);

constraint forall(k in Features) (
    if maxCons[k] != -1 then
      featureUsage[k] <= maxCons[k]
    else
      true
    endif
);

constraint forall(i in Products)( productsTaken[i] <= 2); 
constraint forall(i in Products)( productsTaken[i] >= 0); 

constraint sum(i in Products)(productsTaken[i]) > 0; 
constraint sum(i in Products)(productsTaken[i]) < 100; 

solve satisfy;

Input data:

nProducts = 5;
nFeatures = 2;

featuresMatrix = [
1300,1000,520,480,325,
20,10,30,40,33
];

maxCons = [
2300,
-1
];

minCons = [
2300,
-1
];

The model executes correctly for integer inputs, but I need the model to work with floats instead.
Trying to do so, I changed to following declarations to float.

array[1..nMatrix] of float: featuresMatrix;
array[1..nFeatures] of float: maxCons;
array[1..nFeatures] of float: minCons;

array[Features] of var float: featureUsage;

but I'm getting the following error:
MiniZinc: arithmetic error: arithmetic operation on infinite value

Am I doing something wrong?

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment