Initializing help system before first use

MIP formulations using other entities

Topics covered in this section:

In principle, all you need in building MIP models are continuous variables and binary variables. But it is convenient to extend the set of modeling entities to embrace objects that frequently occur in practice.

Integer decision variables

  • values 0, 1, 2, ... up to small upper bound
  • model discrete quantities
  • try to use partial integer variables instead of integer variables with a very large upper bound

Semi-continuous variable

  • may be zero, or any value between the intermediate bound and the upper bound
  • Semi-continuous integer variables also available: may be zero, or any integer value between the intermediate bound and the upper bound

Special ordered sets

  • set of decision variables
  • each variable has a different ordering value, which orders the set
  • Special ordered sets of type 1 (SOS1): at most one variable may be non-zero
  • Special ordered sets of type 2 (SOS2): at most two variables may be non-zero; the non-zero variables must be adjacent in ordering

Indicator constraints

  • associate a binary variable with a linear or nonlinear constraint
  • model an implication: the constraint is active only if the condition is true

General constraints

  • specific constraint relations that are recognized by MIP solvers
  • piecewise linear: can be used in place of SOS-2 formulations
  • absolute value, minimum value, maximum value of discrete or continuous decision variables
  • logical constraints: 'and' and 'or' over binary variables

Batch sizes

Must deliver in batches of 10, 20, 30, ...

  • Decision variables

    nship number of batches delivered: integer
    ship quantity delivered: continuous

  • Constraint formulation

    ship = 10 · nship

Ordered alternatives

Suppose you have N possible investments of which at most one can be selected. The capital cost is CAPi and the expected return is RETi.

  • Often use binary variables to choose between alternatives. However, SOS1 are more efficient to choose between a set of graded (ordered) alternatives.
  • Define a variable di to represent the decision, di = 1 if investment i is picked
  • Binary variable (standard) formulation

    di : binary variables

    Maximize: ret = ∑i RETi·di
    i di ≤ 1
    i CAPi·di ≤ MAXCAP

  • SOS1 formulation

    {di; ordering value CAPi} : SOS1

    Maximize: ret = ∑i RETi·di
    i di ≤ 1
    i CAPi·di ≤ MAXCAP

Special ordered sets in Mosel

  • special ordered sets are a special type of linear constraint
  • the set includes all variables in the constraint
  • the coefficient of a variable is used as the ordering value (i.e., each value must be unique)

declarations
  I=1..4
  d: array(I) of mpvar
  CAP: array(I) of real
  My_Set, Ref_row: linctr
end-declarations

My_Set:= sum(i in I) CAP(i)*d(i) is_sos1

or alternatively (must be used if a coefficient is 0):

Ref_row:= sum(i in I) CAP(i)*d(i)
makesos1(My_Set, union(i in I) {d(i)}, Ref_row)

Price breaks

All items discount

All items discount: when buying a certain number of items we get discounts on all items that we buy if the quantity we buy lies in certain price bands.

Intro/pricebreakai

less than B1 COST1 each
≥ B1 and < B2 COST2 each
≥ B2 and < B3 COST3 each

Formulation with binary variables or Special Ordered Sets of type 1 (SOS1):

  • Define binary variables bi (i=1,2,3), where bi is 1 if we pay a unit cost of COSTi.
  • Real decision variables xpi represent the number of items bought at price COSTi.
  • The quantity bought is given by x= ∑ixpi , with a total price of iCOSTi·xpi
  • MIP formulation :

    i bi = 1
    xp1 ≤ B1· b1
    Bi-1· bi ≤ xpi ≤ Bi· bi for i=2,3

    where the variables bi are either defined as binaries, or they form a Special Ordered Set of type 1 (SOS1), where the order is given by the values of the breakpoints Bi.

Formulation as piecewise linear expression:

  • Specification as list of piecewise linear segments with associated intervals:

    i=1,2,3 [Bi-1,Bi[ : COSTi·x

    TotalCost:= pwlin(union(i in 1..3) [pws(B(i-1), COST(i)*x)])
  • Specification as list of points:

    i=1,2,3 [Bi-1,COSTi·Bi-1,Bi,COSTi·Bi]

    TotalCost:= pwlin(x, union(i in 1..3) [B(i-1), COST(i)*B(i-1), B(i), COST(i)*B(i)])

Incremental pricebreaks

Incremental pricebreaks: when buying a certain number of items we get discounts incrementally. The unit cost for items between 0 and B1 is COST1, items between B1 and B2 cost COST2 each, etc.

Intro/pricebrinc2

Formulation with Special Ordered Sets of type 2 (SOS2):

  • Associate real valued decision variables wi (i=0,1,2,3) with the quantity break points B0 = 0, B1, B2 and B3.
  • Cost break points CBPi (=total cost of buying quantity Bi):

    CBP0=0
    CBPi = CBPi-1+COSTi· (Bi-Bi-1) for i=1,2,3

  • Constraint formulation:

    iwi=1
    TotalCost = ∑i CBPi· wi
    x = ∑i Bi· wi

    where the wi form a SOS2 with reference row coefficients given by the coefficients in the definition of the total amount x.
    For a solution to be valid, at most two of the wi can be non-zero, and if there are two non-zero they must be contiguous, thus defining one of the line segments.

is_sos2 cannot be used here due to the 0-valued coefficient of w0

  Defx := x = sum(i in 1..3) B(i)*w(i)
  makesos2(My_Set, union(i in 0..3) {w(i)}, Defx)
  sum(i in 1..3) w(i) = 1

Formulation using binaries:

  • Define binary variables bi (i=1,2,3), where bi is 1 if we have bought any items at a unit cost of COSTi.
  • Real decision variables xpi (i=1,..3) for the number of items bought at price COSTi.
  • Total amount bought: x = i xpi
  • Constraint formulation:

    (Bi-Bi-1)· bi+1 ≤ xpi ≤ (Bi-Bi-1)· bi for i=1,2
    xp3 ≤ (B3-B2)· b3
    b1 ≥ b2 ≥ b3

Formulation as piecewise linear expression:

  • Specification as list of slopes with associated intervals:

    i=1,2,3 [Bi-1,Bi[ : COSTi

    Only points of slope changes are specified, start value is 0

    TotalCost:= pwlin(x, union(i in 1..2) [B(i)], union(i in 1..3) [COST(i)])
  • Specification as list of piecewise linear segments with associated intervals:

    i=1,2,3 [Bi-1,Bi[ : CBPi-1+COSTi·(x-Bi-1)

    TotalCost:= pwlin(union(i in 1..3) [pws(B(i-1), CBP(i-1)+COST(i)*(x-B(i-1)))])
  • Specification as list of points:

    i=0,1,2,3 [Bi,CBPi]

    TotalCost:= pwlin(x, union(i in 0..3) [B(i), CBP(i)])

Non-linear functions

Can model non-linear functions in the same way as incremental pricebreaks

  • approximate the non-linear function with a piecewise linear function
  • use an SOS2 to model the piecewise linear function
  • alternatively, formulate as piecewise linear expression by specifying a list of points
  • note that certain nonlinear functions (e.g. absolute value, minimum value, maximum value) are recognized by MIP solvers and can be used directly in the formulation of MIP models, see Section General constraints

Non-linear function in a single variable

Intro/soslin2
  • x-coordinates of the points: R1, ..., R4
    y-coordinates FR1, ..., FR4. So point 1 is (R1,FR1) etc.
  • Let weights (decision variables) associated with point i be wi (i=1,...,4)
  • Form convex combinations of the points using weights wi to get a combination point (x,y):

    x = ∑i wi·Ri
    y = ∑i wi·FRi
    i wi = 1

    where the variables wi form an SOS2 set with ordering coefficients defined by values Ri.

Mosel implementation (SOS-2):

 declarations
  I=1..4
  x,y: mpvar
  w: array(I) of mpvar
  R,FR: array(I) of real
 end-declarations

! ...assign values to arrays R and FR...

! Define the SOS-2 with "reference row" coefficients from R
 Defx:= sum(i in I) R(i)*w(i) is_sos2
 sum(i in I) w(i) = 1

! The variable and the corresponding function value we want to approximate
 x = Defx
 y = sum(i in I) FR(i)*w(i)

Mosel implementation (piecewise linear):

 uses "mmxnlp"
 declarations
  I=1..4
  x,y: mpvar
  R,FR: array(I) of real
 end-declarations

! ...assign values to arrays R and FR...

! Define the piecewise linear expression
 y = pwlin(x, sum(i in I) [R(i), FR(i)])

! Only consider the x-values interval defined by the breakpoints
 setrange(x, R(1), R(4))

Non-linear function in two variables

Interpolation of a function f in two variables: approximate f at a point P by the corners C of the enclosing square of a rectangular grid (NB: the representation of P=(x,y) by the four points C obviously means a fair amount of degeneracy).

Intro/sosquad2
  • x-coordinates of grid points: X1, ..., Xn
    y-coordinates of grid points: Y1, ..., Ym. So grid points are (Xi,Yj).
  • Function evaluation at grid points: FXY11, ..., FXYnm
  • Define weights (decision variables) associated with x and y coordinates, wxi respectively wyj, and for each grid point (X(i),Y(j)) define a variable wxyij
  • Form convex combinations of the points using the weights to get a combination point (x,y) and the corresponding function approximation:

    x = ∑i wxi·Xi
    y = ∑j wyj·Yj
    f = ∑ij wxyij·FXYij
    ∀ i=1,...,n: ∑j wxyij = wxi
    ∀ j=1,...,m: ∑i wxyij = wyj
    i wxi = 1
    j wyj = 1

    where the variables wxi form an SOS2 set with ordering coefficients defined by values Xi, and the variables wyj are a second SOS2 set with coordinate values Yj as ordering coefficients.
 declarations
  RX,RY:range
  X: array(RX) of real          ! x coordinate values of grid points
  Y: array(RY) of real          ! y coordinate values of grid points
  FXY: array(RX,RY) of real     ! Function evaluation at grid points
 end-declarations

! ... initialize data 

 declarations
  wx: array(RX) of mpvar        ! Weight on x coordinate
  wy: array(RY) of mpvar        ! Weight on y coordinate
  wxy: array(RX,RY) of mpvar    ! Weight on (x,y) coordinates
  x,y,f: mpvar
 end-declarations

! Definition of SOS (assuming coordinate values <>0)
 sum(i in RX) X(i)*wx(i) is_sos2
 sum(j in RY) Y(j)*wy(j) is_sos2

! Constraints 
 forall(i in RX) sum(j in RY) wxy(i,j) = wx(i)
 forall(j in RY) sum(i in RX) wxy(i,j) = wy(j)
 sum(i in RX) wx(i) = 1
 sum(j in RY) wy(j) = 1

! Then x, y and f can be calculated using 
 x = sum(i in RX)  X(i)*wx(i)
 y = sum(j in RY)  Y(j)*wy(j)
 f = sum(i in RX,j in RY) FXY(i,j)*wxy(i,j)

! f can take negative or positive values (unbounded variable)
 f is_free

Minimum activity level

Continuous production rate make. May be 0 (the plant is not operating) or between allowed production limits MAKEMIN and MAKEMAX

  • Can impose using a semi-continuous variable: may be zero, or any value between the intermediate bound and the upper bound
  • Semi-continuous variables are slightly more efficient than the alternative binary variable formulation that we saw before. But if you incur fixed costs on any non-zero activity, you must use the binary variable formulation (see Section Minimum activity level).
make is_semcont MAKEMIN
make <= MAKEMAX

Partial integer variables

  • In general, try to keep the upper bound on integer variables as small as possible. This reduces the number of possible integer values, and so reduces the time to solve the problem.
  • Sometimes this is not possible – a variable has a large upper bound and must take integer values.
    ⇒ Try to use partial integer variables instead of integer variables with a very large upper bound: takes integer values for small values, where it is important to be precise, but takes real values for larger values, where it is OK to round the value afterwards.
  • For example, it may be important to clarify whether the value is 0, 1, 2, ..., 10, but above 10 it is OK to get a real value and round it.
x is_partint 10        ! x is integer valued from 0 to 10
x <= 20                ! x takes real values from 10 to 20

General constraints

Certain nonlinear constraint relations (refered to as general constraints) are recognized by MIP solvers and they are treated as MIP modeling constructs. These include

The Mosel implementation of the numerical constraints abs, fmin and fmax makes it possible to use linear expressions as argument to these functions. Note that models using these general constraints need to load the mmxnlp module in addition to mmxprs although the problems will be solved by the Xpress MIP solver.

 uses "mmxnlp"

 public declarations
   R=1..3
   x: array(R) of mpvar
   y,z: mpvar
 end-declarations

 forall(i in R) x(i) <= 20
 abs(x(1)-2*x(2)) <= 10                     ! Absolute value constraint
 MinCtr:= fmin(union(i in R) [x(i)]) >= 5   ! Minimum value constraint
 y = fmax(x(3), 20, x(1)-z)                 ! Maximum value constraint

 maximize(sum(i in R) x(i))                 ! Solve as MIP problem
 if getprobstat=XPRS_OPT then               ! Solution reporting
   writeln("Solution: ", getobjval)
   forall(i in R) write("x", i, "=", x(i).sol, ", ")
   writeln("y=", y.sol, ", z=", z.sol)
   writeln("abs=", getsol(abs(x(1)-2*x(2))), ", Min of x(i)=", MinCtr.sol+5)
 else
   writeln("No solution")
 end-if

© 2001-2025 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.