| |||||||||||||||||||||||||||
| |||||||||||||||||||||||||||
|
Burglar - Data source access from Mosel models Description
Source Files By clicking on a file name, a preview is opened at the bottom of this page. Data Files
burglar2e.mos
(!******************************************************
Mosel Example Problems
======================
file burglar2e.mos
``````````````````
Use of spreadsheet I/O drivers for data handling.
(c) 2008 Fair Isaac Corporation
author: S. Heipcke, Feb. 2007, rev. Dec. 2012
*******************************************************!)
model "Burglar2 (Excel)"
uses "mmxprs", "mmsheet"
parameters
! CNCTEXC = "mmsheet.excel:burglar.xls" ! Windows only
CNCTEXC = "mmsheet.xls:burglar.xls" ! Windows and Linux
end-parameters
declarations
WTMAX = 102 ! Maximum weight allowed
ITEMS: set of string ! Index set for items
VALUE: array(ITEMS) of real ! Value of items
WEIGHT: array(ITEMS) of real ! Weight of items
SOLTAKE: array(ITEMS) of real ! Solution values
end-declarations
! Spreadsheet range includes header line -> use option 'skiph'
initializations from CNCTEXC
[VALUE,WEIGHT] as "skiph;BurgData"
end-initializations
!)
(! Alternatively:
initializations from CNCTEXC
[VALUE,WEIGHT] as "[burglar$B4:D11]"
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 problem
! Solution output
forall(i in ITEMS) SOLTAKE(i):= getsol(take(i))
writeln(SOLTAKE)
! Insert solutions into spreadsheet: results from previous runs
! are overwritten by new output
! (only first line of output range is specified -> use option 'grow')
initializations to CNCTEXC
SOLTAKE as "skiph;grow;SolTake"
end-initializations
!)
(! Alternatively:
initializations to CNCTEXC
SOLTAKE as "grow;[burglar$F4:G4]"
end-initializations
!)
(! Or:
initializations to CNCTEXC
SOLTAKE as "[burglar$F4:G11]"
end-initializations
!)
end-model
| |||||||||||||||||||||||||||
| © Copyright 2025 Fair Isaac Corporation. |