You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I was wondering whether the MiniZinc could infer an index set for array comprehensions being assigned to well defined variables/parameters. Currently, it always assumes indexing starting from 1 and it requires manual reindexing.
Example:
array[0..N-1] of int: arr = [i | i in 0..N-1];
it throws an error:
MiniZinc: evaluation error: Index set mismatch. Declared index set of `arr' is [0..3], but is assigned to array with index set [1..4]. You may need to coerce the index sets using the array1d function.
Also when such assignment happens in constraint:
array[0..N-1] of var int: arr;
constraint arr = [i | i in 0..N-1];
it only throws:
MiniZinc: assertion failed: array index sets do not match
Why the error message is shorter and doesn't recommend coercing via the array1d function?
The text was updated successfully, but these errors were encountered:
We have discussed inferring index sets in the past, but decided against inferring index sets as it can lead to unexpected behaviour elsewhere in the language.
Instead we have added syntax to directly index your comprehension:
array[0..N-1] of int: arr = [i: i | i in 0..N-1];
or for a multidimensional array:
array[_,_,_] of int: arr = [(i,j,k): i*j*k | i,j,k in -5..5]
Regarding the difference in error message. The first message is from the compiler, whereas the second message is from the MiniZinc library (from the '=' predicate. Although it will remain an assertion, I can see what I can do to make sure it at least gives more information about the index sets
While I get that inferring index sets might be problematic in many cases and thus can't be done in general everywhere, it is a recurring annoyance.
The most common case for me when it turns up is when I have data that is best represented using (typically) 0-indexed arrays. Writing data-files with array1d calls is not very nice, and neither is having a data value that is just used, and then reshaped to another name in the model file.
Adding some way to solve some of these minor problems might be worth thinking about. For example, having an annotation for an array that specifies that this declaration will auto-coerce index sets could be one way.
For data from data files there are currently already a few ways to mitigate the problem as well. First, JSON files will actually do the inference of index sets (since we currently have no other way to give an index set to JSON list data).
For DZN data, we currently do not do inference, but when you just need to offset an array literal you no longer have to use array1d calls. Instead you can use the new literal types and provide the index for the first member:
I was wondering whether the MiniZinc could infer an index set for array comprehensions being assigned to well defined variables/parameters. Currently, it always assumes indexing starting from
1
and it requires manual reindexing.Example:
it throws an error:
Also when such assignment happens in constraint:
it only throws:
Why the error message is shorter and doesn't recommend coercing via the array1d function?
The text was updated successfully, but these errors were encountered: