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

Working with arrays

Description
  • arraydef.mos: Defining arrays: sparse and dense arrays; deleting array entries; multiple indices; array access functions
  • arrayinit.mos: Array initialization from a text file (requires arrayinit.dat)
  • autoarray.mos: Working with automatic arrays
  • chess2.mos: Indexing arrays by variables
Further explanation of this example: 'Mosel User Guide', Section 8.1 Arrays


Source Files
By clicking on a file name, a preview is opened at the bottom of this page.
arraydef.mos[download]
arrayinit.mos[download]
autoarray.mos[download]
chess2.mos[download]

Data Files





arrayinit.mos

(!******************************************************
   Mosel User Guide Example Problems
   ================================= 

   file arrayinit.mos 
   ``````````````````
   Array initialization from a text file.
 
   (c) 2010 Fair Isaac Corporation
       author: S. Heipcke, Jul. 2010
*******************************************************!)
model "Initializing arrays"

 declarations
  A: array(1..2,1..3) of real          ! Can use dense format
  B: array(R:range,T:range) of real    ! Requires sparse format
  D: dynamic array(set of string, range) of real   ! Requires sparse format
  S: set of string
  M: dynamic array(S) of integer       ! Requires sparse format
  N: dynamic array(S) of string        ! Requires sparse format
 end-declarations
 
 initializations from "arrayinit.dat"
  A  B           
  D as "SomeName"                      ! Data label different from model name
  D as "SomeName2"                     ! Add some data to 'D'
  [M,N] as "MNData"                    ! 2 arrays read from the same table
 end-initializations 
 
 writeln("A:", A, " B:", B, "\nD:", D, "\nM:", M, "\nN:", N)

end-model 

Back to examples browserPrevious exampleNext example