leo
leo

Reputation: 3749

Minizinc "cannot determine lower bound" for float

I have a minizinc model where I have a distance matrix:

array[1..n, 1..n] of var float: dist;

Which will output the error Error: Gecode: Float::linear: Number out of limits. If I try to minimize the the matrix for example with solve minimize sum(i,j in 1..n)(dist[i,j]); (in reality the code is more complex).The lower bound is clear to me. No value in the distance matrix can be lower than zero. Formulating a constraint with the lowerbound will however not work:

constraint forall(i,j in 1..n)(dist[i,j] >= 0.0);

Making the domain smaller will work. But I can not say ahead of time what will be the upper bound of the domain (for the code bellow I just took a very big number, which might in certain cases be too small):

array[1..n, 1..n] of var 0.0..1000000.0: dist;

Is there a posibility to only define the lower bound?

I use Minizinc 2.2.1 with geocode 6.0.1.

Upvotes: 1

Views: 394

Answers (1)

Andrea Rendl-Pitrey
Andrea Rendl-Pitrey

Reputation: 508

You are getting the Error: Gecode: Float::linear: Number out of limits because Gecode (and any other CP solver) will need an upper and lower bound for every variable. In your objective you are summing over variables that each ranges from 0.0..1000000.0. Internally, MiniZinc creates a variable for this sum expression, and the domain of this variable exceeds Gecode's internal bounds.

So I see two solutions for solving this issue:

1) Create the objective variable yourself and set an upper bound for it. The following model works for me on MiniZinc 2.2.1 and Gecode 6.0.1:

int: n = 3;
array[1..n, 1..n] of var 0.0..100000.0: dist; 
% a new variable for the objective term with a lower and upper bound
var 0.0..1000000.0: total_distance;  

constraint forall(i,j in 1..n)(dist[i,j] >= 0.0);

constraint    % set the objective term
   total_distance = sum(i,j in 1..n)(dist[i,j]);

solve minimize total_distance;

2) Don't use a CP solver, but use a MIP (Mixed Integer Programming) solver. They can deal with variables that have infinite bounds. MiniZinc comes with the MIP solver CBC, and it solves the following MiniZinc model without problems:

int: n = 3;
array[1..n, 1..n] of var float: dist;

constraint forall(i,j in 1..n)(dist[i,j] >= 0.0);

solve minimize sum(i,j in 1..n)(dist[i,j]);

Upvotes: 4

Related Questions