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

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[download all files]

Source Files
By clicking on a file name, a preview is opened at the bottom of this page.


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

   This example requires an installation of Java, see
   the manual 'mosjvm Module for Mosel' for
   compatible versions and setup instructions.
   The compiled PassArray.class file must be in the current working

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

model myModel
  uses 'mosjvm'
    classAndMethodName = "PassArray.sumValues"
    result: real
    values: dynamic array(0..9) of real
  ! 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

  ! Tell Java to look for classes in work directory

  ! 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)

Back to examples browserPrevious exampleNext example