FICO Xpress Optimization Examples Repository
 FICO Optimization Community FICO Xpress Optimization Home

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.

• blend.mos: Reading data from text files (requires blend.dat or blendb.dat)
• blend2.mos: Using runtime parameters (requires blend.dat)
• blend3c.mos: Reading data in CSV format (requires blend.csv)
• blend3e.mos: Reading data from an Excel spreadsheet, using the excel I/O driver (requires blend.xls)
• blend4.mos: Reading data from a database (requires blend.mdb or blend.sqlite)
Further explanation of this example: 'Mosel User Guide', Section 2.2 A blending example

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


(c) 2008 Fair Isaac Corporation
author: S. Heipcke, 2001
*******************************************************!)

model "Blend"
uses "mmxprs"

declarations
REV = 125                      ! Unit revenue 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
end-initializations

! Alternatively, uncomment to read data from blendb.dat
(!
initializations from 'blendb.dat'
end-initializations
!)

! Objective: maximize total profit
Profit:= sum(o in ORES) (REV-COST(o))* use(o)

! Lower and upper bounds on ore quality