4.2.2.8. Mathematical constraints

In this section: arg_max, arg_max_weak, arg_min, arg_min_weak, arg_val, arg_val_weak, maximum, maximum_arg, minimum, minimum_arg, piecewise_linear, range, sliding_sum, sum_pred, sum_set.

arg_max

1.  function var $$E: arg_max(array [$$E] of var $$T: xs)

2.  function var $$E: arg_max(array [$$E] of var bool: xs)

3.  function var $$E: arg_max(array [$$E] of var float: xs)

4.  function var $$E: arg_max(array [$$E] of var opt $$T: xs)

5.  function var $$E: arg_max(array [$$E] of var opt bool: xs)

6.  function var $$E: arg_max(array [$$E] of var opt float: xs)
1-3.

Returns the index of the maximum value in the array xs. When breaking ties the least index is returned.

4-6.

Returns the index of the maximum non-absent value in the array xs. When breaking ties the least index is returned.

arg_max_weak

function var opt $$E: arg_max_weak(array [$$E] of var opt $$T: xs)
function var opt $$E: arg_max_weak(array [$$E] of var opt bool: xs)
function var opt $$E: arg_max_weak(array [$$E] of var opt float: xs)

Returns the index of the maximum non-absent value in the array xs. When breaking ties the least index is returned. Returns absent when all elements are absent.

arg_min

1.  function var $$E: arg_min(array [$$E] of var $$T: xs)

2.  function var $$E: arg_min(array [$$E] of var bool: xs)

3.  function var $$E: arg_min(array [$$E] of var float: xs)

4.  function var $$E: arg_min(array [$$E] of var opt $$T: xs)

5.  function var $$E: arg_min(array [$$E] of var opt bool: xs)

6.  function var $$E: arg_min(array [$$E] of var opt float: xs)
1-3.

Returns the index of the minimum value in the array xs. When breaking ties the least index is returned.

4-6.

Returns the index of the minimum non-absent value in the array xs. When breaking ties the least index is returned.

arg_min_weak

function var opt $$E: arg_min_weak(array [$$E] of var opt $$T: xs)
function var opt $$E: arg_min_weak(array [$$E] of var opt bool: xs)
function var opt $$E: arg_min_weak(array [$$E] of var opt float: xs)

Returns the index of the minimum non-absent value in the array xs. When breaking ties the least index is returned. Returns absent when all elements are absent.

arg_val

function $$E: arg_val(array [$$E] of $T: xs, $T: value)
function var $$E: arg_val(array [$$E] of var bool: xs, var bool: value)
function var $$E: arg_val(array [$$E] of var opt bool: xs,
                          var opt bool: value)
function var $$E: arg_val(array [$$E] of var float: xs,
                          var float: value)
function var $$E: arg_val(array [$$E] of var opt float: xs,
                          var float: value)
function var $$E: arg_val(array [$$E] of var $$V: xs, var $$V: value)
function var $$E: arg_val(array [$$E] of var opt $$V: xs,
                          var opt $$V: value)

Returns the index of the value value in the array xs. When breaking ties the least index is returned. Note that this function forces the value value to occur in xs.

arg_val_weak

function opt $$E: arg_val_weak(array [$$E] of $T: xs, $T: value)
function var opt $$E: arg_val_weak(array [$$E] of var bool: xs,
                                   var bool: value)
function var opt $$E: arg_val_weak(array [$$E] of var opt bool: xs,
                                   var opt bool: value)
function var opt $$E: arg_val_weak(array [$$E] of var float: xs,
                                   var float: value)
function var opt $$E: arg_val_weak(array [$$E] of var opt float: xs,
                                   var opt float: value)
function var opt $$E: arg_val_weak(array [$$E] of var $$V: xs,
                                   var $$V: value)
function var opt $$E: arg_val_weak(array [$$E] of var opt $$V: xs,
                                   var opt $$V: value)

Returns the index of the value value in the array xs when value. When breaking ties the least index is returned. Returns absent when value does not occur in xs.

maximum

predicate maximum(var $$E: max_value, array [$X] of var $$E: xs)
predicate maximum(var float: max_value, array [$X] of var float: xs)

Constrains max_value to be the maximum of the values in xs.

Assumptions: |xs| > 0.

maximum_arg

1.  predicate maximum_arg(array [$$E] of var $$T: xs, var $$E: idx)

2.  predicate maximum_arg(array [$$E] of var bool: xs, var $$E: idx)

3.  predicate maximum_arg(array [$$E] of var float: xs, var $$E: idx)
1, 2.

Constrain idx to be the index of the maximum value in the array xs. When breaking ties the least index is returned.

Assumption: |xs| > 0

  1. Constrain idx to be the index of the maximum value in the array xs. When breaking ties the least index is returned.

    Assumption: |xs| > 0

minimum

predicate minimum(var float: min_value, array [$X] of var float: xs)
predicate minimum(var $$E: min_value, array [$X] of var $$E: xs)

Constrains min_value to be the minimum of the values in xs.

Assumptions: |xs| > 0.

minimum_arg

predicate minimum_arg(array [$$E] of var $$T: xs, var $$E: idx)
predicate minimum_arg(array [$$E] of var bool: xs, var $$E: idx)
predicate minimum_arg(array [$$E] of var float: xs, var $$E: idx)

Constrain idx to be the index of the minimum value in the array xs. When breaking ties the least index is returned.

Assumption: |xs| > 0

piecewise_linear

1.  function var float: piecewise_linear(var float: x,
                                         array [int] of float: x_knot,
                                         array [int] of float: y_knot)

2.  predicate piecewise_linear(var float: x,
                               var float: y,
                               array [int] of float: x_knot,
                               array [int] of float: y_knot)

3.  function var float: piecewise_linear(var float: x,
                                         array [int] of float: x_start,
                                         array [int] of float: x_end,
                                         array [int] of float: y_start,
                                         array [int] of float: y_end)

4.  predicate piecewise_linear(var float: x,
                               var float: y,
                               array [int] of float: x_start,
                               array [int] of float: x_end,
                               array [int] of float: y_start,
                               array [int] of float: y_end)
  1. Return the piecewise-linear function of x on the given point-value sequence. The array x_knot defines the points, and y_knot the corresponding values.

  2. Constrains y(x) to be the piecewise-linear function on the provided point-value sequence. The array x_knot defines the points, and y_knot the corresponding values.

  3. Return the piecewise-linear function of x on the given (possibly disconnected) intervals. Each interval i connects (x_start[i], y_start[i]) to (x_end[i], y_end[i]).

  4. Constrains y(x) to be the piecewise-linear function on the given (possibly disconnected) intervals. Each interval i connects (x_start[i], y_start[i]) to (x_end[i], y_end[i]).

range

1.  predicate range(array [$$X] of var $$Y: xs,
                    var set of $$X: domain,
                    var set of $$Y: image)

2.  function var set of int: range(array [int] of var int: xs,
                                   var set of int: domain)
  1. Requires that the image of function xs (represented as an array) on set of values domain is image. ub(domain) must be a subset of index_set(xs) otherwise an assertion failure will occur.

  2. Returns the image of function xs (represented as an array) on set of values domain. ub(domain) must be a subset of index_set(xs) otherwise an assertion failure will occur.

sliding_sum

predicate sliding_sum(int: low,
                      int: up,
                      int: window_size,
                      array [$$E] of var int: xs)

Requires that in each subsequence xs[i], …, xs[i + window_size - 1] the sum of the values belongs to the interval [low, up].

sum_pred

predicate sum_pred(var $$X: idx,
                   array [$$X] of set of $$Y: sets,
                   array [$$Y] of int: coefficients,
                   var int: total)

Requires that the sum of coefficients[i1]..coefficients[iN] equals total, where i1..iN are the elements of the idx th set in sets.

Nb: not called ‘sum’ as in the constraints catalog because ‘sum’ is a MiniZinc built-in function.

sum_set

predicate sum_set(array [$$X] of $$Y: values,
                  array [$$X] of int: weights,
                  var set of $$Y: selected,
                  var int: total)

Requires that the sum of the weights weights[i1]..weights[iN] equals total, where values[i1]..values[iN] are the elements appearing in set selected