libminizinc
libminizinc copied to clipboard
Failed type inference of anonymous decision variables
Tested in MiniZinc 2.0.2.
Anonymous decision variables don't seem to be coerced to the correct type within array assignments. This would be useful for conditionalizing the size of an array, for example.
Input file:
array [int] of var bool: x = [_ | i in 1..3];
solve satisfy;
Output of mzn2fzn:
input.mzn:1:
MiniZinc: type error: initialisation value for `x' has invalid type-inst: expected `array[int] of var bool', actual `array[int] of ??? '
This is a current limitation in the type inference algorithm. Unfortunately there is no direct workaround, except using code like
array[1..3] of var bool: x;
Changing this will require a major restructuring of the type inference algorithm, so this change will not appear in the immediate future.
Ah, I see. Thanks.
For the time being, do you know if it's possible to conditionalize the size of an array by other means? It would be nice to be able to cut out arrays that aren't used under certain conditions.
The example below is along the lines of what I was aiming for.
bool: collapse;
array [int] of var bool: x =
if collapse then
[]
else
[_ | i in 1..3];
endif;
...
This might work for you:
bool: collapse;
int: n = if collapse then 0 else 3 endif;
array [1..n] of var bool: x;
Or shorter if n as an input parameter:
int: n;
array [1..n] of var bool: x;
Note 1..0 represents an empty (int) set.