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





autoarray.mos

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

   file autoarray.mos 
   ``````````````````
   Working with automatic arrays.
 
   (c) 2010 Fair Isaac Corporation
       author: S. Heipcke, Jul. 2010
*******************************************************!)
model "Automatic arrays"

 declarations
  B: array(S:set of string, I:set of real) of integer
 end-declarations
 
 B::(["a","b"], [3,1.5,7])[1,2,3,4,5,6]
 writeln("B: ", B)

! Row and colum arrays (1-dimensional)
 forall(s in S) writeln("Row ", s, ": ", array(i in I) B(s,i))
 forall(i in I) writeln("Column ", i, ": ", array(s in S) B(s,i))

! Filtered array entries (2-dimensional)
 writeln("B filtered: ", array(s in S,i in I | s<>"a" and i<5) B(s,i))

! Inversed indices (2-dimensional)
 writeln("Transpose: ", array(i in I, s in S) B(s,i)) 
 
 initializations to "arrayout.txt"
  B
  evaluation of array(i in I, s in S) B(s,i) as "B_T"
 end-initializations
end-model

Back to examples browserPrevious exampleNext example