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

Definition of a network

Description
  • definition of a data structure to represent arcs in a network with source, sink, and other properties
  • accessing the different record fields
  • initialization of records with data from a text file
  • selection of record fields in initializations (arcs2.mos)
  • separate initialization of record fields (arcs3.mos)
  • sets and lists of records, using type constructors (arcs4.mos)
  • constant record definition, sets of constant records (arcs5.mos)
Further explanation of this example: 'Mosel User Guide', Section 8.6 Records


Source Files
By clicking on a file name, a preview is opened at the bottom of this page.
arcs.mos[download]
arcs2.mos[download]
arcs3.mos[download]
arcs4.mos[download]
arcs5.mos[download]

Data Files





arcs5.mos

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

   file arcs5.mos
   ``````````````
   Working with records.
   - Sets of constant records -
   
   (c) 2020 Fair Isaac Corporation
       author: S. Heipcke, Apr. 2020
*******************************************************!)

model "Arcs constants"

 public declarations
  NODES: list of string                 ! List of nodes
  arc = public record                   ! Arcs:
   Source,Sink: string                  !   Source and sink of arc
   Cost: real                           !   Cost coefficient
  end-record 
  ARCS: set of arc  
!!! Only records with scalar fields of basic types can be declared as constants
  ARCSC: set of constant arc  
  myarc=arc(.Source:='S',.Sink:='A',.Cost:=10)    ! A constant record
 end-declarations

 function newarc(s,t:string, c:real): arc
  returned.Source:=s
  returned.Sink:=t
  returned.Cost:=c
 end-function

 NODES:=['A','B','C','D','E','F']

 forall(j in NODES) do
  ARCS += {newarc("","",0)}      ! Add several elements with the same contents
  ARCSC += {newarc("","",0)}     ! Add repeatedly the same set element
! Same as:
  ARCSC += {arc(.Cost:=0)}
 end-do 
 
 writeln("ARCS =", ARCS, " size=", ARCS.size)
 writeln("ARCSC=", ARCSC, " size=", ARCSC.size)

 i:='S'; ct:=0
 forall(j in NODES, ct as counter) do
  ARCS+= {arc(.Source:=i,.Sink:=j,.Cost:=10*ct)}
  ARCSC+= {arc(.Source:=i,.Sink:=j,.Cost:=10*ct)}
! Same as:
  ARCSC += {newarc(i,j,10*ct)}
  i:=j
 end-do 
 
 writeln("myarc=", myarc)
 writeln("ARCS =", ARCS, " size=", ARCS.size)
 writeln("myarc is in ARCS: ", myarc in ARCS)

 writeln("ARCSC=", ARCSC, " size=", ARCSC.size)
 writeln("myarc is in ARCS: ", myarc in ARCSC)

end-model 

Back to examples browserPrevious exampleNext example