Initializing help system before first use

Definition of a network


Type: Programming
Rating: 3
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)
File(s): arcs.mos, arcs2.mos, arcs3.mos
Data file(s): arcs.dat


arcs.mos
(!******************************************************
   Mosel User Guide Example Problems
   ================================= 

   file arcs.mos
   `````````````
   Working with records: definition of a network.
   
   (c) 2008 Fair Isaac Corporation
       author: S. Heipcke, Nov. 2006
*******************************************************!)

model "Arcs"

 declarations
  NODES: set of string                  ! Set of nodes
  ARC: array(ARCSET:range) of record    ! Arcs:
   Source,Sink: string                  !   Source and sink of arc
   Cost: real                           !   Cost coefficient
  end-record 
 end-declarations

 initializations from 'arcs.dat'
  ARC
 end-initializations

! Calculate the set of nodes
 NODES:=union(a in ARCSET) {ARC(a).Source, ARC(a).Sink}
 writeln(NODES)

 writeln("Average arc cost: ", sum(a in ARCSET) ARC(a).Cost / getsize(ARCSET) )

end-model 

arcs2.mos
(!******************************************************
   Mosel User Guide Example Problems
   ================================= 

   file arcs2.mos
   ``````````````
   Working with records: definition of a network.
   - Selecting the record fields in initializations -
   
   (c) 2008 Fair Isaac Corporation
       author: S. Heipcke, Sep. 2007
*******************************************************!)

model "Arcs"

 declarations
  NODES: set of string                  ! Set of nodes
  ARC: array(ARCSET:range) of record    ! Arcs:
   flow: mpvar                          !   Flow quantity
   Source,Sink: string                  !   Source and sink of arc
   Cost: real                           !   Cost coefficient
  end-record 
 end-declarations

 initializations from 'arcs.dat'
  ARC(Source,Sink,Cost)
 end-initializations

! Calculate the set of nodes
 NODES:=union(a in ARCSET) {ARC(a).Source, ARC(a).Sink}
 writeln(NODES)

 writeln("Average arc cost: ", sum(a in ARCSET) ARC(a).Cost / getsize(ARCSET) )

end-model 

arcs3.mos
(!******************************************************
   Mosel User Guide Example Problems
   ================================= 

   file arcs3.mos
   ``````````````
   Working with records: definition of a network.
   - Reading the record fields from different sources -
   
   (c) 2008 Fair Isaac Corporation
       author: S. Heipcke, Sep. 2007
*******************************************************!)

model "Arcs"

 declarations
  NODES: set of string                  ! Set of nodes
  ARC: array(ARCSET:range) of record    ! Arcs:
   flow: mpvar                          !   Flow quantity
   Source,Sink: string                  !   Source and sink of arc
   Cost: real                           !   Cost coefficient
  end-record 
 end-declarations

 initializations from 'arcs.dat'
  ARC(Source,Sink) as "ARCDEF" 
  ARC(Cost) as "COST"
 end-initializations

! Calculate the set of nodes
 NODES:=union(a in ARCSET) {ARC(a).Source, ARC(a).Sink}
 writeln(NODES)

 writeln("Average arc cost: ", sum(a in ARCSET) ARC(a).Cost / getsize(ARCSET) )

end-model