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





burglar_rec.mos

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

   file burglar_rec.mos
   ````````````````````
   Use of records.
   
   A burglar considers eight items that have different values
   and weights. He wants to take a group of items that maximizes
   the total value while the total weight is not more than the
   maximum 'WTMAX' he can carry.

   This IP model represents the so-called knapsack problem where 
   binary decision variable 'take(i)' takes value 1 if item 'i'
   is taken; 0 otherwise. This implementation illustrates that 
   data may also be given in the form of a single record, in this
   case the array 'I' which is populated with the data file 
   burglar_rec.dat.

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

model "Burglar (records)"
 uses "mmxprs"
 
 declarations
  WTMAX = 102                    ! Maximum weight allowed
  ITEMS = {"camera", "necklace", "vase", "picture", "tv", "video", 
           "chest", "brick"}     ! Index set for items
  
  I: array(ITEMS) of record
   VALUE: real                   ! Value of items
   WEIGHT: real                  ! Weight of items
  end-record
  take: array(ITEMS) of mpvar    ! 1 if we take item i; 0 otherwise
 end-declarations

 initializations from 'burglar_rec.dat'
  I
 end-initializations

! Objective: maximize total value
 MaxVal:= sum(i in ITEMS) I(i).VALUE*take(i) 

! Weight restriction
 sum(i in ITEMS) I(i).WEIGHT*take(i) <= WTMAX

! All variables are 0/1
 forall(i in ITEMS) take(i) is_binary  

 maximize(MaxVal)                 ! Solve the MIP-problem

! Print out the solution
 writeln("Solution:\n Objective: ", getobjval)
 forall(i in ITEMS)  writeln(" take(", i, "): ", getsol(take(i)))
end-model

Back to examples browserNext example