MiniZinc Documentation - Standard Library

These functions implement the basic operations on sets.

Functions and Predicates
function set of $$E: '..'($$E: a, $$E: b)

Usage: a..b

Return the set \(\{{\bf a},\ldots,{\bf b}\}\)

function set of float: '..'(float: a, float: b)

Usage: a..b

Return the set \(\{{\bf a},\ldots,{\bf b}\}\)

function set of $T: 'diff'(set of $T: x, set of $T: y)

Usage: x diff y

Return the set difference of sets xy

function var set of int: 'diff'(var set of int: x, var set of int: y)

Usage: x diff y

Return the set difference of sets xy

test 'in'(int: x, set of int: y)

Usage: x in y

Test if x is an element of the set y

predicate 'in'(var int: x, var set of int: y)

Usage: x in y

x is an element of the set y

test 'in'(float: x, set of float: y)

Usage: x in y

Test if x is an element of the set y

predicate 'in'(var float: x, set of float: y)

Usage: x in y

Test if x is an element of the set y

function set of $T: 'intersect'(set of $T: x, set of $T: y)

Usage: x intersect y

Return the intersection of sets x and y

function var set of int: 'intersect'(var set of int: x, var set of int: y)

Usage: x intersect y

Return the intersection of sets x and y

test 'subset'(set of $T: x, set of $T: y)

Usage: x subset y

Test if x is a subset of y

predicate 'subset'(var set of int: x, var set of int: y)

Usage: x subset y

x is a subset of y

test 'superset'(set of $T: x, set of $T: y)

Usage: x superset y

Test if x is a superset of y

predicate 'superset'(var set of int: x, var set of int: y)

Usage: x superset y

x is a superset of y

function set of $T: 'symdiff'(set of $T: x, set of $T: y)

Usage: x symdiff y

Return the symmetric set difference of sets x and y

function var set of int: 'symdiff'(var set of int: x, var set of int: y)

Usage: x symdiff y

Return the symmetric set difference of sets x and y

function set of $T: 'union'(set of $T: x, set of $T: y)

Usage: x union y

Return the union of sets x and y

function var set of int: 'union'(var set of int: x, var set of int: y)

Usage: x union y

Return the union of sets x and y

function set of $U: array_intersect(array [$T] of set of $U: x)

Return the intersection of the sets in array x

function var set of int: array_intersect(array [int] of var set of int: x) =
if length(x)==0 then assert(false, "can\'t be!", -infinity..infinity) elseif length(x)==1 then x[min(index_set(x))] else let { int: l = min(index_set(x)), int: u = max(index_set(x)), array [l..u-1] of var set of ub_array(x): y, constraint y[l]==x[l] intersect x[l+1], constraint forall ( i in l+2..u ) ( y[i-1]==y[i-2] intersect x[i] ), } in ( y[u-1]) endif
(standard decomposition from builtins.mzn:681)

Return the intersection of the sets in array x

function set of $U: array_union(array [$T] of set of $U: x)

Return the union of the sets in array x

function var set of int: array_union(array [int] of var set of int: x) =
if length(x)==0 then {} elseif length(x)==1 then x[min(index_set(x))] else let { int: l = min(index_set(x)), int: u = max(index_set(x)), array [l..u-1] of var set of ub_array(x): y, constraint y[l]==x[l] union x[l+1], constraint forall ( i in l+2..u ) ( y[i-1]==y[i-2] union x[i] ), } in ( y[u-1]) endif
(standard decomposition from builtins.mzn:663)

Return the union of the sets in array x

function int: card(set of $T: x)

Return the cardinality of the set x

function var int: card(var set of int: x)

Return the cardinality of the set x

function var $$E: max(var set of $$E: s)

Return the maximum of the set s

function var $$E: min(var set of $$E: s)

Return the minimum of the set s