I'm working through the Introduction to Minizink course on Coursera and have come to an example which I really would like to have a better intuitive understanding of.
The model in this vieo https://www.coursera.org/learn/basic-modeling/lecture/PZO1B/1-1-7-global-constraints declares the following parameters
set of int: DIGIT = 1..9;
array[DIGIT] of int: rods = [1,2,3,4,5,2,3,4,5];
with these constraints after
constraint rods[M1] + rods[M2] + rods[M3] +
rods[M4] + rods[M5] = 12;
constraint 2303 + M1 * 10 + 980 + M2 * 1000 + M3
= 301 + M4 * 1000 + M5 * 10;
I'm struggling to visualise what's going on here. To check, a set called DIGIT is declared consisting of numbers 1 to 9, which could also be viewed as {1,...,9}
, then it's 'also' being 'instantiated/declared as/associated with' an array that looks like as it is written above inside the []
, matched up by the corresponding index. In contrast, declaring var 1..9: DIGIT
would create a range of values that DIGIT could take, which isn't an array or set.
In fact, as I write this, I actually remembered how I understood earlier examples in the course, but I'll finish this pose to perhaps get further perspectives and clarity on it, or see if I'm still missing something.
Say for example you have an enumerated set FRUIT = {apple,orange,banana}
with which you could associate an array of integers using for example array[FRUIT] of int: whatever = [4,9834,-42]
. Then, use either the enumareted possibilities by declaring var FRUIT: Opt1;
, so Opt1
can take the value of either apple, orange or banana, depending on the type of constraint used, while using whatever[Opt1]
inside a constraint would take on the value of either 4, 9834 or -42, depending on the fruit currently being 'tested' as Opt1
?
So as is often the case, explaining something to someone actually helps you to understand it better yourself, so I think I get it, but I wonder if there is anything off or missing about how I interpret the way this aspect of Minizinc works?