| |||||||||||||||||||||||||||||||||||||
Introductory examples Description
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'
Source Files By clicking on a file name, a preview is opened at the bottom of this page. Data Files burglar2.mos (!****************************************************** Mosel Example Problems ====================== file burglar2.mos ````````````````` Knapsack problem 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 how problem data could be read into tables from text files. Instead of having the item data embedded in the Mosel model file, we have the data in a file and use 'initializations from'. (c) 2008 Fair Isaac Corporation author: S. Heipcke, Aug. 2002 *******************************************************!) model "Burglar 2" uses "mmxprs" declarations ITEMS: set of string ! Set of items WTMAX = 102 ! Maximum weight allowed VALUE: array(ITEMS) of real ! Value of items WEIGHT: array(ITEMS) of real ! Weight of items end-declarations initializations from 'burglar.dat' VALUE WEIGHT end-initializations (! alternatively: initializations from 'burglar2.dat' [VALUE, WEIGHT] as 'KNAPSACK' end-initializations !) declarations take: array(ITEMS) of mpvar ! 1 if we take item i; 0 otherwise end-declarations ! Objective: maximize total value MaxVal:= sum(i in ITEMS) VALUE(i)*take(i) ! Weight restriction sum(i in ITEMS) WEIGHT(i)*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 | |||||||||||||||||||||||||||||||||||||
© Copyright 2023 Fair Isaac Corporation. |