Initializing help system before first use

# 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}
z | 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

Parent Topic Constraints

© 2001-2026 Fair Isaac Corporation. All rights reserved. This documentation is the property of Fair Isaac Corporation (“FICO”). Receipt or possession of this documentation does not convey rights to disclose, reproduce, make derivative works, use, or allow others to use it except solely for internal evaluation purposes to determine whether to purchase a license to the software described in this documentation, or as otherwise set forth in a written software license agreement between you and FICO (or a FICO affiliate). Use of this documentation and the software described in it must conform strictly to the foregoing permitted uses, and no other use is permitted.