FICO
FICO Xpress Optimization Examples Repository
FICO Optimization Community FICO Xpress Optimization Home
Back to examples browserNext example

Introductory examples

Description
Problem name and type, featuresDifficulty
approx Approximation: Piecewise linear approximation **
SOS-2, Special Ordered Sets, piecewise linear approximation of a nonlinear function, pwlin
burglar MIP modeling: Knapsack problem: 'Burglar' *
simple MIP model with binary variables, data input from text data file, array initialization, numerical indices, string indices, record data structure
chess LP modeling: Production planning: 'Chess' problem *
simple LP model, solution output, primal solution values, slack values, activity values, dual solution values
pricebrai All item discount pricing: Piecewise linear function ***
SOS-1, Special Ordered Sets, piecewise linear function, approximation of non-continuous function, step function, pwlin
pricebrinc Incremental pricebreaks: Piecewise linear function ***
SOS-2, Special Ordered Sets, piecewise linear function, step function


Further explanation of this example: 'Applications of optimization with Xpress-MP', Introductory examples (Chapters 1 to 5) of the book 'Applications of optimization with Xpress-MP'

mosel_app_intro.zip[download all files]

Source Files

Data Files





approx2.mos

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

   file approx2.mos
   ````````````````
   Function approximation via piecewise linear expression   

   In this example, we aim to represent f as a function of x 
   that is specified via four line segments between the five 
   points (X(i),FX(i)).  
   We use the 'pwlin' construct to state f as a piecewise linear
   constraint that will be handled directly by the MIP solver
   although the constraint formulation requires the nonlinear
   module 'mmxnlp'.

   (c) 2021 Fair Isaac Corporation
       author: S. Heipcke, July 2021
*******************************************************!)

model "Approximation (pwlin)"
 uses "mmxnlp"

 declarations
  NB = 5
  BREAKS = 1..NB
  X,FX: array(BREAKS) of real          ! Coordinates of break points
  x,f: mpvar                           ! Decision variables
 end-declarations

 X::  [1, 2.2, 3.4, 4.8, 6.5]
 FX:: [2, 3.2, 1.4, 2.5, 0.8]

 f = pwlin(x, union(i in BREAKS) [X(i),FX(i)])
 
! Bounds
 1<=x; x<=6.5

! Solve the problem
 minimize(f)
 
 writeln("Objective value: ", getobjval)
 writeln("x: ", getsol(x))
  
end-model 

Back to examples browserNext example