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





pricebrinc3.mos

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

   file pricebrinc3.mos
   ````````````````````
   Incremental pricebreaks formulated with 
   piecewise linear expressions

   This model represents the situation where we buy a certain
   number of items and we get discounts incrementally. The
   unit cost for items between 0 and B1 is C1, whereas items
   between B1 and B2 cost C2 each, and items between B2 and
   B3 cost C3 each.

   We model the incremental price breaks via 'pwlin' expressions. 
   Three different versions can be used for representing 
   this particular case of a continuous cost function.
   This general constraint is 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 "Incremental pricebreaks (pwlin)"
 uses "mmxnlp"
 
 declarations
  NB = 3                                ! Number of price bands
  BREAKS = 0..NB
  COST: array(1..NB) of real            ! Cost per unit within price bands
  x: mpvar                              ! Total quantity bought
  B,CBP: array(BREAKS) of real          ! Break points, cost break points
 end-declarations
 
 DEM:= 150                              ! Demand
 B::  [0, 50, 120, 200]
 COST:: [0.8, 0.5, 0.3]
 
 CBP(0):= 0
 forall(i in 1..NB) CBP(i):= CBP(i-1) + COST(i) * (B(i)-B(i-1))

! Objective: total price (uncomment one of the three following options)

! 1- Specification as a list of slopes with associated intervals:
! (only points of slope changes are specified, the start value is 0):
!TotalCost:= pwlin(x, union(i in 1..2) [B(i)], union(i in 1..3) [COST(i)])

! 2- Specification as a list of piecewise linear segments (pws) with associated intervals:
TotalCost:= pwlin(union(i in 1..3) [pws(B(i-1), CBP(i-1)+COST(i)*(x-B(i-1)))])

! 3- Specification as a list of points:
!TotalCost:= pwlin(x, union(i in 0..3) [B(i), CBP(i)])

! Meet the demand
 x = DEM 

! Solve the problem
 minimize(TotalCost)

! Solution printing
 writeln("Objective: ", getobjval, 
         " (avg price per unit: ", getobjval/DEM, ")")
 forall(i in 1..NB)
  writeln("Interval ", i, ": ", minlist(B(i)-B(i-1),x.sol-B(i-1)), " (price per unit: ", COST(i), ")")

end-model

Back to examples browserNext example