FICO
FICO Xpress Optimization Examples Repository
FICO Optimization Community FICO Xpress Optimization Home
Back to examples browserPrevious exampleNext example

Reading 3-dimensional arrays

Description
This example shows how to read a 3-dimensional array from an excel file (threedimarr.mos) and from a generic spreadsheet (threedimarr5.mos) where the last index is specifed 'across the columns', resulting in a pivot-style table format where the first N-1 columns contain index values (here: 2 index columns). Model versions (2) and (4) show the same example for databases, and model version (6) works with data in CSV format.

Note that standard use of the 'partndx' option for spreadsheets assumes that the last index is a set of type 'range', the example partidxstr.mos defines a utility routine 'makelabel' that makes it possible to work with a 'set of string' for the last index.

threedimarr.zip[download all files]

Source Files

Data Files
threedim.csv[download]
threedim.xls[download]
threedim.xlsx[download]
threedim.mdb[download]
threedim.sqlite[download]
partidxdata.csv[download]
partidxdata.xls[download]
partidxdata.xlsx[download]





threedimarr.mos

(!*******************************************************
   Mosel Example Problems 
   ======================

   file threedimarr.mos
   ````````````````````
   Reading 3-dimensional arrays.
   - Using 'initializations from' with the odbc driver -
       
   (c) 2010 Fair Isaac Corporation
       author: S. Heipcke, July 2010, rev. Jan. 2014
*******************************************************!)

model ThreeDimArr
 uses "mmodbc"

 parameters
  CSTR = "threedim.mdb"        ! Use Access database `threedim.mdb'
!  CSTR = 'threedim.sqlite'    ! Use SQLite database `threedim.sqlite' directly
                               ! Use SQLite database `threedim.sqlite' via ODBC
!  CSTR = 'DSN=sqlite;DATABASE=threedim.sqlite'
 end-parameters

 declarations
  I: range
  J: set of string
  K = 1..5	              ! The last index set must be defined in the model
  A: dynamic array(I,J,K) of real
 end-declarations

 initializations from 'mmodbc.odbc:debug;noindex;' + CSTR
  A as 'Tab_23'
 end-initializations

 writeln("A: ")
 forall(i in I, j in J, k in K | exists(A(i,j,k)))
  writeln("A(", i, ",", j, ",", k, "): ", A(i,j,k))

end-model



Back to examples browserPrevious exampleNext example