0

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?

MikeyB
  • 460
  • 1
  • 6
  • 22
  • Seems you have the correct idea. A decision variable can be used as an index to an array. The output of that expression then just depends on which value the decision variable takes. – Dekker1 Jul 10 '21 at 07:43
  • Can I ask another question about intuition, which the course doesn't so well address? It's related to my other question you helped out on at https://stackoverflow.com/questions/68165353/minizinc-basic-understanding-of-arrays-and-booleans/68171296?noredirect=1#comment120539681_68171296 Does combining everything into a single, massive, 2d array and performing a `forall` on it speed things up VS programmatically creating multiple, even hundreds of constraints, where each `constraint pref[n] =` can have a few `\/` statements constraining the outcome? – MikeyB Jul 10 '21 at 19:52
  • That is a though question because it depends on the problem, but generally yes. Logical clauses are easier for solvers (and thus said to be more powerful) when they have less options. – Dekker1 Jul 11 '21 at 04:28

0 Answers0