| |||||||||||||||
Basic MIP tasks: binary variables; logic constraints Description We wish to choose among items of different value and
weight those that result in the maximum total value for
a given weight limit.
Source Files By clicking on a file name, a preview is opened at the bottom of this page.
burglar.mos (!******************************************************* * Mosel Example Problems * * ====================== * * * * file burglar.mos * * ```````````````` * * Example for the use of the Mosel language * * (Burglar problem) * * * * (c) 2008 Fair Isaac Corporation * * author: S. Heipcke, 2001 * *******************************************************!) model Burglar ! Start a new model uses "mmxprs" ! Load the optimizer library declarations Items=1..8 ! Index range for items VALUE: array(Items) of real ! Value of items WEIGHT: array(Items) of real ! Weight of items WTMAX=102 ! Max weight allowed for haul x: array(Items) of mpvar ! 1 if we take item i; 0 otherwise end-declarations ! Item: 1 2 3 4 5 6 7 8 VALUE :: [15,100, 90, 60, 40, 15, 10, 1] WEIGHT:: [ 2, 20, 20, 30, 40, 30, 60, 10] MaxVal:= sum(i in Items) VALUE(i)*x(i) ! Objective: maximize total value ! Weight restriction WtMax:= sum(i in Items) WEIGHT(i)*x(i) <= WTMAX forall(i in Items) x(i) is_binary ! All x are 0/1 maximize(MaxVal) ! Solve the MIP-problem ! Print out the solution writeln("Solution:\n Objective: ", getobjval) forall(i in Items) writeln(" x(", i, "): ", x(i).sol) end-model | |||||||||||||||
© Copyright 2024 Fair Isaac Corporation. |