clojure2minizinc.core
clojure2minizinc provides an interface between MiniZinc and Clojure. The clojure2minizinc user models in Clojure constraint satisfaction or optimisation problems over Boolean, integer, real number, and/or set variables. clojure2minizinc translates them into MiniZinc, they are solved in the background by a compatible solver, and the result is read back into Clojure. clojure2minizinc code can be very similar to the corresponding MiniZinc code, but in addition the full power of Clojure is at hand.
--
(-- min max)
Expects a minimum an a maximum value (ints or floats) and returns a domain specification for a decision variable (ints or floats).
->anArray
(->anArray name mzn-string boundaries)
Positional factory function for class clojure2minizinc.core.anArray.
->aVar
(->aVar name mzn-string)
Positional factory function for class clojure2minizinc.core.aVar.
aggregate
macro
(aggregate generators exp)
(aggregate generators exp set-or-array)
List (array) and set comprehension. Generates a MiniZinc array/set containing the possible combinations of locally declared MiniZinc parameters (generators) used in the expression (exp).
Example:
(aggregate [i (-- 1 3)]
(* i i))
; means [1*1, 2*2, 3*3] (in MiniZinc syntax)
Note that every generator (e.g., (-- 1 3)
) declares always only a single MiniZinc parameter (i
in the example above). This follows standard Clojure conventions (e.g., similar to let
and friends), while MiniZinc allows for declaring multiple parameters together.
A where-expression can be added after the generators, which acts as a filter. Only elements satisfying this Boolean expression are used to construct elements in the output array/set.
Example:
(def a (array (-- 1 3) :int))
(aggregate [i (-- 1 3)
j (-- 1 3)
:where (< i j)]
(!= (nth a i) (nth a j)))
; means [a[1] != a[2], a[2] != a[3]] (in MiniZinc syntax)
The optional arguments set-or-array
specifies whether result is array or set. It must be either :array
or :set
, default is :array
.
Example:
(aggregate [i (-- 1 3)]
(= (nth a i) 0)
:set)
all_disjoint
(all_disjoint x)
all_disjoint(array[int] of var set of int: x)
Ensures that every pair of sets in the array x is disjoint.
all_equal
(all_equal x)
all_equal(array[int] of var int: x) all_equal(array[int] of var set of int: x)
Constrains the array of objects x to have the same value.
alldifferent
(alldifferent x)
alldifferent(array[int] of var int: x) alldifferent(array[int] of var set of int: x)
Constrains the array of objects x to be all different.
alldifferent_except_0
(alldifferent_except_0 x)
alldifferent_except_0(array[int] of var int: x)
Constrains the elements of the array x to be all different except those elements that are assigned the value 0.
among
(among n x v)
among(var int: n, array[int] of var int: x, set of int: v)
Requires exactly n variables in x to take one of the values in v.
array
(array index-set type-inst)
(array index-set type-inst array-name)
(array index-set type-inst array-name init-value)
Declares a one- or multi-dimensional array.
Arguments:
- index-set: The explicitly declared indices of the array. Either an integer range (declared with function –), a set variable initialised to an integer range, or for multi-dimensional arrays a list of integer ranges and/or MiniZinc sets.
- type-inst: Specifies the parameter type or variable domain The type of the variables contained in the array (a string, symbol or keyword; can be int, float, bool, string and “set of int”).
- array-name (optional): a name for the array (a string, symbol or keyword). Default is a “gensym-ed” name.
- init-value (optional): a vector of MiniZinc-supported values. Defaults to nil.
Examples:
(array (-- 1 10) :bool) ; array of bools at indices 1-10 (not decision variables!)
(array (-- 1 10) :int) ; array of ints at indices 1-10
(array (-- 1 10) [:set :int]) ; array of sets of integers
(array (-- 1 10) (-- -1 2)) ; array of integers in given range
(array (-- 1 10) (-- 2.0 4.0)) ; array of floats in range
(array (-- 1 10) [:set (-- -1 2)]) ; array of subsets of set range
(array (-- 1 10) [:var :int]) ; array of int variables
(array (-- 1 10) [:var (-- 1 3)]) ; array of int variables with given domain
(array (-- 1 10) [:var #{1 3 5}]) ; array of int variables with given domain
(array (-- 1 10) [:var (-- 1.0 3.0)]) ; array of float variables with given domain
(array (-- 1 10) [:var :set (-- 1 3)]) ; array of set variables with domain
(array (-- 1 10) [:var :set #{1 3 5}]) ; array of set variables with domain
(array [(-- 1 10) (-- 1 10)] [:var :int (-- 1 3)]) ; two-dimensional array of int variables
(array (-- 1 10) :int 'x) ; array explicitly named x
(array (-- 1 3) :int 'x [5 6 7]) ; array of ins with init value
BUG: literal arrays not supported as init val.
array->clj-seq
(array->clj-seq my-array)
Transforms a one or more dimensional MiniZinc array into a Clojure list (of MiniZinc code strings representing the array elements), so that MiniZinc functions can be applied to individual MiniZinc elements (e.g., by mapping).
BUG: multi-dimensional array should return nested sequence to clearly highlight the dimensions. Currently, simply a flat sequence with all elements (the cartesian product) is returned.
array1d
(array1d x a)
Initialise an array of one dimension from given array a.
See example for array2d.
array2d
(array2d x1 x2 a)
Initialise a 2D array from given array a.
Example:
(array2d (-- 1 3) (-- 1 2) [1 2 3 4 5 6])
is equivalent to (literal-array [1 2][3 4][5 6])
which is the MiniZinc array [|1, 2 |3, 4 |5, 6|])
array6d
(array6d x1 x2 x3 x4 x5 x6 a)
Initialise a 6D array from given array a.
See example for array2d.
assert
(assert mz-expr error-msg)
Constraint to guard against certain errors (e.g., to double-check input from data files).
mz-expr (string) a MiniZinc expression returning a Boolean value error-msg (string) an error message printed in case mz-expr is false
BUG: mzn2fzn (version 1.6.0) detects inconsistency, but does not print the error message.
at_least
(at_least n x v)
at_least(int: n, array[int] of var int: x, int: v) at_least(int: n, array[int] of var set of int: x, set of int: v)
Requires at least n variables in x to take the value v.
at_most
(at_most n x v)
at_most(int: n, array[int] of var int: x, int: v) at_most(int: n, array[int] of var set of int: x, set of int: v)
Requires at most n variables in x to take the value v.
at_most1
(at_most1 s)
at_most1(array[int] of var set of int: s)
Requires that each pair of sets in s overlap in at most one element.
bin_packing
(bin_packing c bin w)
bin_packing(int: c, array[int] of var int: bin, array[int] of int: w)
Requires that each item i be put into bin bin[i] such that the sum of the weights of each item, w[i], in each bin does not exceed the capacity c. Aborts if an item has a negative weight or if the capacity is negative. Aborts if the index sets of bin and w are not identical.
bin_packing_capa
(bin_packing_capa c bin w)
bin_packing_capa(array[int] of int: c, array[int] of var int: bin, array[int] of int:w)
Requires that each item i be put into bin bin[i] such that the sum of the weights of each item, w[i], in each bin b does not exceed the capacity c[b]. Aborts if an item has negative weight. Aborts if the index sets of bin and w are not identical.
bin_packing_load
(bin_packing_load l bin w)
bin_backing_load(array[int] of var int: l, array[int] of var int: bin, array[int] of int: w)
Requires that each item i be put into bin bin[i] such that the sum of the weights of each item, w[i], in each bin b is equal to the load l[b]. Aborts if an item has negative weight. Aborts if the index sets of bin and w are not identical.
bool
(bool)
(bool par-name)
(bool par-name init-value)
Declares a bool parameter (quasi a constant) with an optional init-value (default nil, meaning no initialisation), and optional name (a string, symbol or keyword, default is a gensym-ed name).
call-fn
(call-fn fn & args)
A MiniZinc function call supporting a function arity of 1 or more.
call-global-constraint
(call-global-constraint fn & args)
Includes
call-operator
(call-operator operator x y & more)
A MiniZinc operator call supporting arities of 2 or more. For higher arities multiple operators are used (e.g., a ternary plus is translated into x + y + z)
circuit
(circuit x)
circuit[array[int] of var int: x)
Constraints the elements of x to define a circuit where x[i] = j mean that j is the successor of i.
clj2mnz
macro
(clj2mnz & constraints)
Translates a constraint problem defined in Clojure into the corresponding MiniZinc code. Expects any number of variable/parameter declarations, any number of constraints, one output, and one solver declaration, all in any order.
concat
(concat x)
Concatenate an array of strings. Equivalent to folding ‘++’ over the array, but may be implemented more efficiently.
constraint
(constraint constraint-expr)
Expects a constraint expression (a string) and turns it into a constraint statement.
count_eq
(count_eq x y c)
count_eq(array[int] of var int: x, var int: y, var int: c)
Constrains c to be the number of occurrences of y in x. Also available by the name count.
count_geq
(count_geq x y c)
count_geq(array[int] of var int: x, var int: y, var int: c)
Constrains c to greater than or equal to the number of occurrences of y in x.
count_gt
(count_gt x y c)
count_gt(array[int] of var int: x, var int: y, var int: c)
Constrains c to strictly greater than the number of occurrences of y in x.
count_leq
(count_leq x y c)
count_leq(array[int] of var int: x, var int: y, var int: c)
Constrains c to less than or equal to the number of occurrences of y in x.
count_lt
(count_lt x y c)
count_lt(array[int] of var int: x, var int: y, var int: c)
Constrains c to strictly less than the number of occurrences of y in x.
count_neq
(count_neq x y c)
count_neq(array[int] of var int: x, var int: y, var int: c)
Constrains c to not be the number of occurrences of y in x.
cumulative
(cumulative s d r b)
cumulative(array[int] of var int: s, array[int] of var int: d, array[int] of var int: r, var int: b)
Requires that a set of tasks given by start times s, durations d, and resource requirements r, never require more than a global resource bound b at any one time. Aborts if s, d, and r do not have identical index sets. Aborts if a duration or resource requirement is negative.
decreasing
(decreasing x)
decreasing(array[int] of var bool: x) decreasing(array[int] of var float: x) decreasing(array[int] of var int: x) decreasing(array[int] of var set of int: x)
Requires that the array x is in (non-strictly) decreasing order.
diffn
(diffn x y dx dy)
diffn(array[int] of var int: x, array[int] of var int: y, array[int] of var int: dx, array[int] of var int: dy)
Constrains rectangles, given by their origins x,y and sizes dx,dy, to be non-overlapping.
disjoint
(disjoint s t)
disjoint(var set of int: s, var set of int: t)
Requires that sets s and t do not intersect.
distribute
(distribute card value base)
distribute(array[int] of var int: card, array[int] of var int: value, array[int] of var int: base)
Requires that card[i] is the number of occurrences of value[i] in base. In this implementation the values in value need not be distinct. Aborts if card and value do not have identical index sets.
dom_array
(dom_array x)
Domain reflection: a safe approximation to the union of all possible values of the expressions appearing in the array x (ints).
element
(element i x y)
element(var int: i, array[int] of var bool: x, var bool: y) element(var int: i, array[int] of var float: x, var float: y) element(var int: i, array[int] of var int: x, var int: y) element(var int: i, array[int] of var set of int: x, var set of int: y)
The same as x[i] = y or (= (nth x i) y). That is, y is the ith element of the array x. The difference to nth is that i can be a variable.
exactly
(exactly n x v)
exactly(int: n, array[int] of var int: x, int: v) exactly(int: n, array[int] of var set of int: x, set of int: v)
Requires exactly n variables in x to take the value v.
exists
macro
(exists x)
(exists generators exp)
Existential quantification (logical disjunction of Boolean expressions). When applied to an empty list, exists returns false.
Unary: MiniZinc function exists.
Binary: exists with list comprehension support.
See aggregate for list comprehension syntax and examples.
fix
(fix x)
Check if the argument’s value is fixed at this point in evaluation. If not, abort; if so, return its value. This is most useful in output items when decision variables should be fixed – it allows them to be used in places where a fixed value is needed, such as if-then-else conditions.
float
(float)
(float par-name)
(float par-name init-value)
Declares a float parameter (quasi a constant) with an optional init-value (default nil, meaning no initialisation), and optional name (a string, symbol or keyword, default is a gensym-ed name).
forall
macro
(forall generators exp)
Universal quantification with list comprehension support: Logical conjunction of aggregated Boolean expressions. When applied to an empty list, forall returns true.
See aggregate for list comprehension syntax and examples.
global_cardinality
(global_cardinality x cover counts)
global_cardinality(array[int] of var int: x, array[int] of int: cover, array[int] of var int: counts)
Requires that the number of occurrences of cover[i] in x is counts[i]. Aborts if cover and counts do not have identical index sets.
global_cardinality_closed
(global_cardinality_closed x cover counts)
global_cardinality_closed(array[int] of var int: x, array[int] of int: cover, array[int] of var int: counts)
Requires that the number of occurrences of cover[i] in x is counts[i]. The elements of x must take their values from cover. Aborts if cover and counts do not have identical index sets.
global_cardinality_low_up
(global_cardinality_low_up x cover lb ub)
global_cardinality_low_up(array[int] of var int: x, array[int] of int: cover, array[int] of int: lb, array[int] of int: ub)
Requires that for all i, the value cover[i] appears at least lb[i] and at most ub[i] times in the array x.
global_cardinality_low_up_closed
(global_cardinality_low_up_closed x cover lb ub)
global_cardinality_low_up_closed(array[int] of var int: x, array[int] of int: cover, array[int] of int: lb, array[int] of int: ub)
Requires that for all i, the value cover[i] appears at least lb[i] and at most ub[i] times in the array x. The elements of x must take their values from cover.
iffall
macro
(iffall generators exp)
N-ary bi-implication with list comprehension support: even number of aggregated Boolean expressions holds.
See aggregate for list comprehension syntax and examples.
include
(include file)
Include the given file. Does automatic book keeping whether file was already included, and includes it only once.
increasing
(increasing x)
increasing(array[int] of var bool: x) increasing(array[int] of var float: x) increasing(array[int] of var int: x) increasing(array[int] of var set of int: x)
Requires that the array x is in (non-strictly) increasing order.
index_set
(index_set x)
Reflection function: the index set (set of indices) of a one dimensional array.
int
(int)
(int par-name)
(int par-name init-value)
Declares an initeger parameter (quasi a constant) with an optional init-value (default nil, meaning no initialisation), and optional name (a string, symbol or keyword, default is a gensym-ed name).
int_set_channel
(int_set_channel x y)
int_set_channel(array[int] of var int: x, array[int] of var set of int: y)
Requires that x[i] = j if and only if i is an element of y[j].
inverse
(inverse f invf)
inverse(array[int] of var int: f, array[int] of var int: invf)
Constrains two arrays to represent inverse functions of each other. All the values in each array must be within the index set of the other array.
inverse_set
(inverse_set f invf)
inverse_set(array[int] of var set of int: f, array[int] of var set of int: invf)
Constrains the two arrays f and invf so that a j is an element of f[i] if and only if i is an element of invf[j]. All the values in each array’s sets must be within the index set of the other array.
join
(join s a)
Concatenates an array of strings a, putting a seperator string s beween adjacent strings. Returns the empty string if the array is empty.
lb
(lb x)
Domain reflection: a safe approximation to the lower bound value of x (int, float, or set of int).
lb_array
(lb_array x)
Domain reflection: a safe approximation to the lower bound of all expressions appearing in the array x (of int, float, or set of int).
lex2
(lex2 x)
lex2(array[int, int] of var int: x)
Require adjacent rows and adjacent columns in the the array x to be lexicographically ordered. Adjacent rows and adjacent columns may be equal.
lex_greater
(lex_greater x y)
lex_greater(array[int] of var bool: x, array[int] of var bool: y) lex_greater(array[int] of var float: x, array[int] of var float: y) lex_greater(array[int] of var int: x, array[int] of var int: y) lex_greater(array[int] of var set of int: x, array[int] of var set of int: y)
Requires that the array x is strictly lexicographically greater than array y. Compares them from first to last element, regardless of indices.
lex_greatereq
(lex_greatereq x y)
lex_greatereq(array[int] of var bool: x, array[int] of var bool: y) lex_greatereq(array[int] of var float: x, array[int] of var float: y) lex_greatereq(array[int] of var int: x, array[int] of var int: y) lex_greatereq(array[int] of var set of int: x, array[int] of var set of int: y)
Requires that the array x is lexicographically greater than or equal to array y. Compares them from first to last element, regardless of indices.
lex_less
(lex_less x y)
lex_less(array[int] of var bool: x, array[int] of var bool: y) lex_less(array[int] of var float: x, array[int] of var float: y) lex_less(array[int] of var int: x, array[int] of var int: y) lex_less(array[int] of var set of int: x, array[int] of var set of int: y)
Requires that the array x is strictly lexicographically less than array y. Compares them from first to last element, regardless of indices.
lex_lesseq
(lex_lesseq x y)
lex_lesseq(array[int] of var bool: x, array[int] of var bool: y) lex_lesseq(array[int] of var float: x, array[int] of var float: y) lex_lesseq(array[int] of var int: x, array[int] of var int: y) lex_lesseq(array[int] of var set of int: x, array[int] of var set of int: y)
Requires that the array x is lexicographically less than or equal to array y. Compares them from first to last element, regardless of indices.
link_set_to_booleans
(link_set_to_booleans s b)
link_set_to_booleans(var set of int: s, array[int] of var bool: b)
The array of booleans b is the characteristic representation of the set s. Aborts if the index set of b is not a superset of the possible values of s.
literal-array
(literal-array & exprs)
Specifies a one- or two-dimensional array that contains the given MiniZinc expressions as elements. Two-dimensional arrays are defined by a list of expressions.
literal-set
(literal-set & exprs)
Specifies a set of explicitly given integers (can be MiniZinc expressions) as elements.
map->anArray
(map->anArray m__5869__auto__)
Factory function for class clojure2minizinc.core.anArray, taking a map of keywords to field values.
map->aVar
(map->aVar m__5869__auto__)
Factory function for class clojure2minizinc.core.aVar, taking a map of keywords to field values.
map2minizinc
(map2minizinc mzn-map)
Utility function for creating data files (*.dzn files) that map keys (MiniZinc variable names) to values.
BUG: only few value types supported.
max
macro
(max x)
(max generators exp)
Maximal value
Unary: MiniZinc function max.
Binary: max with list comprehension support: greatest element in aggregated expressions. If aggregated expressions are empty gives MiniZinc error.
See aggregate for list comprehension syntax and examples.
maximum
(maximum m x)
maximum(var int: m, array[int] of var int: x) maximum(var float: m, array[int] of var float: x)
Constrains m to be the maximum of the values in x. (The array x must have at least one element.)
member
(member x y)
member(array[int] of var bool: x, var bool: y) member(array[int] of var float: x, var float: y) member(array[int] of var int: x, var int: y) member(array[int] of var set of int: x, var set of int: y) member(var set of int: x, var int: y)
Requires that y occurs in the array or set x.
min
macro
(min x)
(min generators exp)
Minimal value
Unary: MiniZinc function min.
Binary: min with list comprehension support: least element in aggregated expressions. If aggregated expressions are empty gives MiniZinc error.
See aggregate for list comprehension syntax and examples.
minimum
(minimum m x)
minimum(var float: m, array[int] of var float: x) minimum(var int: m, array[int] of var int: x)
Constrains m to be the minimum of the values in x. (The array x must have at least one element.)
minizinc
(minizinc mzn & {:keys [solver mznfile data print-cmd? print-mzn? print-solution? num-solutions all-solutions? options], :or {options [], num-solutions 1, solver *fd-solver*, data false, mznfile (doto (java.io.File/createTempFile "clojure2minizinc" ".mzn") .deleteOnExit), print-mzn? false, all-solutions? false, print-solution? false, print-cmd? false}})
Calls a MiniZinc solver on a given MiniZinc program and returns a list of one or more solutions.
Options are
- :mzn (string) a MiniZinc program, which can be created with other functions of clojure2minizinc wrapped into clj2mnz
- :print-cmd? (boolean) whether or not to print the UNIX command call of the solver (for debugging)
- :print-mzn? (boolean) whether or not to print resulting MiniZinc data and model (for debugging)
- :print-solution? (boolean) whether or not to print the result output by MiniZinc directly instead of reading it into a Clojure value (e.g., for debugging). Prints the map resulting from clojure.java.shell/sh.
- :solver (string) solver to call
- :mznfile (string or file) MiniZinc file path to generate and use in the background
- :data (string) Content for a MiniZinc data file (*.dzn file). Can conveniently be created with map2minizinc
- :num-solutions (int) An upper bound on the number of solutions to output
- :all-solutions (boolean) If true, return all solutions
- :options (collection of strings) Arbitrary options given to the solver in UNIX shell syntax, e.g., [“-a”] for all solutions.
BUG: resulting temporary MiniZinc file is not deleted after Clojure quits.
nth
(nth my-array & indices)
Accesses the array element at the given index, or indices in case of a multi-dimensional array
nvalue
(nvalue x)
nvalue(var int: n, array[int] of var int: x)
Requires that the number of distinct values in x is n.
output
(output mzn-string)
Expects an output definition (a string) and turns it into an output statement (surround by brackets etc.)
BUG: this fn is currently far too inflexible.
output-map
(output-map my-map)
Expects a map containing MiniZinc variables and returns a string formatted for MiniZinc to output a Clojure map for Clojure to read.
output-var
(output-var my-var)
Outputs a single MiniZinc variable. For example, a one-dimensional MiniZinc array can be read into a Clojure vector directly.
output-vector
(output-vector my-vec)
Expects a vector of MiniZinc variables and returns a string formatted for MiniZinc to output a Clojure vector for Clojure to read.
partition_set
(partition_set s universe)
partition_set(array[int] of var set of int: s, set of int: universe)
Partitions universe into disjoint sets.
product
macro
(product x)
(product generators exp)
Multiplication
Unary: MiniZinc function Multiplication.
Binary: product with list comprehension support: multiplies aggregated expressions. If aggregated expressions are empty returns 1.
See aggregate for list comprehension syntax and examples.
range
(range x s t)
range(array[int] of var int: x, var set of int: s, var set of int: t)
Requires that the image of function x (represented as an array) on set of values s is t. Aborts if ub(s) is not a subset of the index set of x.
regular
(regular x Q S d q0 F)
regular(array[int] of var int: x, int: Q, int: S, array[int,int] of int: d, int: q0, set of int: F)
The sequence of values in array x (which must all be in the range 1..S) is accepted by the DFA of Q states with input 1..S and transition function d (which maps ⟨1..Q, 1..S⟩ to 0..Q) and initial state q0 (which must be in 1..Q) and accepting states F (which all must be in 1..Q). State 0 is reserved to be an always failing state. Aborts if Q < 1. Aborts if S < 1. Aborts if the transition function d is not in [1..Q, 1..s]. Aborts if the start state, q0, is not in 1..Q. Aborts if F is not a subset of 1..Q.
roots
(roots x s t)
roots(array[int] of var int: x, var set of int: s, var set of int: t)
Requires that x[i] is an element of t for all i element of s. Aborts if ub(s) is not a subset of the index set of x.
set
(set)
(set par-name)
(set par-name init-value)
Declares a set of integers parameter (quasi a constant) with an optional init-value and optional name (a string, symbol or keyword, default is a gensym-ed name). The init value is a range, e.g., (-- 1 10)
meaning the set contains all integers in the range. The default is nil, meaning no initialisation.
show
(show x)
To-string conversion. Converts any value to a string for output purposes. The exact form of the resulting string is implementation-dependent.
show_float
(show_float justification digits x)
Formatted to-string conversion for floats. Converts the float x
into a string right justified by the number of characters given by justification
(int), or left justified if that argument is negative. The number of digits to appear after the decimal point is given by digits
(int). It is a run-time error for digits
to be negative. If x
is not fixed, the form of the string is implemenation-dependent.
show_int
(show_int justification x)
Formatted to-string conversion for integers. Converts the integer x
into a string right justified by the number of characters justification
(int), or left justified if that argument is negative. If x
is not fixed, the form of the string is implementation-dependent.
sliding_sum
(sliding_sum low up seq vs)
sliding_sum(int: low, int: up, int: seq, array[int] of var int: vs)
Requires that in each subsequence vs[i], …, vs[i + seq - 1] the sum of the values belongs to the interval [low, up].
solve
(solve solver)
(solve solver exp)
Solve items specify what kind of solution is being looked for. Supported values for solver are :satisfy, :maximize, and :minimize (a keyword).
sort
(sort x y)
sort(array[int] of var int: x, array[int] of var int: y)
Requires that the multiset of values in x is the same as the multiset of values in y but y is in sorted order. Aborts if the cardinality of the index sets of x and y is not equal.
strict_lex2
(strict_lex2 x)
strict_lex2(array[int, int] of var int: x)
Require adjacent rows and adjacent columns in the the array x to be lexicographically ordered. Adjacent rows and adjacent columns cannot be equal.
subcircuit
(subcircuit x)
subcircuit(array[int] of var int: x)
Constrains the elements of x to define a subcircuit where x[i] = j means that j is the successor of i and x[i] = i means that i is not in the circuit.
sum
macro
(sum x)
(sum generators exp)
Summation
Unary: MiniZinc function sum.
Binary: sum with list comprehension support: adds aggregated expressions. If aggregated expressions are empty returns 0.
See aggregate for list comprehension syntax and examples.
sum_pred
(sum_pred i sets c s)
sum_pred(var int: i, array[int] of set of int: sets, array[int] of int: c, var int: s)
Requires that the sum of c[i1]…c[iN] equals s, where i1..iN are the elements of the ith set in sets. This constraint is usually named sum, but using that would conflict with the MiniZinc built-in function of the same name.
table
(table x t)
table(array[int] of var bool: x, array[int, int] of bool: t) table(array[int] of var int: x, array[int, int] of int: t)
Represents the constraint x is element of t where we consider each row in t to be a tuple and t as a set of tuples. Aborts if the second dimension of t does not equal the number of variables in x. The default decomposition of this constraint cannot be flattened if it occurs in a reified context.
trace
(trace s x)
Return x (any type). As a side-effect, an implementation may print the string s.
ub
(ub x)
Domain reflection: a safe approximation to the upper bound value of x (int, bool, float or set of int).
ub_array
(ub_array x)
Domain reflection: a safe approximation to the upper bound of all expres- sions appearing in the array x x (of int, float, or set of int).
value_precede
(value_precede s t x)
value_precede(int: s, int: t, array[int] of var int: x) value_precede(int: s, int: t, array[int] of var set of int: x)
Requires that s precede t in the array x. For integer variables this constraint requires that if an element of x is equal to t, then another element of x with a lower index is equal to s. For set variables this constraint requires that if an element of x contains t but not s, then another element of x with lower index contains s but not t.
value_precede_chain
(value_precede_chain c x)
value_precede_chain(array[int] of int: c, array[int] of var int: x) value_precede_chain(array[int] of int: c, array[int] of var set of int: x)
Requires that the value_precede constraint is true for every pair of adjacent integers in c in the array x.
variable
(variable type-inst)
(variable type-inst var-name)
Declares a decision variable (bool, int, float, or set of int) with the given domain, and an optional variable name (string, symbol or keyword).
Examples:
(variable :bool) ; a Boolean variable (no further domain specification supported)
(variable :int) ; an integer variable with maximum supported domain size
(variable (-- -1 10)) ; an integer variable with domain [-1, 10]
(variable #{1 3 6 8}) ; an integer variable with the domain {1, 3, 6, 8}
(variable (-- 1.0 10.0)) ; a float variable with domain [1.0, 10.0]
(variable [:set (-- 1 3)]) ; a set of integers with the given domain (set is subset of domain)
(variable [:set #{1 3 6 8}]) ; a set of integers with the given domain (set is subset of domain)
(variable [:int (-- 1 3)]) ; same as (variable (-- -1 10))
(variable (-- 1 10) 'x) ; an integer variable named x (instead of an automatically assigned name)
xorall
macro
(xorall generators exp)
N-ary exclusive disjunction with list comprehension support: odd number of aggregated Boolean expressions holds.
See aggregate for list comprehension syntax and examples.