| |||||||||
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:
Source Files By clicking on a file name, a preview is opened at the bottom of this page. 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 | |||||||||
© Copyright 2024 Fair Isaac Corporation. |