'How to iterate through a 2D Array with an inner set of non-fixed length?
While trying to assign unique values along a 2D array I'm lacking of an idea how to appropriately do this.
I'll have an 2D array [1..N_SECTIONS] of var set of int: content and a set of unique elements items that need to be distributed in content by a certain rule, in a way that in the end they still don't occur more than once in any of the individual sets of content.
I tried to solve this over a nested forall however I failed due to I don't see a way to append new elements to the individual sets of an unkown size. Same goes if I would convert this structure to a real 2D array like array[1..N_SECTIONS,1..N_ITEMS] of int: content basically because each section can have a different amount of members. Additionally this way the array is much oversized since N_SECTIONS * N_ITEMS >> N_ITEMS (i.e. the unqiue elements to assign).
Unfortunately I couldn't find a neat solution to constrain such a distribution in the official docs.
Thanks for any hints in advance!
Update:
Here's a dataset (Note: the assignment rule here does not guarantee a unique representation of each element, it is just used for demonstration)
array[1..5] of int: items = [1,2,3,4,5];
array[1..20] of var set: sections;
constraint forall(cur_sec in 1..3)(
forall(item in items)(
item mod cur_sec == 0 ->
sections[cur_sec][card(sections[cur_sec]] = item)); % this is particular line is not working
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
