Search code examples
arraysminizinc

Minizinc: create an array of int pairs


What is the Minizinc syntax to create an array of n int pairs like this:

{(x1,y1), (x2,y2),....(xn,yn)}

and how can I access to a specific element j to get, for example, its y value?


Solution

  • In MiniZinc you would currently use multi-dimensional arrays for this purpose. If, for example, you want to create n pairs of integer variables you can use:

    array [1..n, 1..2] of var int: pairs;
    

    You could then access each pair, but also each element. If, for example, you want to access pair j, then you can use the statement pairs[j]. This is an array of dimensions 1..2; you can access the second element (y), using pairs[j][y].

    This approach allows you to use the variables directly, but you can also use pairs for predicates that call for arrays.