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

Passing an array from a Mosel model to a Java method

Description
Demonstrates constructing an array of reals in a Mosel model, then passing this to a Java method which returns the sum of the values, and finally displaying the returned sum from Mosel. You must compile the Java file before running the example - e.g. javac PassArray.java

mosjvm_passingarrays.zip[download all files]

Source Files





passarray.mos

(!*******************************************************
   file passarray.mos
   ``````````````````
   a model that demonstrates passing an array from Mosel to a Java method

   (c) 2016 Fair Isaac Corporation
       author: J. Farmer, 2016
  *******************************************************!)


model myModel
  uses 'mosjvm'
  
  declarations
    classAndMethodName = "PassArray.sumValues"
    result: real
    values: dynamic array(0..9) of real
  end-declarations
 
  ! Set to initial array elements
  values(0) := 1
  values(1) := 5
  values(2) := 10
  values(7) := 10
 
  ! Abort model if we encounter a Java exception
  setparam('jvmabortonexception',true)

  ! Tell Java to look for classes in work directory
  setparam('jvmclasspath',getparam('workdir'))

  ! Call into Java to sum values
  ! (missing values in the array will be passed to Java as 0)
  result := jvmcallreal( classAndMethodName, values )
  
  ! Output result
  writeln('Sum of values: ',result)
end-model

Back to examples browserPrevious exampleNext example