FICO
FICO Xpress Optimization Examples Repository
FICO Optimization Community FICO Xpress Optimization Home
Back to examples browserPrevious exampleNext example

Linearizations and approximations via SOS and piecewise linear (pwlin) expressions

Description
Various examples of using SOS (Special Ordered Sets of type 1 or 2) and piecewise linear expressions to represent nonlinear functions in MIP models implemented with Mosel (files *.mos) or BCL (files *.cxx).
  • approximating a continuous nonlinear function in a single variable via piecewise linear expressions (soslingc.mos) or SOS-1 (soslin.*);
  • approximating a continuous nonlinear function in two variables via SOS-2 (sosquad.*);
  • price breaks: all items discount (non-continuous piecewise linear function) formulated via piecewise linear expressions (pricebrai) or SOS-1 (pricebrai SOS);
  • incremental pricebreaks formulated via piecewise linear expressions (pricebrinc), SOS-2 (pricebrinc SOS), or binary variables (pricebrinc bin).
Further explanation of this example: Whitepaper 'MIP formulations and linearizations', Section Non-linear functions


Source Files
By clicking on a file name, a preview is opened at the bottom of this page.
soslin.cxx[download]
soslin.mos[download]
soslingc.mos[download]
sosquad.cxx[download]
sosquad.mos[download]





soslingc.mos

(!*******************************************************
   Mosel Example Problems 
   ======================

   file soslingc.mos
   `````````````````
   Approximation of a nonlinear function by a SOS-2.
   Formulation using the pwlin construct 
   - Example discussed in mipformref whitepaper -  
     
   (c) 2020 Fair Isaac Corporation
       author: S. Heipcke, July 2020
*******************************************************!)

model "soslingc"
 uses "mmxnlp"

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

! These values would normally be calculated here or read in from file
 R:: [1, 2.5, 4.5, 6.5]
 FR::[1.5, 6, 3.5, 2.5]

! The variable and the corresponding function value we want to approximate
 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))

! Set a bound to make the problem more interesting
 x >= 2
 
(! Uncomment to display solver problem on screen
 setparam("XPRS_loadnames", true)
 loadprob(y)
 writeprob("","l")
!)

! Solve the problem
 minimize(y)
 
 writeln("Solution: ", getobjval)
 writeln("x: ", x.sol) 
 
end-model 

Back to examples browserPrevious exampleNext example