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]





soslin.mos

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

   file soslin.mos
   ```````````````
   Approximation of a nonlinear function by a SOS-2.
   - Example discussed in mipformref whitepaper -  
    
   (c) 2008 Fair Isaac Corporation
       author: S. Heipcke, 2002, rev. Feb. 2022
*******************************************************!)

model "soslin"
 uses "mmxprs"

 public declarations
  I=1..4                          ! Set of breakpoints
  x,y: mpvar                      ! The actual decision variables x and y
  w: array(I) of mpvar            ! Weight variables for SOS formulation
  R,FR: array(I) of real           ! X and Y coordinates of breakpoints
 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]

! 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)

! 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