Initializing help system before first use

maximum_minimum

maximum_minimum


Purpose
The maximum (resp) minimum constraint states that a variable z is the maximum (resp) minimum of a list of variables vars
Synopsis
minimum(vars) = z or maximum(vars) = z
z = minimum(vars) or z = maximum(vars)
Arguments
vars 
list of decision variables: {set of cpvar | array(range) of cpvar | cpvarlist}
decision variable for the maximum/minimum: cpvar
Return value
A maximum/minimum constraint over z and vars
Example
The following example shows how to use the maximum/minimum constraints:
model "Min and Max"
 uses "kalis"

 declarations
  R = 1..5
  x: array(R) of cpvar
  v, w, y: cpvar
  L: cpvarlist
  MaxCtr: cpctr
 end-declarations

 setname(v,"v")
 setname(w,"w")
 setname(y,"y")

 forall(i in R) do
  setname(x(i),"x"+i+"")
  setdomain(x(i), 0, 2*i + round(5*random + 0.5))
 end-do

 writeln("Initial domains:\n ", x, "  ", v)

! Minimum constraint with automated posting
 v = minimum(x)
 writeln("With minimum constraint:\n ", x, "  ", v)

 x(1) = 2
 writeln("Fixing x(1) to 2: ", v)

! Maximum constraint with explicit posting
 MaxCtr:= w = maximum({x(2), x(3), x(5)})
 if cp_post(MaxCtr) then
  writeln("With maximum constraint:\n ", x, "  ", w)
 else exit(1)
 end-if

 w <= 7
 writeln("Bounding w by 7:\n ", x, "  ", w)

! Maximum constraint on list of variables
 L += x(2); L += x(3); L += x(4)
 y = maximum(L)
 writeln("With 2nd maximum constraint:\n ", x, "  ", y)

 if (cp_find_next_sol) then
  writeln("A solution:\n ", x, "  ", v, "  ", w, "  ", y)
 end-if
end-model