0

In a model that I've written in MiniZincIDE 0.9.9, the following constraint throws a "cannot determine bounds" error during array comprehension:

constraint forall(i in Layers)(
layDists[i] == sum(
   [Dists[find(a,b,c,d)] | a in Coords, c in Layers, b in Coords, d in Layers
      where coordSolLays[a,c] == i ]));

where

array[Coords,Layers] of var Layers: coordSolLays;
array[Layers] of var 0..10000000: layDists;

function var 1..length(Dists): find(var int: a, var int: b, var int: c, var int: d) = 
    adjIndex[a] + (d-1) + (c-1)*numLays + (b-1)*numLays2;

and adjIndex and Dists are parameter arrays.

The error itself reads:

MiniZinc: evaluation error: 
.../model.mzn:206:
in call 'forall'
in array comprehension expression
with i = 1
.../model.mzn:207:
in binary '=' operator expression
in call 'sum'
.../model.mzn:208:
in array comprehension expression
with a = 1
with c = 1
with b = 1
with d = 1
cannot determine bounds

I'm aware that the error is generally thrown when variable bounds can't be determined (MiniZinc "cannot determine bounds"), however, all of the constraint variables are bound.

I suspect the issue is with find(a,b,c,d), coordSolLays[a,b], and/or their interaction, since replacing one or both of them with integers or simple variables (i.e. a,b,i) yields a solution.

Any ideas of what might be happening? Thanks in advance!

Community
  • 1
  • 1
user123403
  • 31
  • 4

1 Answers1

0

In the comments of this post there is a note that some early versions of MiniZinc had problems with some bounds. I tried your code (with random values for the variables you did not specify) in MiniZinc 1.6 and it works there, so it might be a bug in MiniZinc 2.0.5.

These kind of problems generally arise when the length of an array expressions depends on a variable. For example

var int : a;
[i in 1..5 where i == a]

The type of the array is not array[int] of var int but rather array[int] of var opt int. I am not very experienced with the opt type but it is generally a good idea to avoid it.

My best solution is to write:

var int : a;
[i * bool2int(i == a) in 1..5]

This array is of type array[int] of var int and should not cause any problems.

Community
  • 1
  • 1
Kobbe
  • 809
  • 5
  • 16