| |||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||
|
Blend - data input from external sources Description This example is taken from the 'Mosel User Guide', Section 2.2. A blending example. In many applications data are provided in the form of spreadsheets or need to be extracted from databases. Mosel has facilities whereby the contents of ranges within spreadsheets may be read into data tables and databases may be accessed. Mosel's ODBC interface (module mmodbc) may be used to read the data from databases. The ODBC technology is a generic means for accessing databases and some spreadsheets such as certain versions of Microsoft Excel also support (a reduced set of) ODBC functionality. The ODBC interface can be used in initializations blocks that automatically generate the required SQL statments and it is also possible to employ SQL statements directly in Mosel models (see blend4.mos). Mosel also provides specific interfaces to Excel spreadsheets through the module mmsheet. These interfaces that support all basic tasks of data exchange (model files blend3*.mos) should be used for working with Excel data.
Source Files By clicking on a file name, a preview is opened at the bottom of this page.
Data Files
blend.mos
(!******************************************************
Mosel User Guide Example Problems
=================================
file blend.mos
``````````````
Reading data from file.
(c) 2008 Fair Isaac Corporation
author: S. Heipcke, 2001
*******************************************************!)
model "Blend"
uses "mmxprs"
declarations
REV = 125 ! Unit revenue of product
MINGRADE = 4 ! Minimum permitted grade of product
MAXGRADE = 5 ! Maximum permitted grade of product
ORES = 1..2 ! Range of ores
COST: array(ORES) of real ! Unit cost of ores
AVAIL: array(ORES) of real ! Availability of ores
GRADE: array(ORES) of real ! Grade of ores (measured per unit of mass)
use: array(ORES) of mpvar ! Quantities of ores used
end-declarations
! Read data from file blend.dat
initializations from 'blend.dat'
COST
AVAIL
GRADE
end-initializations
! Alternatively, uncomment to read data from blendb.dat
(!
initializations from 'blendb.dat'
[COST,AVAIL,GRADE] as 'BLENDDATA'
end-initializations
!)
! Objective: maximize total profit
Profit:= sum(o in ORES) (REV-COST(o))* use(o)
! Lower and upper bounds on ore quality
sum(o in ORES) (GRADE(o)-MINGRADE)*use(o) >= 0
sum(o in ORES) (MAXGRADE-GRADE(o))*use(o) >= 0
! Set upper bounds on variables
forall(o in ORES) use(o) <= AVAIL(o)
maximize(Profit) ! Solve the LP-problem
! Print out the solution
writeln("Solution:\n Objective: ", getobjval)
forall(o in ORES) writeln(" use(" + o + "): ", getsol(use(o)))
end-model
| |||||||||||||||||||||||||||||||||||||
| © Copyright 2025 Fair Isaac Corporation. |