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

Definition of a procedure for getting solution values into an array

Description
Language extensions provided by this module:
  • subroutine: procedure
Similar (less generic) functionality can be provided by a package.

Further explanation of this example: 'Mosel Native Interface User Guide', Chapter 2 User-defined subroutines; package version: 'Mosel User Guide', Secction 16.2 Definition of subroutines


Source Files

Data Files





solarrayanypkg.mos

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

   File solarrayanypkg.mos
   ```````````````````````
   Example package providing the procedure
     solarray(array of mpvar, array of real)
   for getting solutions into an array.
   -- Implementation via union types and reflection --

   (c) 2022 Fair Isaac Corporation
       author: S. Heipcke, Jan 2022
*******************************************!)

package solarrayanypkg 
 uses "mmreflect"

 ! Utility routine checking whether 2 arrays have the same index set types
 function checkindices(x:any, s:any): boolean
   returned:= x.array.nbdim=s.array.nbdim and     
     and(i in 1.. x.array.nbdim) 
       x.array.index(i).eltype=s.array.index(i).eltype
 end-function

 ! Generic implementation of solarray routine
 public procedure solarray(x:any, s:any)
   declarations
     it: iterator
   end-declarations
   if x is array of mpvar and s is array of real then
     if checkindices(x,s) then
       inititer(it,x.array)
       reset(s.array)
       while (nextcell(it)) s.array(it).real:= x.array(it).mpvar.sol
     else
       writeln("SOLARRAY: array indices don't match")
     end-if
   else
     writeln("SOLARRAY: arguments must be arrays of type mpvar / real")
   end-if
 end-procedure 
 
end-package

Back to examples browserPrevious exampleNext example