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

Subroutines

Description
  • lcdiv2.mos: Recursive function calls
  • primefct.mos: function returning a set
  • qsort1.mos: 'forward' definition of subroutines
  • qsort2.mos: Overloading of subroutines
  • shsortfct.mos: Function returning an array
  • subrout.mos: Local and global declarations, fixed and variable number of arguments
  • reftosubr.mos: Working with subroutine references, using mmreflect functionality for retrieving and calling subroutines
Further explanation of this example: 'Mosel User Guide', Chapter 9 Functions and procedures

subroutines.zip[download all files]

Source Files
By clicking on a file name, a preview is opened at the bottom of this page.
lcdiv2.mos[download]
qsort1.mos[download]
qsort2.mos[download]
subrout.mos[download]
reftosubr.mos[download]





lcdiv2.mos

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

   file lcdiv2.mos 
   ``````````````` 
   Recursive function calls.
 
   (c) 2008 Fair Isaac Corporation
       author: S. Heipcke, 2001, rev. Jun. 2022
*******************************************************!)

model Lcdiv2

 function lcdiv(a,b:integer):integer
   if a=b then
     returned:=a
   elif a>b then
     returned:=lcdiv(b,a-b)
   else
     returned:=lcdiv(a,b-a)
   end-if   
 end-function

 declarations
   A,B: integer
 end-declarations

 write("Enter two integer numbers:\n  A: ")
 readln(A)
 write("  B: ")
 readln(B)

 writeln("Largest common divisor: ", lcdiv(A,B))

end-model

Back to examples browserPrevious exampleNext example