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

Parameters: tolerances

Description
This example demonstrates the effect of the equality tolerance (parameter ZEROTOL) in Mosel. When solving optimization problems, it may be useful to adapt the setting of this parameter to a tolerance value used by the solver. With Xpress Optimizer for instance, the Mosel equality tolerance could be brought in line with the feasibility tolerance XPRS_FEASTOL.


Source Files





equaltol.mos

(!*******************************************************
   Mosel Example Problems 
   ======================

   file equaltol.mos
   `````````````````
   Show the effect of the equality tolerance in Mosel.
       
   (c) 2008 Fair Isaac Corporation
       author: S. Heipcke, 2002, rev. Jun. 2019
*******************************************************!)

model "equality tolerance"
 uses "mmsystem"

 declarations
  a,b,r,s: real
  DEFZEROTOL: real
 end-declarations 

 a:=0.0000011
 b:=0.000002
 r:=1
 s:=1.00000004

! setparam("realfmt", "%.14f")        ! Set real number printing format

 DEFZEROTOL:= getparam('zerotol')    ! Retrieve the default zero tolerance

      ! Make tolerance smaller than the value to be displayed in the next line
 setparam("zerotol", DEFZEROTOL/10)
 writeln("Default equality tolerance:", DEFZEROTOL)

! **** Effect of different zero tolerance settings
 forall(ztol in [DEFZEROTOL, 1e-7, 1e-5]) do
   writeln("\nChanging tolerance to ", ztol)
   setparam("zerotol", ztol)

  ! Equality comparisons: tolerance applies
   writeln("a=", a, " is different from b=", b, ": ", a<>b)
   writeln("r=", r, " and s=", s, " are equal: ", r=s)

  ! Inequality comparison: tolerance also applies
   writeln("a=", a, " is smaller than  b=", b, ": ", a<b)

  ! Comparison between constants: tolerance does not apply
   writeln("1 and 1.00000004 are equal: ", 1=1.00000004)
 
 end-do

end-model

Back to examples browserPrevious exampleNext example