use variable to index into array of records with arrays

37 views
Skip to first unread message

Andrey Rybalchenko

unread,
Apr 23, 2024, 6:58:54 AMApr 23
to MiniZinc
Hi, 

Any plans to lift this restriction, is it fundamental?
Error: type error: array access using a variable is not supported for array of a record type which contain an array.

My current workaround is to use 2d arrays, which are jagged so require additional bookkeeping.

Thanks,
Andrey



Jip Dekker

unread,
Apr 25, 2024, 5:29:33 AMApr 25
to MiniZinc
Hi Andrey,

The problem is fundamental in the sense that it has the same problem as your workaround. Because the arrays in each of the records can have different index set, selecting one of the records with a variable leaves us in a position were we cannot determine an index set. This goes against a lot of the assumptions within the MiniZinc compiler, and would currently make it impossible to compile array access for these arrays correctly according to MiniZinc's relational semantics.
With new compilation techniques that can take "real" variable length arrays, it might be possible to change this in the future. However, I think this is currently not a priority, and I don't see this changing soon. Instead using a 2d array with using optional types would seem the right solution for most of these situations.

Cheers,
Jip

Andrey Rybalchenko

unread,
Apr 25, 2024, 6:12:45 AMApr 25
to mini...@googlegroups.com
Hi Jip,

Thanks for the clarification. 

Andrey

PS: It looks like even if the nested array is of fixed length, the compiler is not taking advantage of that.

---8<---
type Test = record(
  array [1 .. 4] of opt int: data,
  1 .. 4: size,
);

array [_] of Test: tests = [(data: [1,2,3, <>], size: 3), (data: [1,2, <>, <>], size: 2)];
var 1 .. card(index_set(tests)): x;

constraint tests[x].size = 2;
---8<---
Error: type error: array access using a variable is not supported for array of a record type which contain an array.

--
You received this message because you are subscribed to a topic in the Google Groups "MiniZinc" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/minizinc/bo5VnazXg-c/unsubscribe.
To unsubscribe from this group and all its topics, send an email to minizinc+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/minizinc/7c44236a-246a-4823-a114-d553e071478cn%40googlegroups.com.

Jip Dekker

unread,
Apr 28, 2024, 7:49:18 PMApr 28
to MiniZinc
Hi Andrey,

You're right that we probably could easily allow this when the arrays are guaranteed to have the same index sets. However, the problem is that index sets in MiniZinc are only guaranteed to be available at runtime. For now the check whether variable indexing for records is allowed is implemented in the typechecker, which does not yet have this information.

Cheers,
Jip

Reply all
Reply to author
Forward
0 new messages