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

Reading and writing records and lists

Description
This set of examples shows how to work with advanced data structures when accessing data in spreadsheets and databases:
  • reading in records (recordin*.mos)
  • writing out records (recordout*.mos)
  • reading and writing lists (listinout*.mos)
The basic model version uses an ODBC connection to spreadsheets or databases through the odbc driver, model version (2) uses ODBC through SQL statements, and model version (3) uses the software-specific driver excel to access Excel spreadsheets. Model version (1) shows how to work with Mosel's text data file format.

Further explanation of this example: Xpress Whitepaper 'Using ODBC and other database interfaces with Mosel', Section Examples - Working with lists - Working with records.

listrecord.zip[download all files]

Source Files

Data Files
recorddata.dat[download]
recorddata.csv[download]
recorddata2.csv[download]
recorddata.mdb[download]
recorddata.xls[download]
recorddata2.xls[download]
recordout_templ.xls[download]
recorddata.xlsx[download]
recorddata2.xlsx[download]
recorddata.sqlite[download]
listdata.dat[download]
listdata.csv[download]
listdata.mdb[download]
listdata.xls[download]
listdata.xlsx[download]
listdata.sqlite[download]





listinout1.mos

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

   file listinout1.mos
   ```````````````````
   Reading/writing lists from/to text files.
   
   (c) 2008 Fair Isaac Corporation
       author: S. Heipcke, Nov. 2007
*******************************************************!)

model "List handling (Text file)"

 declarations
  R: range
  LI: list of integer
  LS,LS2: array(R) of list of string   ! With text data files we can use
                                       ! compositions of structured types
 end-declarations

 initializations from "listdata.dat"
  LI as "List1"
  LS as "List2"
 end-initializations 

! Display the lists
 writeln("LI: ", LI)
 writeln("LS: ", LS)

! Reverse the list LI
 reverse(LI)

! Append some text to every entry of LS
 forall(i in R) LS2(i):= sum(l in LS(i)) [l+" year"+i]

! Display the modified lists
 writeln("LI: ", LI)
 writeln("LS2: ", LS2)

 initializations to "listout.dat"
  LI as "List1Out"
  LS2 as "List2Out"
 end-initializations 

end-model

Back to examples browserPrevious exampleNext example