MiniZinc Documentation - Standard Library

These functions implement the basic operations on arrays.

Functions and Predicates
function array [int] of $T: '++'(array [int] of $T: x, array [int] of $T: y)

Usage: x++y

Return the concatenation of arrays x and y

function array [int] of var $T: '++'(array [int] of var $T: x, array [int] of var $T: y)

Usage: x++y

Return the concatenation of arrays x and y

function array [int] of var opt $T: '++'(array [int] of var opt $T: x, array [int] of var opt $T: y)

Usage: x++y

Return the concatenation of arrays x and y

function array [int] of $V: array1d(array [$U] of $V: x)

Return array x coerced to index set 1..length(x)

function array [int] of var $V: array1d(array [$U] of var $V: x)

Return array x coerced to index set 1..length(x)

function array [int] of var opt $V: array1d(array [$U] of var opt $V: x)

Return array x coerced to index set 1..length(x)

function array [$$E] of $V: array1d(set of $$E: S, array [$U] of $V: x)

Return array x coerced to one-dimensional array with index set S

function array [$$E] of var $V: array1d(set of $$E: S, array [$U] of var $V: x)

Return array x coerced to one-dimensional array with index set S

function array [$$E] of var opt $V: array1d(set of $$E: S, array [$U] of var opt $V: x)

Return array x coerced to one-dimensional array with index set S

function array [$$E,$$F] of $V: array2d(set of $$E: S1, set of $$F: S2, array [$U] of $V: x)

Return array x coerced to two-dimensional array with index sets S1 and S2

function array [$$E,$$F] of var $V: array2d(set of $$E: S1, set of $$F: S2, array [$U] of var $V: x)

Return array x coerced to two-dimensional array with index sets S1 and S2

function array [$$E,$$F] of var opt $V: array2d(set of $$E: S1, set of $$F: S2, array [$U] of var opt $V: x)

Return array x coerced to two-dimensional array with index sets S1 and S2

function array [$$E,$$F,$$G] of $V: array3d(set of $$E: S1, set of $$F: S2, set of $$G: S3, array [$U] of $V: x)

Return array x coerced to three-dimensional array with index sets S1, S2 and S3

function array [$$E,$$F,$$G] of var $V: array3d(set of $$E: S1, set of $$F: S2, set of $$G: S3, array [$U] of var $V: x)

Return array x coerced to three-dimensional array with index sets S1, S2 and S3

function array [$$E,$$F,$$G] of var opt $V: array3d(set of $$E: S1, set of $$F: S2, set of $$G: S3, array [$U] of var opt $V: x)

Return array x coerced to three-dimensional array with index sets S1, S2 and S3

function array [$$E,$$F,$$G,$$H] of $V: array4d(set of $$E: S1, set of $$F: S2, set of $$G: S3, set of $$H: S4, array [$U] of $V: x)

Return array x coerced to 4-dimensional array with index sets S1, S2, S3 and S4

function array [$$E,$$F,$$G,$$H] of var $V: array4d(set of $$E: S1, set of $$F: S2, set of $$G: S3, set of $$H: S4, array [$U] of var $V: x)

Return array x coerced to 4-dimensional array with index sets S1, S2, S3 and S4

function array [$$E,$$F,$$G,$$H] of var opt $V: array4d(set of $$E: S1, set of $$F: S2, set of $$G: S3, set of $$H: S4, array [$U] of var opt $V: x)

Return array x coerced to 4-dimensional array with index sets S1, S2, S3 and S4

function array [$$E,$$F,$$G,$$H,$$I] of $V: array5d(set of $$E: S1, set of $$F: S2, set of $$G: S3, set of $$H: S4, set of $$I: S5, array [$U] of $V: x)

Return array x coerced to 5-dimensional array with index sets S1, S2, S3, S4 and S5

function array [$$E,$$F,$$G,$$H,$$I] of var $V: array5d(set of $$E: S1, set of $$F: S2, set of $$G: S3, set of $$H: S4, set of $$I: S5, array [$U] of var $V: x)

Return array x coerced to 5-dimensional array with index sets S1, S2, S3, S4 and S5

function array [$$E,$$F,$$G,$$H,$$I] of var opt $V: array5d(set of $$E: S1, set of $$F: S2, set of $$G: S3, set of $$H: S4, set of $$I: S5, array [$U] of var opt $V: x)

Return array x coerced to 5-dimensional array with index sets S1, S2, S3, S4 and S5

function array [$$E,$$F,$$G,$$H,$$I,$$J] of $V: array6d(set of $$E: S1, set of $$F: S2, set of $$G: S3, set of $$H: S4, set of $$I: S5, set of $$J: S6, array [$U] of $V: x)

Return array x coerced to 6-dimensional array with index sets S1, S2, S3, S4, S5 and S6

function array [$$E,$$F,$$G,$$H,$$I,$$J] of var $V: array6d(set of $$E: S1, set of $$F: S2, set of $$G: S3, set of $$H: S4, set of $$I: S5, set of $$J: S6, array [$U] of var $V: x)

Return array x coerced to 6-dimensional array with index sets S1, S2, S3, S4, S5 and S6

function array [$$E,$$F,$$G,$$H,$$I,$$J] of var opt $V: array6d(set of $$E: S1, set of $$F: S2, set of $$G: S3, set of $$H: S4, set of $$I: S5, set of $$J: S6, array [$U] of var opt $V: x)

Return array x coerced to 6-dimensional array with index sets S1, S2, S3, S4, S5 and S6

function array [$T] of $V: arrayXd(array [$T] of var opt $X: x, array [$U] of $V: y)

Return array y coerced to array with same number of dimensions and same index sets as array x

function array [$T] of var $V: arrayXd(array [$T] of var opt $X: x, array [$U] of var $V: y)

Return array y coerced to array with same number of dimensions and same index sets as array x

function array [$T] of var opt $V: arrayXd(array [$T] of var opt $X: x, array [$U] of var opt $V: y)

Return array y coerced to array with same number of dimensions and same index sets as array x

function array [$$E] of $T: col(array [$$E,int] of $T: x, int: c) =
array1d(index_set_1of2(x), [ x[i, c] | i in index_set_1of2(x) ])
(standard decomposition from builtins.mzn:947)

Return column c of array x

function array [$$E] of var $T: col(array [$$E,int] of var $T: x, int: c) =
array1d(index_set_1of2(x), [ x[i, c] | i in index_set_1of2(x) ])
(standard decomposition from builtins.mzn:950)

Return column c of array x

function array [$$E] of var opt $T: col(array [$$E,int] of var opt $T: x, int: c) =
array1d(index_set_1of2(x), [ x[i, c] | i in index_set_1of2(x) ])
(standard decomposition from builtins.mzn:953)

Return column c of array x

test has_element($T: e, array [int] of $T: x) =
exists ( i in index_set(x) ) ( x[i]==e )
(standard decomposition from builtins.mzn:959)

Test if e is an element of array x

predicate has_element($T: e, array [$$E] of var opt $T: x) =
exists ( i in index_set(x) ) ( x[i]==e )
(standard decomposition from builtins.mzn:961)

Test if e is an element of array x

test has_index(int: i, array [int] of var opt $T: x) =
i in index_set(x)
(standard decomposition from builtins.mzn:957)

Test if i is in the index set of x

function set of $$E: index_set(array [$$E] of var opt $U: x)

Return index set of one-dimensional array x

function set of $$E: index_set_1of2(array [$$E,int] of var opt $U: x)

Return index set of first dimension of two-dimensional array x

function set of $$E: index_set_1of3(array [$$E,int,int] of var opt $U: x)

Return index set of first dimension of 3-dimensional array x

function set of $$E: index_set_1of4(array [$$E,int,int,int] of var opt $U: x)

Return index set of first dimension of 4-dimensional array x

function set of $$E: index_set_1of5(array [$$E,int,int,int,int] of var opt $U: x)

Return index set of first dimension of 5-dimensional array x

function set of $$E: index_set_1of6(array [$$E,int,int,int,int,int] of var opt $U: x)

Return index set of first dimension of 6-dimensional array x

function set of $$E: index_set_2of2(array [int,$$E] of var opt $U: x)

Return index set of second dimension of two-dimensional array x

function set of $$E: index_set_2of3(array [int,$$E,int] of var opt $U: x)

Return index set of second dimension of 3-dimensional array x

function set of $$E: index_set_2of4(array [int,$$E,int,int] of var opt $U: x)

Return index set of second dimension of 4-dimensional array x

function set of $$E: index_set_2of5(array [int,$$E,int,int,int] of var opt $U: x)

Return index set of second dimension of 5-dimensional array x

function set of $$E: index_set_2of6(array [int,$$E,int,int,int,int] of var opt $U: x)

Return index set of second dimension of 6-dimensional array x

function set of $$E: index_set_3of3(array [int,int,$$E] of var opt $U: x)

Return index set of third dimension of 3-dimensional array x

function set of $$E: index_set_3of4(array [int,int,$$E,int] of var opt $U: x)

Return index set of third dimension of 4-dimensional array x

function set of $$E: index_set_3of5(array [int,int,$$E,int,int] of var opt $U: x)

Return index set of third dimension of 5-dimensional array x

function set of $$E: index_set_3of6(array [int,int,$$E,int,int,int] of var opt $U: x)

Return index set of third dimension of 6-dimensional array x

function set of $$E: index_set_4of4(array [int,int,int,$$E] of var opt $U: x)

Return index set of fourth dimension of 4-dimensional array x

function set of $$E: index_set_4of5(array [int,int,int,$$E,int] of var opt $U: x)

Return index set of fourth dimension of 5-dimensional array x

function set of $$E: index_set_4of6(array [int,int,int,$$E,int,int] of var opt $U: x)

Return index set of fourth dimension of 6-dimensional array x

function set of $$E: index_set_5of5(array [int,int,int,int,$$E] of var opt $U: x)

Return index set of fifth dimension of 5-dimensional array x

function set of $$E: index_set_5of6(array [int,int,int,int,$$E,int] of var opt $U: x)

Return index set of fifth dimension of 6-dimensional array x

function set of $$E: index_set_6of6(array [int,int,int,int,int,$$E] of var opt $U: x)

Return index set of sixth dimension of 6-dimensional array x

test index_sets_agree(array [$T] of var opt $U: x, array [$T] of var opt $W: y)

Test if x and y have the same index sets

function int: length(array [$T] of var opt $U: x)

Return the length of array x

Note that the length is defined as the number of elements in the array, regardless of its dimensionality.

function array [$$E] of $T: reverse(array [$$E] of $T: x) =
let {int: l = max(index_set(x))+min(index_set(x)), } in (array1d(index_set(x), [ x[l-i] | i in index_set(x) ]))
(standard decomposition from builtins.mzn:724)

Return the array x in reverse order

The resulting array has the same index set as x.

function array [$$E] of var $T: reverse(array [$$E] of var $T: x) =
let {int: l = max(index_set(x))+min(index_set(x)), } in (array1d(index_set(x), [ x[l-i] | i in index_set(x) ]))
(standard decomposition from builtins.mzn:732)

Return the array x in reverse order

The resulting array has the same index set as x.

function array [$$E] of var opt $T: reverse(array [$$E] of var opt $T: x) =
let {int: l = max(index_set(x))+min(index_set(x)), } in (array1d(index_set(x), [ x[l-i] | i in index_set(x) ]))
(standard decomposition from builtins.mzn:740)

Return the array x in reverse order

The resulting array has the same index set as x.

function array [$$E] of $T: row(array [int,$$E] of $T: x, int: r) =
array1d(index_set_2of2(x), [ x[r, i] | i in index_set_2of2(x) ])
(standard decomposition from builtins.mzn:937)

Return row r of array x

function array [$$E] of var $T: row(array [int,$$E] of var $T: x, int: r) =
array1d(index_set_2of2(x), [ x[r, i] | i in index_set_2of2(x) ])
(standard decomposition from builtins.mzn:940)

Return row r of array x

function array [$$E] of var opt $T: row(array [int,$$E] of var opt $T: x, int: r) =
array1d(index_set_2of2(x), [ x[r, i] | i in index_set_2of2(x) ])
(standard decomposition from builtins.mzn:943)

Return row r of array x