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





pricebrai2.mos

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

   file pricebrai2.mos
   ```````````````````
   Modeling price breaks:
   All item discount pricing
   - formulation as piecewise linear expression -
   
   This implementation represents the situation where we 
   buy a certain number of items and we get discounts on 
   all items that we buy if the quantity we buy lies in 
   certain price bands. We have three price bands. If we 
   buy a number of items in [0,B1) then for each item we 
   pay COST1, if the quantity we buy lies in [B1,B2) we 
   pay COST2 for each item. Finally if we buy an amount 
   in [B2,B3) then we pay an amount COST3 for each item. 
   This sort of pricing is called all item discount pricing.
   
   To model these item price breaks we use a 'pwlin' 
   expression specified via a list of the linear segments.
   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 "All item discount (pwlin)"
 uses "mmxnlp"
 
 declarations
  NB = 3                                ! Number of price bands
  BREAKS = 1..NB
  COST: array(BREAKS) of real           ! Cost per unit
  x: mpvar                              ! Number of items bought
  B: array(0..NB) of real               ! Break points of cost function
 end-declarations
 
 DEM:= 150                              ! Demand
 B:: [0, 50, 120, 200]
 COST:: [ 1, 0.7, 0.5]

 ! Objective: Specification as list of piecewise linear segments
 TotalCost:= pwlin(x, union(i in 1..3) [B(i-1), COST(i)*B(i-1), B(i), COST(i)*B(i)])
 ! Objective: Specification as list of points
 ! TotalCost:= pwlin(x, union(i in 1..3) [B(i-1), COST(i)*B(i-1), B(i), COST(i)*B(i)])

! Meet the demand
 x = DEM 

! Solve the problem
 minimize(TotalCost)

! Solution printing
 writeln("Objective: ", getobjval, 
         " (price per unit: ", getobjval/DEM, ")")
 forall(i in BREAKS) 
  writeln("Interval ", i, ": ", if(x.sol>=B(i-1) and x.sol<=B(i),x.sol,0), 
    " (price per unit: ", COST(i), ")")

end-model

Back to examples browserNext example