FICO Xpress Optimization Examples Repository
 FICO Optimization Community FICO Xpress Optimization Home

Robust formulations of the single knapsack problem

Description
Introductory example from the whitepaper 'Robust Optimization with Xpress'. Alternative robust formulations of a small single knapsack problem:
• deterministic version: knapsack_basic.mos
• ellipsoidal uncertainty: knapsack_ellipsoid.mos
• polyhedral uncertainty: knapsack_polyhedron.mos
• historical data used as uncertainty scenario: knapsack_scenario.mos
• simple bounded uncertains: knapsack_simplebounds.mos, knapsack_simplebounds_direct.mos
Further explanation of this example: Whitepaper 'Robust Optimization with Xpress', Section 1 Introduction

 robknapsack.zip [download all files]

Source Files
By clicking on a file name, a preview is opened at the bottom of this page.
 knapsack_basic.mos [download] knapsack_ellipsoid.mos [download] knapsack_polyhedron.mos [download] knapsack_scenario.mos [download] knapsack_simplebounds.mos [download] knapsack_simplebounds_direct.mos [download]

knapsack_basic.mos

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

Example model for the
Robust Optimization with Xpress white paper

(c) 2014 Fair Isaac Corporation

*******************************************************!)
model Knapsack
uses "mmrobust"                                 ! Load the robust library

parameters
NUM=5                                          ! Number of items
MAXVAL=100                                     ! Maximum value
MAXWEIGHT=80                                   ! Maximum weight
WTMAX=102                                      ! Max weight allowed for haul
end-parameters

declarations
Items=1..NUM                                   ! Index range for items
VALUE: array(Items) of real                    ! Value of items
WEIGHT: array(Items) of real                   ! Weight of items
x: array(Items) of mpvar                       ! Decision variables
end-declarations

setrandseed(5);
forall(i in Items) do
VALUE(i):=50+random*MAXVAL
WEIGHT(i):=1+random*MAXWEIGHT
end-do
forall(i in Items) x(i) is_binary               ! All x are 0/1

MaxVal:= sum(i in Items) VALUE(i)*x(i)          ! Objective: maximize total value
WtMax:= sum(i in Items) WEIGHT(i)*x(i) <= WTMAX ! Weight restriction

maximize(MaxVal)

writeln("Solution:\n Objective: ", getobjval)
writeln("Item  Weight  Value")
forall(i in Items)
writeln(i, ": ", getsol(x(i)), strfmt(WEIGHT(i),8,2), strfmt(VALUE(i),8,2))

end-model