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

Working with records

Description
  • defining records and arrays of records
  • accessing record fields
  • assigning values to record fields
  • initialization with data from file
  • defining records of records (recorddef2.mos)
  • selecting record fields in initializations (recorddef2.mos)
Further explanation of this example: 'Mosel User Guide', Section 8.6 Records


Source Files

Data Files





recorddef.mos

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

   file recorddef.mos 
   `````````````````` 
   Defining and initializing records.
 
   (c) 2008 Fair Isaac Corporation
       author: S. Heipcke, Nov. 2006, rev. Sep. 2018
*******************************************************!)

model "Defining records"

 public declarations 
  R = 1..10
  D: public record
   name: string
   values: array(R) of real
  end-record
 end-declarations

 public declarations 
  mydata = public record                   ! Define a named record
   name: string
   values: array(R) of real
  end-record
  M: mydata
  A: dynamic array(T:range) of mydata
 end-declarations
 
 D.name:= "D"
 forall(i in R) D.values(i):= i
 writeln("Values of ", D.name, ": ", D.values)

 initializations from "recorddef.dat"
  A
 end-initializations

 writeln("An entry of A: ", A(1))
 writeln("'name' of an entry of A: ", A(4).name)
 writeln("'values' of an entry of A: ", A(3).values)
 writeln("First entry of 'values' of 'A4': ", A(4).values(1))

 forall(i in T | exists(A(i))) writeln(A(i).name)

end-model 

Back to examples browserPrevious exampleNext example